From c1ac5ea5c3b0cdbff355ab401a6f64c37c2c4a70 Mon Sep 17 00:00:00 2001 From: nocturn9x Date: Tue, 9 Apr 2024 17:55:12 +0200 Subject: [PATCH] Initial work for UCI mode --- src/Chess/board.nim | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Chess/board.nim b/src/Chess/board.nim index 129b47c..11242fe 100644 --- a/src/Chess/board.nim +++ b/src/Chess/board.nim @@ -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 : 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()