CPG/src/Chess/player.nim

22 lines
581 B
Nim

import board as chess
import std/strformat
import std/strutils
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()}"