mirror of
https://github.com/GoodStartLabs/AI_Diplomacy.git
synced 2026-04-19 12:58:09 +00:00
script + error logging for order decoding
This commit is contained in:
parent
a1aed6674f
commit
1b042cf6c6
6 changed files with 136 additions and 70 deletions
35
random_game.py
Normal file
35
random_game.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
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)
|
||||
|
||||
print(f"{power_name} orders: {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