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
Support Chess960 #786
Comments
Maybe I'm missing something but can't you use a single plane and set the squares on which the rooks have castling rights? In your example where the king is on e1 and the rooks are on a1 and b1, then the move to castling with the a1 rook would be e1a1 and with the b1 rook would be e1b1. If a1 on the castling plane is set, then a1 has castling rights; if a1 is clear, then no castling rights. Same for b1. You could also split the single castling plane into a castling plane for white and a castling plane for black, if desired. |
Because that is a convolution network, encoding castling rights with a single bit would be inconvenient for the NN. It will only "see" that flag while thinking about something close to that rook, and it will be hard to take castling rights into account when calculating remote parts of the board. |
In theory propagating of the castling right is not a problem with SE-units. It's possible to make a constant filled plane from input plane with only a single position set using just one SE-unit. It's also possible to turn other planes on or off depending on the castling plane. Ordinary resnet would require multiple residual blocks to do the same. |
Ok, then it's not much of a problem, so we don't need option 1. |
Here is a PDF with Bobby Fischer's original RULES OF FISCHERANDOM CHESS (1996): I will use Fischer's terminology from that document. Hans-Walter Schmitt used the term "Chess960" in the Mainz Chess event, instead of FISCHERANDOM CHESS, and soon some other's followed. Bobby Fischer said in an interview that he don't like the term "Chess960". He said they removed his name from it and branded it "Chess960" because some organisations don't want to be associated with his name after his live radio interviews. For those who like to respect Bobby Fischer I therefore suggest to not use the term "Chess960". However, in PGN games for F.R. Chess games the See https://en.wikipedia.org/wiki/Chess960 Using Bobby Fischer's terminology from the original RULES OF FISCHERANDOM CHESS manual, we say "a"-side and "h"-side castling for Queen-side (O-O-O and... O-O-O) and King-side (O-O and ... O-O) castling, respectively. The AlphaZero papers are here: In https://arxiv.org/pdf/1712.01815.pdf on page 13 the representation of the input features are explained. It looks similar in all AlphaZero papers as far as I can see. AlphaZero Chess uses two planes for player P1 and two planes for player P2 to denote the possibility to castle Queen-side or King-side. As far as I understand it, these four planes are boolean values where the entire 8x8 planes are either filled with zero's or one's. Likewise, the color plane indicating side to move works the same: The entire NxN size plane is filled with zero's or one's to indicate a boolean state. I think the reason that the entire NxN plane is filled (and not just one bit or a row of bits) and set to the same vale (0 or 1), for the side to move (color) and castling rights, is that the neural network shall not associate this kind of state with a location (geographical location on the board). Do you guys think that is correct? I don't know if this is the case. Maybe a neural network can figure it out even when not all squares are marked with the same boolean value, but it seems to me that by setting all NxN bits in a plane to the same value the neural network will not have to figure out if it is location based (and it is obviously not the case even for castling states, it is just a static state that is not affected by the location of any piece). Therefore, if this is true, Lc0 should use the same representation here as AlphaZero Chess. So the input features to Lc0 should then represent the right to castle as boolean states, four "flags" where the entire planes (four: two for each player) shall be set to zero's or one's. The names of the states can conveniently use Bobby Fischer's terminology: Those are the only input states needed to the neural network when it comes to the castling stuff. There is probably no need at all to have any input features to point out which "a"-side and "h"-side Rook's are the Rooks that the King can castle with. The neural network considers the position of all pieces and expresses through the policy head the prior probabilities for all actions (which can be moves, but can also be non-moves, like in Go one action is to "pass" and AlphaZero has a separate action output for "pass"). The actions includes moves that are illegal because of location of all pieces. The way AlphaZero Chess expresses the action to castle Queen-side or King-side (the Classical Chess terminology) is simply King (on e1) to c1 (for Queen-side), or King to g1 (for King-side) castling. It has learned that when it expresses the "castle Queen-side" action the result is that the King ends up on c1 and Rook on d1, and the "castle King-side" action results in that the King ends up on g1 and Rook on f1. That encoding "e1-c1" or "e1-g1" could have been anything I'm sure. It could be a separate action signal, just as in Go AlphaZero uses a separate action signal to express "pass". Therefore the encoding can be anything to express castling "a"-side or castling "h"-side. Then comes the other part that is not at all related to the input and output of the neural network. That is to encode which "a"-side Rook (if any) is the Rook that the King can castle with, and likewise which is the "h"-side Rook (if any) that the King can castle with. That information needs to be stored with each position in the game tree and search tree, or at least the current analysis line of the search tree. I can think of several representations. For example, an 8-bit byte, a bitmask, marking White's backrow with a '1' on the Rook or Rooks that are the Rooks the King can castle with. Since it is known where the King is, it is also known which Rook is the "a"-side and which Rook is the "h"-side, since it will be to the left side of the King and to the right side of the King. With the "a"-side Rook placed on the "a"-file, the King on the "c"-file and the "h"-side Rook placed on the "g"-file, the bitmask would look like this: White and Black have one such bitmask each. This representation needs 16-bits of storage per position. Not too bad. With this there is no need to have four separate flags to indicate the right to castle "a"-side and "h"-side for White and Black, because those four flags are stored in those 16-bits. An alternative is to have four flags in a bitmask to indicate the possibility for "a"-side and "h"-side castling for White and Black, and then store the file location (a..h) as a 3-bit value 0..7 indicating which file the "a"-side Rook is placed on, and likewise a 3-bit value indicating which file the "h"-side Rook is placed on. If the flags indicating the right to castle "a"-side or "h"-side is set to false, then the 3-bit file location value is ignored (it can be any value). This also requires 16-bits of storage for each position: Maybe that is a better encoding. NOTE: Castling is considered a King move. |
For FEN notation, use the same as Stockfish & Co. To express castling in the game/search tree: |
Ok, our training data format doesn't support generic planes, so training code would need changes too. So it probably doesn't make sense to implement chess960 until we have protobuf-based training files. |
One part of the implementation will be to handle FEN that contains F.R. Chess positions. Using the F.R. Chess games stored as PGN at CCRL http://ccrl.chessdom.com/ccrl/404FRC/
FEN as defined for the Classical Chess starting position: The part of the FEN that express castling availability is different. In FEN that support F.R. Chess, castling availability is expressed by denoting the files (A..H or a..h) where the Rooks (that can be castled with) are positioned, in this order: A few more examples:
|
The neural network need to take into consideration if castling rights exist or not. In My 60 Memorable Games, game 40 Fischer checks the opponents King and then moves the Knight back, so that the position of all pieces are the same, but Black has lost the right to castle (by moving his King). Fischer commented "Back where we started — but Black has lost the right to castle." Therefore I think it is of paramount importance that the neural network has knowledge of the castling state. The neural network need to see which Rook's can be castled with for both sides. |
I didn't ask anything like that in Discord. :) |
UCI protocol for Fischer Random Chess • The engine has to tell the GUI that it is capable of playing Fischer Random Chess, and the GUI has to tell the engine that is should play according to the Fischer Random Chess rules. This is done by the special engine option UCI_Chess960. If the engine knows about Fischer Random Chess it should send the command 'option name UCI_Chess960 type check default false' to the GUI at program startup. • Whenever a Fischer Random Chess game is played, the GUI should set this engine option to 'true'. • Castling is different in Fischer Random Chess and the White King move when castling short is not always e1g1. A King move could both be the castling King move or just a normal King move. This is why castling moves are sent in the form King-takes-own Rook. Example: e1h1 for the White short castle (O-O) move in the normal Chess starting position. • In EPD and FEN position strings specifying the castle rights with w and q is not enough as there could be more than one Rook on the right or left side of the King. This is why the castle rights are specified with the letter of the castling Rook's file. Upper case letters for White's and lower case letters for Black's castling rights. Example: The normal chess position would be: |
Do we close this issue @mooskagh ? |
Indeed! |
Let's have a tracking issue for Chess960 support.
The main question is how to encode castling moves as output from NN, and how to encode castling rights as input of NN.
For the output, the agreement seems to be that we should implement it as "king takes own rook" move, which actually we already do for normal chess.
https://discordapp.com/channels/425419482568196106/445928688115122176/502374216180563968
For the input, we need to signalize somehow, which castlings are possible.
Currently it's implemented as separate planes from king-side and queen-side castlings, which are filled with ones if side has right to castle.
For Chess960 this is not enough:
Consider the following position:
Rooks a1, b1. King e1. Queen-side castling rights are not lost. No pieces at c1, d1.
Is castling possible in this position?
The answer is "unknown", because it's not possible to distinguish between two situations:
So we need different encoding.
Possible options:
Pros: similar to current approach.
Cons: Needs NN change. Also plane "castling with rook at d1 is allowed" actually may mean two different allowed moves depending on king location.
Pros: No need for NN change, and two planes (one per player) becomes unused.
Cons: Encodes two different castling rights the same.
It's not clear how worse setting column to ones is worse than setting entire plane, as it may make decision making at far corner of the board harder.
(Reuse current castling planes for that)
Encode allowed castlings with entire column filled with ones.
Pros: No need for NN change, planes even have a bit similar meaning to what we have now (most surely still not compatible play-wise).
Encodes two different castling types in different planes.
Cons: It's not clear how worse setting column to ones is worse than setting entire plane, as it may make decision making at far corner of the board harder.
I like option 3 the most.
Please share your ideas/concerns.
The text was updated successfully, but these errors were encountered: