4 ms·
I'm actually realizing - you can simply have a case where if a white/black pawn is on the 4th/5th rank, have the next bit be a flag for en passant. This makes a
by alexb_ 3y ago
I'm actually realizing - you can simply have a case where if a white/black pawn is on the 4th/5th rank, have the next bit be a flag for en passant. This makes all en passant rules stored in 8 bits at max. Since only 1 pawn can be in a status of "en passantable" at a time, we can make it stop assigning a flag bit for future pawns if the answer is ever "yes".
- Dylan16807 3y ago8 flag bits is a lot though when we're trying to shave down 20-ish bytes! And we're only worried about the worst case scenario, so assume it's the last pawn in the list. Also you can have at least 10 pawns visibly at risk of en passant at once. If you base it on rank alone, you can have all 16 pawns in position at the same time, wasting 16 bits. If you're going to explicitly store it, at least squeeze down to 4 bits to pick a specific pawn (and picking one visibly not at risk if no pawn is at risk). But using clever piece rearrangements is a lot better than spending flag bits.
- LorenPechtel 3y agoYou can have only one en passant situation on the board at once. This means you can use 3 bits to encode the column for en passant, you check the board to evaluate the legality of the solution and discard if it isn't legal (this means you don't have to use a bit to encode whether it's possible as the encoder is guaranteed to be able to pick a column that it's not possible.)
- Dylan16807 3y agoYou can have two pawns in the same column in plausible en passant position after pawns cross over via capture. Of course after a capture you have more bits free, but you need to do something more complex than encoding the column.
- LorenPechtel 3y agoI think we are both wrong. En passant only exists for one move, whatever has happened from captures is irrelevant. However, now I realize you can have two possible en passant captures at once--a pawn moves to 4th rank between two opposing pawns on the 4th rank.
- alexb_ 3y agoThat's just not true. Pawns can only be captured en passant on one rank for each color.
- Dylan16807 3y agoYes 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.
- mlyle 3y agoPart of a chess position is whose turn to move. That has to be encoded anyways.
- Dylan16807 3y agoI guess, but the article wasn't trying to do so.