Created
October 23, 2020 16:01
-
-
Save masouduut94/65512fa0e2dfed03da5bf89f27bb7b58 to your computer and use it in GitHub Desktop.
code for backpropagation part.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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