maxpumperla / deep_learning_and_the_game_of_go

Code and other material for the book "Deep Learning and the Game of Go"
https://www.manning.com/books/deep-learning-and-the-game-of-go
953 stars 387 forks source link

Why create a new Node as Root at this position? #42

Open artus-LYTiQ opened 4 years ago

artus-LYTiQ commented 4 years ago

https://github.com/maxpumperla/deep_learning_and_the_game_of_go/blob/c1add1ff272f8927a82d81c9ee430f9c13e062ef/code/dlgo/agent/alphago.py#L118

Hi Max, hi Kevin,

What is the point of a) Creating a new Root node here and then also b) testing if the move is in root.children?

We have selected the move to be a child of the old root. Therefore, without creating a new empty node as root, the condition from line 119 would be met anyway. But then you create a new empty (?) node and assign it as root in 118. How can the test in 119 be successful then?

Can't wrap my head around it, sorry.

` move = max(self.root.children, key=lambda move: # <1> self.root.children.get(move).visit_count) # <1>

    self.root = AlphaGoNode()
    if move in self.root.children:  # <2>
        self.root = self.root.children[move]
        self.root.parent = None

    return move`
maxpumperla commented 4 years ago

@artus-LYTiQ that's entirely on me, the intended behavior is this:

if move in self.root.children: 
    self.root = self.root.children[move]
    self.root.parent = None
else:
    self.root = AlphaGoNode()
return move

as in: set root node to child corresponding to move or else reset. Apparently one very late night a few months ago I must have been under the impression that those statements are equivalent.