maxpumperla / deep_learning_and_the_game_of_go

Code and other material for the book "Deep Learning and the Game of Go"

Home Page:https://www.manning.com/books/deep-learning-and-the-game-of-go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ch 13 agent/alphago.py wrong code?

pocca2048 opened this issue · comments

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

Why do you reset self.root here

before referencing it below?

if move in self.root.children: # <2>

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

found out this #42
so closing it

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.