suragnair / alpha-zero-general

A clean implementation based on AlphaZero for any game in any framework + tutorial + Othello/Gobang/TicTacToe/Connect4 and more
MIT License
3.84k stars 1.03k forks source link

Question about valid moves #171

Closed goshawk22 closed 4 years ago

goshawk22 commented 4 years ago

I am currently working on the code for the game Draughts. Draughts is different to the other games because, instead of placing a piece, you move an existing on on the board, and each piece might have multiple places to move to. There are also two types of piece for each player, men and kings. To work around this, the move variable has three values: the type of move (could be a standard move, standard capture, king move or king capture), the piece to be moved (tuple) and the destination (tuple). The problem is that this isn't going to work with the MCTS as it returns the probability for each square on the board, not which piece to move and where. Is there a better way of implementing the move variable, or should I try something else? Code is at https://github.com/goshawk22/alpha-zero-general/tree/draughts

goshawk22 commented 4 years ago

I have found a workaround although I think it's very inefficient. I take the two coordinates of the board and convert them to a value between 0 and 64. This gives me an list; (0-3, 0-64, 0-64). Then I convert this to a value between 0 and 16384 (64644). This is then the length of valids, as opposed to 64 in Othello. I haven't finished the code yet but I will report back as to whether it is very slow or not!

goshawk22 commented 4 years ago

Yes, seems there are some problems. My computer is running out of ram before even 1 game of self play is finished (and I have 32gb). I'm not sure if its possible to make the valid moves array smaller but i can certainly work on it! Any ideas would be useful.

evg-tyurin commented 4 years ago

See the repo for a variant of Checkers. Number of moves is much less you mentioned above. https://github.com/evg-tyurin/alpha-nagibator