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.89k stars 1.03k forks source link

getCanonicalForm rotate board #44

Closed Wikunia closed 6 years ago

Wikunia commented 6 years ago

We are trying to implement a version for Hex/Nash https://en.wikipedia.org/wiki/Hex_(board_game)

There the two players are trying to reach a slightly different goal. One player is playing from left to right the other one from top to bottom. Therefore, the idea was to rotate the board and flip it in getCanonicalForm but then the moves aren't legal anymore as the board has changed at least that's what we believe is happening :D

Any ideas of how to overcome this issue?

suragnair commented 6 years ago

I see. Does this error come up during self-play or only during the pit stage?

Wikunia commented 6 years ago

If I just implement the it like for every other game and then use the rotation flipping in getCanonicalForm the error occurs when getNextState is called by Coach.py in the self playing part. There the getNextState is called with -1 as a player sometimes, right? Whereas the mcts variant calls it always with player 1. I have to say that I didn't fully understand your code and naively tried to implement it for this game :laughing: It's currently a bit hard to debug without knowing when which representation is used (like if it is currently the canonical form (and if yes rotated) or the normal representation of it.

Wikunia commented 6 years ago

I think I found a way. For this game but I think also in general it would be nice to implement Pie rule (https://en.wikipedia.org/wiki/Pie_rule)

suragnair commented 6 years ago

Thanks, will have a look!

luzai commented 6 years ago

Sometimes the black and white player is not symmetry. For example, in Renju, a variation of Gobang, there are rules of three and three, four and four, and longlink for black player only and sometimes swap player.

May I ask some suggestions for implementing more general getCanonicalForm in GobangGame.py?

trentjmorris commented 7 months ago

I think I found a way. For this game but I think also in general it would be nice to implement Pie rule (https://en.wikipedia.org/wiki/Pie_rule) @Wikunia Would you mind sharing how you've overcome this? I have a similar issue with asymmetric win-conditions depending on the player's piece color.