mirror of
https://github.com/GoodStartLabs/AI_Diplomacy.git
synced 2026-04-28 17:29:41 +00:00
INIT
This commit is contained in:
parent
e8530a146d
commit
93c073e2df
295 changed files with 86794 additions and 0 deletions
31
randomgame.py
Normal file
31
randomgame.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import random
|
||||
from diplomacy import Game
|
||||
from diplomacy.utils.export import to_saved_game_format
|
||||
|
||||
# Creating a game
|
||||
# Alternatively, a map_name can be specified as an argument. e.g. Game(map_name='pure')
|
||||
game = Game()
|
||||
while not game.is_game_done:
|
||||
|
||||
# Getting the list of possible orders for all locations
|
||||
possible_orders = game.get_all_possible_orders()
|
||||
|
||||
# For each power, randomly sampling a valid order
|
||||
for power_name, power in game.powers.items():
|
||||
power_orders = [random.choice(possible_orders[loc]) for loc in game.get_orderable_locations(power_name)
|
||||
if possible_orders[loc]]
|
||||
game.set_orders(power_name, power_orders)
|
||||
|
||||
# Messages can be sent locally with game.add_message
|
||||
# e.g. game.add_message(Message(sender='FRANCE',
|
||||
# recipient='ENGLAND',
|
||||
# message='This is a message',
|
||||
# phase=self.get_current_phase(),
|
||||
# time_sent=int(time.time())))
|
||||
|
||||
# Processing the game to move to the next phase
|
||||
game.process()
|
||||
|
||||
# Exporting the game to disk to visualize (game is appended to file)
|
||||
# Alternatively, we can do >> file.write(json.dumps(to_saved_game_format(game)))
|
||||
to_saved_game_format(game, output_path='game.json')
|
||||
Loading…
Add table
Add a link
Reference in a new issue