node in children
is always false
but in the debugger:
(pdb) children.keys()
...
turn: 1, last: (5, 2), hash: 5837165650205296398,
...
(pdb) node
turn: 1, last: (5, 2), hash: 5837165650205296398
(pdb) node in children
False
(pdb) node.__eq__(node)
True
heres the function.
def _select(node):
path = []
global new, terminals, found
while True:
path.append(node)
if node not in children: new += 1;return path
if not children[node]: terminals += 1;return path;
unexplored = children[node] - children.keys()
if unexplored:
found += 1
n = unexplored.pop() # ignore best path?
path.append(n)
return path
# node = _uct_select(node)
else: node = choice(tuple(children[unexplored]))
and here's the hash() and eq() functions
def __hash__(self):
"Nodes must be hashable"
return hash(tuple(self.board.flatten() ))
def __eq__(node1, node2):
"Nodes must be comparable"
return node1.board is node2.board
board is just a [6,7] array