CPG/src/Chess/player.nim

22 lines
581 B
Nim
Raw Normal View History

2023-10-13 11:54:57 +02:00
import board as chess
2023-10-16 22:14:58 +02:00
import std/strformat
import std/strutils
2023-03-18 18:14:30 +01:00
2023-10-16 14:55:43 +02:00
2023-10-16 22:14:58 +02:00
var
board = newChessboardFromFEN("rnbqkbnr/8/8/8/8/8/8/RNBQKBNR w KQkq - 0 1")
startSquare: string
targetSquare: string
move: Move
while true:
echo board.pretty()
echo &"Turn: {board.getActiveColor()}"
stdout.write("From -> ")
startSquare = readLine(stdin).strip(chars={'\0', ' '})
stdout.write("To -> ")
targetSquare = readLine(stdin)
try:
move = board.makeMove(startSquare, targetSquare)
except ValueError:
echo &"Error: {getCurrentExceptionMsg()}"