DenseLance / mcts-simple

mcts-simple is a Python3 library that allows reinforcement learning problems to be solved easily with its implementations of Monte Carlo Tree Search.
MIT License
18 stars 1 forks source link

missing test in tictactoe example #4

Closed PierreG2023 closed 9 months ago

PierreG2023 commented 9 months ago

Hello, Minor quibble found while testing with very incomplete trees (few training iterations): in step 5, the game loop may seach node for an action when it is None, in the elif branch of if node is not None and action in node.children: node = node.children[action] elif action not in node.children: node = None

elif test should be node is not None and action not in node.children. Found out while toying around with short initial trainings combined with in-game training from current state when "falling off" a tree. BTW your library is a great educational resource. P.G.

DenseLance commented 9 months ago

Hi Pierre, thanks for pinpointing that out (which I might have missed during my debugging)!

Indeed, if we were to run step 5 with an incomplete tree, there will definitely be an instance where node = None and trigger an AttributeError.

In that case, let's roll with this:

if node is not None:
    node = node.children[action] if action in node.children else None

I will be adding the code above to the module in the coming days. Cheers!

DenseLance commented 9 months ago

Feel free to ask questions/point out any bugs in the library; I appreciate it a lot. Will close this issue once I update the library.

DenseLance commented 9 months ago

Do check the above commit and see if it works. Will be marking this as completed.