OpenSpiel core functions: deserialize_game_and_state

Back to Core API reference

deserialize_game_and_state(game: pyspiel.Game, state: pyspiel.State)

Returns a (game, state) tuple that is reconstructed from the serialized string data.

Note: pickle can also be used to serialize / deserialize data, and the pickle uses the same serialization methods.

Examples:

import pyspiel

game = pyspiel.load_game("tic_tac_toe")
state = game.new_initial_state()
state.apply_action(4)
state.apply_action(2)
state.apply_action(1)
state.apply_action(5)

serialized_data = pyspiel.serialize_game_and_state(game, state)
print(serialized_data)

game_copy, state_copy = pyspiel.deserialize_game_and_state(serialized_data)
print(state_copy)

# Output:
# # Automatically generated by OpenSpiel SerializeGameAndState
# [Meta]
# Version: 1
#
# [Game]
# tic_tac_toe()
# [State]
# 4
# 2
# 1
# 5
#
#
# .xo
# .xo
# ...