Skip to content

Instantly share code, notes, and snippets.

@masouduut94
Created October 23, 2020 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masouduut94/380b4eda46a4f98938afd3ebed92e1b6 to your computer and use it in GitHub Desktop.
Save masouduut94/380b4eda46a4f98938afd3ebed92e1b6 to your computer and use it in GitHub Desktop.
simulation code of mcts agent.
@staticmethod
def roll_out(state: GameState) -> int:
"""
Simulate an entirely random game from the passed state and return the winning
player.
Args:
state: game state
Returns:
int: winner of the game
"""
moves = state.moves() # Get a list of all possible moves in current state of the game
while state.winner == GameMeta.PLAYERS['none']:
move = choice(moves)
state.play(move)
moves.remove(move)
return state.winner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment