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

Ch 13 agent/alphago.py wrong code? #94

Open pocca2048 opened 2 years ago

pocca2048 commented 2 years ago

Hi! I am reading your book and I think I found an error in Ch 13.

Why do you reset self.root here https://github.com/maxpumperla/deep_learning_and_the_game_of_go/blob/50aa0ce1cd1e638c62c5ddd6ee602db3b1c23d47/code/dlgo/agent/alphago.py#L118

before referencing it below? https://github.com/maxpumperla/deep_learning_and_the_game_of_go/blob/50aa0ce1cd1e638c62c5ddd6ee602db3b1c23d47/code/dlgo/agent/alphago.py#L119

I don't know what was the intention of it but I believe this would be wrong since that will never be executed.

pocca2048 commented 2 years ago

found out this https://github.com/maxpumperla/deep_learning_and_the_game_of_go/issues/42 so closing it

pocca2048 commented 2 years ago

This code is wrong either:

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

since else is never executed and self.root cannot reflect opponent's move so that it eventually makes illegal moves.

To solve this, there are two choices:

  1. reset by self.root = AlphaGoNode() no matter what.
  2. make a new function that when opponent makes a move, reflect it on self.root. e.g.,
    def reflect_move(self, move):
    if move in self.root.children: 
        self.root = self.root.children[move]
        self.root.parent = None
    else:
        self.root = AlphaGoNode()

Please let me know if I'm wrong.