leanchess wrote: ↑Fri Dec 03, 2021 4:51 pm
Fulvio wrote: ↑Fri Dec 03, 2021 3:42 pm
Fulvio wrote: ↑Fri Dec 03, 2021 3:26 pm
But it probably works.
Or maybe it does not work?
How do you encode the previous castling rights when the king moves?
With the position [fen]4k3/8/8/8/8/8/4K3/R6R b - - 0 12[/fen]
the last move was Ke2, how do you know if the previous position was:
4k3/8/8/8/8/8/8/R3K2R w - - 0 12
or
4k3/8/8/8/8/8/8/R3K2R w K - 0 12
or
4k3/8/8/8/8/8/8/R3K2R w KQ - 0 12
Do I really need to implement it all?
Code: Select all
void unmake(struct rmove m, int color) {
int toPiece = m.toPiece != MovedRook
? m.toPiece
: (Rook | Moved);
board[m.toSquare] = toPiece | (color ^ Color);
int piece = m.fromPiece;
switch (piece) {
case MovedRook: piece = Rook | Moved;
break;
case MovedKing: piece = King | Moved;
break;
case King: if (m.flags & CastleQueen) {
//...
} else if (m.flags & CastleKing) {
//...
}
break;
case Pawn: //...
break;
}
//...
board[m.fromSquare] = piece | color;
}
I still think it does not work.
In all cases flags, isEnPassant, enPassantFile would be 0.
toPieces would also always be 0 (None) and cannot be used because in E2 maybe there was a piece.
fromSquare would always be E1 and toSquare E2.
So you are left with only fromPiece which you can use for 2 cases:
full castle rights KQ -> MovedKing
no castle rights -- -> King
but there is no way to encode the other 2 cases:
can only castle queen side Q
can only castle king side K