Initial work for UCI mode

This commit is contained in:
Mattia Giambirtone 2024-04-09 17:55:12 +02:00
parent 57353c0994
commit c1ac5ea5c3
1 changed files with 23 additions and 5 deletions

View File

@ -2079,6 +2079,17 @@ proc handlePositionCommand(board: var ChessBoard, command: seq[string]) =
echo board.pretty()
proc handleUCICommand(board: var ChessBoard, command: seq[string]): bool =
if len(command) != 1:
echo "error: uci: invalid number of arguments"
return false
echo "id name Nimfish 0.1"
echo "id author Nocturn9x & Contributors (see LICENSE)"
# TODO
echo "uciok"
return true
const HELP_TEXT = """Nimfish help menu:
- go: Begin a search
Subcommands:
@ -2112,26 +2123,33 @@ const HELP_TEXT = """Nimfish help menu:
- pretty: Shorthand for "position pretty"
- print: Shorthand for "position print"
- get <square>: Get the piece on the given square
- uci: enter UCI mode (WIP)
"""
proc main: int =
## Nimfish's control interface
echo "Nimfish by nocturn9x (see LICENSE)"
var board = newDefaultChessboard()
var
board = newDefaultChessboard()
uciMode = false
while true:
var
cmd: seq[string]
cmdStr: string
try:
stdout.write(">>> ")
stdout.flushFile()
if not uciMode:
stdout.write(">>> ")
stdout.flushFile()
cmdStr = readLine(stdin).strip(leading=true, trailing=true, chars={'\t', ' '})
if cmdStr.len() == 0:
continue
cmd = cmdStr.splitWhitespace(maxsplit=2)
case cmd[0]:
of "uci":
if handleUCICommand(board, cmd):
uciMode = true
of "clear":
echo "\x1Bc"
of "help":
@ -2156,12 +2174,12 @@ proc main: int =
echo "En passant target: None"
of "get":
if len(cmd) != 2:
echo "get: invalid syntax"
echo "error: get: invalid number of arguments"
continue
try:
echo board.getPiece(cmd[1])
except ValueError:
echo "get: invalid square"
echo "error: get: invalid square"
continue
of "castle":
let canCastle = board.canCastle()