diplomacy.utils.export

Exporter - Responsible for exporting games in a standardized format to disk

diplomacy.utils.export.to_saved_game_format(game, output_path=None, output_mode='a')[source]

Converts a game to a standardized JSON format

Parameters:
  • game (diplomacy.engine.game.Game) – game to convert.
  • output_path (str | None, optional) – Optional path to file. If set, the json.dumps() of the saved_game is written to that file.
  • output_mode (str, optional) – Optional. The mode to use to write to the output_path (if provided). Defaults to ‘a’
Returns:

A game in the standard format used to saved game, that can be converted to JSON for serialization

Return type:

Dict

diplomacy.utils.export.from_saved_game_format(saved_game)[source]

Rebuilds a diplomacy.engine.game.Game object from the saved game (python Dict) saved_game is the dictionary. It can be built by calling json.loads(json_line).

Parameters:saved_game (Dict) – The saved game exported from to_saved_game_format()
Return type:diplomacy.engine.game.Game
Returns:The game object restored from the saved game
diplomacy.utils.export.load_saved_games_from_disk(input_path, on_error='raise')[source]

Rebuids multiple diplomacy.engine.game.Game from each line in a .jsonl file

Parameters:
  • input_path (str) – The path to the input file. Expected content is one saved_game json per line.
  • on_error – Optional. What to do if a game conversion fails. Either ‘raise’, ‘warn’, ‘ignore’
Return type:

List[diplomacy.Game]

Returns:

A list of diplomacy.engine.game.Game objects.

diplomacy.utils.export.is_valid_saved_game(saved_game)[source]

Checks if the saved game is valid. This is an expensive operation because it replays the game.

Parameters:saved_game – The saved game (from to_saved_game_format)
Returns:A boolean that indicates if the game is valid