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.9k stars 1.04k forks source link

Chess implementation? #296

Closed jamesbraza closed 1 year ago

jamesbraza commented 1 year ago

I am making this issue on 2/28/2023, and at this point in time I don't see a chess implementation.

Are there any plans to implement chess here?

Alternately, are there any known repo(s) that implement chess using this AGZ general framework? Preferably they use the python-chess library to handle chess specifics.


Research

Based on issues in this repo, I have found multiple descendants:

I also discovered this 4/18/2021 PR (currently unaccepted) by @yeekit24: https://github.com/suragnair/alpha-zero-general/pull/240

Lastly, here are a few other noteworthy repos, not based on this framework:

TheMessik commented 1 year ago

Mine is very much WIP and at an early stage. It should be runnable, but the network you get out of it isn't anywhere near good

jamesbraza commented 1 year ago

@TheMessik where did you get your network architecture from (e.g. use of batch norms, hyperparams of layers, etc)?

TheMessik commented 1 year ago

I believe I based it on the Othello network, adding and removing layers and changing parameters until it worked. That part was rushed and needs a rewrite

vedanta28 commented 1 year ago

@TheMessik What do you think that it's Elo is? Like I wanted to create something for a variation of chess. Three Check Chess with an additional rule that pawns move diagonally and capture moving forward. Would just changing these rules in your chess.py and training it , work?

TheMessik commented 1 year ago

It's ELO will definitely be in single digits. I was training it on endgames, so it's opening and middlegame is nonexistent, it's pretty much a random player there.

I don't think python-chess supports 3 checks variant, so you'll also need to do your own game ended checking, aside from adapting the move masking function.

jamesbraza commented 1 year ago

Hello all, for posterity here is my working chess implementation: https://github.com/jamesbraza/cs234-dreamchess/tree/main/azg_chess

The AI inside nn.py was trainable and shown to improve in skill across rounds of self-play. I found an "unsigned" embedding (read the module for what that means) worked better than a "signed" embedding given the same number of training iterations. Also, the Game subclass is fully unit tested and works well.

For me, this was part of a Stanford CS234 Reinforcement Learning class project that I was rushing to complete in the last weeks, so I didn't have time to do a full-blown multi-day training to see how strong the AI could get (measured in Elo). Hope this can help someone in the future, or serve as a better starting point for a PR into this repo. Cheers!