Live data from Hacker News

How to store a chess position in 26 bytes (2022)

ezzeriesa.notion.site

21–30 of 108 posts

Re: How to store a chess position in 26 bytes (2022)

#21
post #11

Bishops only need 5 bits instead of 6 (they can't move to a square of different color), shaving 2 bits and thus reaching exactly 26 bytes. BTW 495 can be computed as a binomial coefficient C(8+5-1,5-1), the number of combinations of 8 elements chosen with repetitions from 5 elements.

Should be able to shave 4 bits, cause there's four bishops?

Re: How to store a chess position in 26 bytes (2022)

#22
post #19

I don't understand the castling part of this - you can move a rook from its starting square and back and castling isn't available - it says that you can determine whether castling is available from the location of the pieces?

If the rook has the king's position, it's never moved. As soon as it moves, it can have any position except the king's.

Re: How to store a chess position in 26 bytes (2022)

#23
There's a logic error from assuming that because the rook is in its original position that the rook has not moved. Also I'm not sure if en passant is available if the pawn has moved from its home file, even if it subsequently moved back - so you can't assume either of these just by looking at the piece's position.

I think that you need one extra bit, that can contextually encode "rook has moved" or "en passant available".

Re: How to store a chess position in 26 bytes (2022)

#24
post #23

There's a logic error from assuming that because the rook is in its original position that the rook has not moved. Also I'm not sure if en passant is available if the pawn has moved from its home file, even if it subsequently moved back - so you can't assume either of these just by looking at the piece's position. I think that you need one extra bit, that can contextually encode "rook has moved" or "en passant availa…

If the rook has the king's position, it's never moved. As soon as it moves, it can have any position except the king's.

Re: How to store a chess position in 26 bytes (2022)

#25
post #23

There's a logic error from assuming that because the rook is in its original position that the rook has not moved. Also I'm not sure if en passant is available if the pawn has moved from its home file, even if it subsequently moved back - so you can't assume either of these just by looking at the piece's position. I think that you need one extra bit, that can contextually encode "rook has moved" or "en passant availa…

You could decide if the en passant location is plausible from the position and color of the pawn on ranks 3 & 6, since it's only available of a pawn has moved two squares, so must be on rank 3 or 6, and it hasn't been promoted(another way it could reach those ranks)

Re: How to store a chess position in 26 bytes (2022)

#26
post #15

Either we have to say that the position does not dictate the possible moves, or that this does not fully capture the position. The problem here is that drawing can become an option or a requirement based on information that this representation doesn't capture. First the simpler version of this problem. After 50 full moves without a capture or pawn move, a draw MAY be claimed. After 75 moves, a draw MUST be claimed. T…

Problem need to include the year in the encoding then

Re: How to store a chess position in 26 bytes (2022)

#27
post #8

Earlier quoted context omitted.

If you are writing a chess engine you'll want to store hundreds of millions of positions while you search for the best move and at that scale a byte is important because it gets multiplied by an enormous factor.

But that is a totally different problem which requires far fewer bytes to represent. For that problem you are just considering of the valid pieces which made a move and what board that came from. Storing a single move is far cheaper than an entire board state.

Not when you include transpositions, where you arrive at the same position from a different move order, in which case saving board states instead of moves could be very valuable.

Re: How to store a chess position in 26 bytes (2022)

#28
post #15

Either we have to say that the position does not dictate the possible moves, or that this does not fully capture the position. The problem here is that drawing can become an option or a requirement based on information that this representation doesn't capture. First the simpler version of this problem. After 50 full moves without a capture or pawn move, a draw MAY be claimed. After 75 moves, a draw MUST be claimed. T…

> Either we have to say that the position does not dictate the possible moves, or that this does not fully capture the position.

It does not fully capture the history needed for determining future claims of draw by repetition. But by definition, the position fully captures the position.

The notion of position used by the FEN notation [1] includes the board diagram, side to move, castling rights, en-passant options, as well as the number of halfmoves since the last capture or pawn advance, and the total number of moves. The last one or last two are often ignored in everyday notions of position.

[1] https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notati...

Re: How to store a chess position in 26 bytes (2022)

#29
post #20
post #15

Either we have to say that the position does not dictate the possible moves, or that this does not fully capture the position. The problem here is that drawing can become an option or a requirement based on information that this representation doesn't capture. First the simpler version of this problem. After 50 full moves without a capture or pawn move, a draw MAY be claimed. After 75 moves, a draw MUST be claimed. T…

The question is, are we storing the state of a chess game, or the state of a chess board? If a game, you might also include timers or other state as well, including full position history.

You may even need envelope encryption for the currently unrevealed post-adjournment move.

Re: How to store a chess position in 26 bytes (2022)

#30
post #24
post #23

There's a logic error from assuming that because the rook is in its original position that the rook has not moved. Also I'm not sure if en passant is available if the pawn has moved from its home file, even if it subsequently moved back - so you can't assume either of these just by looking at the piece's position. I think that you need one extra bit, that can contextually encode "rook has moved" or "en passant availa…

If the rook has the king's position, it's never moved. As soon as it moves, it can have any position except the king's.

To make this work, the rook can only have the king's position, if neither the king nor that rook have moved.
Post reply on HN