ychess is a chess implementation written in nim.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
760 B

  1. import ./chess
  2. proc runGame*(): void =
  3. ## Initializes and runs a game of chess.
  4. var game = initGame()
  5. var draw: string
  6. game.echoBoard(game.toMove)
  7. while not game.isCheckmate(game.toMove) and not game.isStalemate(game.toMove):
  8. echo "Make a move"
  9. echo game.toMove
  10. var move = readLine(stdin)
  11. while not game.checkedMove(notationToMove(move, game.toMove)):
  12. move = readLine(stdin)
  13. game.echoBoard(game.toMove)
  14. if (game.isDrawClaimable):
  15. echo "Do you want to claim a draw? (y/N)"
  16. draw = readLine(stdin)
  17. if (draw == "y"):
  18. echo "Draw claimed"
  19. break
  20. if game.isCheckmate(game.toMove):
  21. echo $game.toMove & " was checkmated"
  22. if game.isStalemate(game.toMove):
  23. echo "Stalemate"
  24. runGame()