Skip to content

Instantly share code, notes, and snippets.

@masouduut94
Created October 23, 2020 16:01
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/65512fa0e2dfed03da5bf89f27bb7b58 to your computer and use it in GitHub Desktop.
Save masouduut94/65512fa0e2dfed03da5bf89f27bb7b58 to your computer and use it in GitHub Desktop.
code for backpropagation part.
@staticmethod
def backup(node: Node, turn: int, outcome: int) -> None:
"""
Update the node statistics on the path from the passed node to root to reflect
the outcome of a randomly simulated playout.
Args:
node:
turn: winner turn
outcome: outcome of the rollout
Returns:
object:
"""
# Careful: The reward is calculated for player who just played
# at the node and not the next player to play
reward = 0 if outcome == turn else 1
while node is not None:
node.N += 1
node.Q += reward
node = node.parent
reward = 0 if reward == 1 else 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment