People have pointed out that due to rules about no repeats, the full state requires storing previous moves. I’m fairly convinced that the most efficient encoding would be keeping only the move history and then playing that forward to obtain the board state. E.g.: there are only 32 distinct pieces so a 5-bit number can select one uniquely. Each piece has a maximum of about 32 positions it can move to. Then the encodin…
How to store a chess position in 26 bytes using bit-level magic (2022)
151–160 of 204 posts
Re: How to store a chess position in 26 bytes using bit-level magic (2022)
#1521. There is still redundancy in that there are multiple pieces of the same type, and if you permute their locations you get another representation of the same state. 2. You don't need to say that some pawn's location is the king if it's en passant. You can just use the back row, which pawns can't get to.
Using this, you can use the permutations of the pawns to store extra information. For instance, all of the pawns will be on the board at squares #a, #b, ... . Since pawns themselves have numerical indices, you could say that the "canonical" representation of the board state has all of the pawn locations sorted in ascending order. Then, different permutations of that can carry information about promotions and which of the "pawns" are really queens, etc.
Re: How to store a chess position in 26 bytes using bit-level magic (2022)
#153Storing a chess position in 26 bytes. Storing a game is also interesting. The number of legal moves varies depending on the position. You could try to define a variable length encoding by giving more likely moves a shorter encoding, but the ordering would need to be deterministic so it could be decoded (running Stockfish for a second isn't).
Re: How to store a chess position in 26 bytes using bit-level magic (2022)
#154Earlier quoted context omitted.
That's just not true. Pawns can only be captured en passant on one rank for each color.
Yes for each color . That means two pawns for each column can be in position to be captured en passant. And also two pawns can be in capturing position. Edit: Column combined with whose turn it is will work, but not just column.
Re: How to store a chess position in 26 bytes using bit-level magic (2022)
#155Minor point: the FIDE rules[1] state > Article 9: The Drawn Game > ... > 9.2 The game is drawn, upon a correct claim by a player having the move, when the same position for at least the third time (not necessarily by a repetition of moves) [happens and a draw is claimed] > 9.3 The game is drawn, upon a correct claim by a player having the move, if: ... 9.3.2 the last 50 moves by each player have been completed withou…
If a pawn moves then you can't repeat a state either, can you? So track the last 75 "moves". > they can only move forward, except in the case of en-passant En passant still attacks forward, into the space the enemy pawn just moved through. > 112 pawn moves without a capture (because there are only 16 pawns and they can only move forward But pawns can't move through pawns. ~~At most I think you can have 4 of the pawns…
You are correct.
So the board state from 75 moves previously plus 75 bytes to store the last 75 moves is sufficient to store a chess game state.
Re: How to store a chess position in 26 bytes using bit-level magic (2022)
#156People have pointed out that due to rules about no repeats, the full state requires storing previous moves. I’m fairly convinced that the most efficient encoding would be keeping only the move history and then playing that forward to obtain the board state. E.g.: there are only 32 distinct pieces so a 5-bit number can select one uniquely. Each piece has a maximum of about 32 positions it can move to. Then the encodin…
Re: How to store a chess position in 26 bytes using bit-level magic (2022)
#157Storing a chess position in 26 bytes. Storing a game is also interesting. The number of legal moves varies depending on the position. You could try to define a variable length encoding by giving more likely moves a shorter encoding, but the ordering would need to be deterministic so it could be decoded (running Stockfish for a second isn't).
Ok, we've positioned the title above. Thanks!
Re: How to store a chess position in 26 bytes using bit-level magic (2022)
#158Earlier quoted context omitted.
Are you saying that, to encode a valid position, ignoring the cost to encode both the starting position and the move definitions, you can encode the move sequence using less information than encoding a single position?
Yes, ignoring compression each (half-)move takes up one byte. So if you want to store a sequence of 10 (half-)moves it would take only 10 bytes.
Re: How to store a chess position in 26 bytes using bit-level magic (2022)
#159Earlier quoted context omitted.
Yes for each color . That means two pawns for each column can be in position to be captured en passant. And also two pawns can be in capturing position. Edit: Column combined with whose turn it is will work, but not just column.
Part of a chess position is whose turn to move. That has to be encoded anyways.
Re: How to store a chess position in 26 bytes using bit-level magic (2022)
#160People have pointed out that due to rules about no repeats, the full state requires storing previous moves. I’m fairly convinced that the most efficient encoding would be keeping only the move history and then playing that forward to obtain the board state. E.g.: there are only 32 distinct pieces so a 5-bit number can select one uniquely. Each piece has a maximum of about 32 positions it can move to. Then the encodin…
I agree with this for a typical-length game. But I'd guess its worst-case is inferior due to some pathologically long games.