Re:Compressing Chess Moves for Fun and Profit
by stevage on Friday March 15, 2024 @07:45PM
(#39721871)
That's really cute.
I'm surprised stalemate detection is harder than checkmate detection. Aren't they the same except checkmate has the extra step of detecting check?
Re:Compressing Chess Moves for Fun and Profit
by bubblyworld on Saturday March 16, 2024 @01:36AM
(#39723638)
Not quite - stalemate is no legal move whatsoever for any of your pieces, and checkmate is king is in check and no legal move stops check.
Re:Compressing Chess Moves for Fun and Profit
by stevage on Saturday March 16, 2024 @02:31AM
(#39723807)
But given that a legal move by definition ends with the king not in check, the distinction often kind of goes away. In implementation terms, I think you basically have to just look at every possible move of every piece and see if any of them end without being in check.
Stalemate can and almost always does involve pieces that can't move because they would create check.
Re:Compressing Chess Moves for Fun and Profit
by bubblyworld on Saturday March 16, 2024 @04:11AM
(#39724165)
Yeah, that's true, I see what you're saying. I guess knowing the king is already in check allows for optimisations, since you have to either move the king, capture the attacker or block the line of attack, and nothing else is legal. And if you're double-checked you have to move the king, no matter what. As opposed to stalemate where you really do have to check the moves of every piece.
Re:Compressing Chess Moves for Fun and Profit
by stevage on Saturday March 16, 2024 @10:36PM
(#39731446)
I guess that could be true if you have ready access to things like "the attacker" and "pieces that are capable of moving to block the line of attack".
Re:Compressing Chess Moves for Fun and Profit
by jstanley on Sunday March 17, 2024 @07:19AM
(#39733632)
It's just because of the chess.js API. It tells you if any given move is a checkmate, so you know to ignore those moves without playing them, but to find out if a move is a stalemate, you need to "play it" on a cloned game and then see if the opponent has any legal moves.
(My implementation: https://incoherency.co.uk/chess-steg/ and explanation at https://incoherency.co.uk/blog/stories/chess-steg.html )