Sunday, March 24, 2013

[iowcmfqz] Chess utility functions

Given a FEN position (or Shredder-FEN or X-FEN for Chess960), generate an array of pieces, e.g., for display.

Given an array of pieces and additional information, generate FEN notation.

Given a position and a move in one of the several shorthand notations, most notably standard algebraic notation (SAN), convert it into a "long-form" move with which one can straightforwardly query origin and destination, piece moved, piece captured, promotion, en passant.

Given a position and a "long-form" move, convert it to SAN.

Given a position and a "long-form" move but with some of the fields missing, fill in the missing fields if not ambiguous. If it is ambiguous, give all the possibilities.  This should be straightforward via generating a list of all legal long-form moves and doing pattern matching.

Given a position and a move, generate the next position.

Determine whether a move is legal in a position.

Given a position, give all the legal moves.

Given a position, determine whether the player's king is in check.

Given a position, determine whether the opponent's king may be immediately captured, i.e., it is an illegal position.

Support analyzing move sequences (e.g., generating the next position given a move) in which illegal moves were made.  This may happen in real life if both players didn't notice a king was in check.

Given a position, determine all the immediately prior moves which could have resulted the position (retrograde analysis).

Given a position and a previous move, calculate the previous position (retrograde analysis).

Determine whether a square is "attacked".  This is a fuzzy question interacting with kings being in check.  It may be possible to implement this using null moves.

Support null moves.  This should be easy; just flip the player-to-move in FEN.

Support some fairy chess pieces.

Support chess variants where king capture is legal.

Perl Chess::Rep can do many of these.

No comments :