Hacker News new | ask | show | jobs
by porkbrain 818 days ago
As for promotion: in a valid chess position you could promote a single pawn at three files simultaneously. One by moving forward and then left and right capture. Additionally, you could have two pawns promoting on the same square, again with capture. And you can have a combination of both.

Encode a white's move exd8=N with white pawns on e7 and c7 and three black queens on f8, d8 and b8.

3 comments

> you could promote a single pawn at three files simultaneously. One by moving forward and then left and right capture.

Ooh, didn't think of that, thanks. Still there's enough constraint in the legal destination squares to work around that. There's at least half the board that's inaccessible to a pawn about to promote, which should be enough to encode any of the 3 legal destination squares and 5 possible promotion targets.

Edit: maybe keep the destination file as-is, and use the destination rank to encode the promotion piece?

> Additionally, you could have two pawns promoting on the same square

The source square should disambiguate between those though, right?

You can encode a promotion as the destination file plus rank 1-4 for the 4 different kinds, since pawns can't move backwards
Promotions could be compressed to

Source position -> 6 bits destination position as ( forward left / forward / forward right -> 2 bits Target piece info Queen/Bishop/Knight/Rook 2 bits )