Chess moves
Write a function that determines if a chess piece, on an empty board, can move from one space to another in one move.
Examples
(can-move? :pawn "A2" "A3") ;=> true
(can-move? :queen "H1" "A8") ;=> true
(can-move? :knight "A4" "A5") ;=> false ;; (that's not how knights move)
(can-move? :king "A8" "A9") ;=> false ;; (that's off the board)
Notes
- This page has a nice graphic of all of the chess pieces and their moves.
- Assume that pawns are moving from the low to the high numbers.
- You can ignore en passant, pawn's capture, castling, and pawn's two-square move on the second rank.
Thanks to this site for the problem idea, where it is rated Very Hard in Java. The problem has been modified.
Please submit your solutions as comments on this gist.
To subscribe: https://purelyfunctional.tv/newsletter/
@jonasseglare
Your solution is just brilliant (even though obfuscated :)! I am enjoying picking it apart.
So far I can gather that you encoded all valid moves as indexes into a table (string) of characters, each of which's
underlying int has its compatible pieces' bits set - very clever.
I still have to figure out precisely how you managed to organize and encode all 225 (from the table size)
valid moves across all pieces.
Nice work!