Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stateful Game-structs throw errors #25

Closed
oqpvc opened this issue Nov 2, 2020 · 1 comment
Closed

Stateful Game-structs throw errors #25

oqpvc opened this issue Nov 2, 2020 · 1 comment

Comments

@oqpvc
Copy link

oqpvc commented Nov 2, 2020

I've started to play around with AlphaZero.jl over the last few days by implementing Othello and Hex. In the process I've run into similar issues a few times: As soon as I let the Game-struct be more stateful, training throws weird errors (e.g. "MCTS.explore! must be called before MCTS.policy", but also others that were more verbose and even less helpful). I expect that is the reason why these lines of code exists in Connect4:

function Base.copy(g::Game)
  history = isnothing(g.history) ? nothing : copy(g.history)
  Game(g.board, g.curplayer, g.finished, g.winner, copy(g.amask), history)
end

I am, generally speaking, at a loss when it comes to debugging this. I think I want to write a few tests to catch these kinds of errors, but I have no idea where to start. Any help would be appreciated.

@jonathan-laurent
Copy link
Owner

First of all, there are some tests available to catch errors in an implementation of GameInterface.
You can look at tests/test_game.jl, which can be executed on your game by running scripts/alphazero.jl with the check-game sub-command.

Also, what probably happens in your case is that your states do not appear as persistent. This seems to be a pretty common mistake and so maybe I should change the API to make it less common.

Indeed, MCTS calls current_state and stores the resulting state in a hash table. Therefore, you will encounter weird bugs if your states are mutable and you do not copy them properly. If you are struggling with this, my advice is to add copy operations conservatively and only remove the unnecessary ones once everything works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants