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.

28 lines
762 B

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