Play a game (Chess)

PLAY <moves… plays moves written as <from<to (e2e4), with a promotion letter q r b n required when a pawn reaches the last rank (e7e8q). Each move must be by the side to move and legal, else print illegal move <move and stop. After each move print it, plus check if the opponent is now in check; if the opponent has no legal moves print checkmate, <winner wins or stalemate, draw and stop. Then print the board as in stage 1.

Input: A FEN line, then PLAY.

Output: One line per move, then the board.

Difficulty: Hard. Write your answer in the browser editor, run the examples, then submit it against hidden tests. Python and JavaScript are free; other languages are part of licode Club.

Hint

  • Switch sides after every move.

More Chess practice