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.

29 lines
806 B

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