From 69a7855f96fae719e1b2abc995479123122de66a Mon Sep 17 00:00:00 2001 From: rektdie Date: Wed, 12 Mar 2025 13:04:44 +0100 Subject: [PATCH 1/7] started rewriting setbyfen + utils --- Makefile | 4 +- source/board.cpp | 175 +++++++---------------------------------------- source/board.h | 2 +- source/types.h | 6 +- source/uci.cpp | 5 ++ source/utils.h | 19 +++++ 6 files changed, 55 insertions(+), 156 deletions(-) create mode 100644 source/utils.h diff --git a/Makefile b/Makefile index 5b554bc..c391a73 100644 --- a/Makefile +++ b/Makefile @@ -29,11 +29,11 @@ OBJS := $(addprefix $(OBJ_DIR)/, $(notdir $(SRCS:.cpp=.o))) # Target executable $(EXE)$(EXE_EXT): $(OBJS) - $(CXX) -o $@ $^ -O3 -lpthread + $(CXX) -std=c++23 -o $@ $^ -O3 -lpthread # Rule to compile source files to object files $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR) - $(CXX) -c -o $@ $< -O3 -lpthread + $(CXX) -std=c++23 -c -o $@ $< -O3 -lpthread # Create the object directory if it doesn't exist $(OBJ_DIR): diff --git a/source/board.cpp b/source/board.cpp index b531a49..a976463 100644 --- a/source/board.cpp +++ b/source/board.cpp @@ -1,7 +1,10 @@ #include "board.h" #include "movegen.h" -#include #include "tt.h" +#include +#include +#include +#include "utils.h" static inline int prevEPTarget = noEPTarget; @@ -24,167 +27,39 @@ void Board::Reset() { hashKey = 0ULL; } -void Board::SetByFen(const char* fen) { +void Board::SetByFen(std::string_view fen) { Reset(); // Starting from top left - Bitboard currentSquare = 0x100000000000000; + int currSquare = a8; - int digits = 0; - while (*fen != ' ' && *fen) { - PIECE pieceType = Pawn; - COLOR pieceColor = Black; + std::vector tokens = split(fen, ' '); + std::vector pieceTokens = split(tokens[0], '/'); - switch (*fen) { - case 'p': - pieceType = Pawn; - pieceColor = Black; - break; - case 'P': - pieceType = Pawn; - pieceColor = White; - break; - case 'n': - pieceType = Knight; - pieceColor = Black; - break; - case 'N': - pieceType = Knight; - pieceColor = White; - break; - case 'b': - pieceType = Bishop; - pieceColor = Black; - break; - case 'B': - pieceType = Bishop; - pieceColor = White; - break; - case 'r': - pieceType = Rook; - pieceColor = Black; - break; - case 'R': - pieceType = Rook; - pieceColor = White; - break; - case 'k': - pieceType = King; - pieceColor = Black; - break; - case 'K': - pieceType = King; - pieceColor = White; - break; - case 'q': - pieceType = Queen; - pieceColor = Black; - break; - case 'Q': - pieceType = Queen; - pieceColor = White; - break; - case '/': - currentSquare = currentSquare >> (8 + digits); - digits = 0; - fen++; - continue; - default: - int num = (*fen) - 48; - fen++; - if (*fen != '/') { - currentSquare = currentSquare << num; - digits += num; + constexpr std::string_view pieceTypes = "pnbrqk"; + + for (std::string_view rank : pieceTokens) { + for (const char piece : rank) { + if (std::isdigit(piece)) { + currSquare += piece - '0'; + continue; } - continue; - } - pieces[pieceType] |= currentSquare; - colors[pieceColor] |= currentSquare; + bool side = std::islower(piece); + int pieceType = pieceTypes.find(std::tolower(piece)); - fen++; - if (*fen != '/') { - digits++; - currentSquare = currentSquare << 1; + colors[side].SetBit(currSquare); + pieces[pieceType].SetBit(currSquare); + + currSquare++; } + currSquare -= 16; } - fen++; // skipping previous space - int section = 0; + sideToMove = tokens[1] == "b"; - while (*fen) { - switch (*fen) { - case ' ': - fen++; - section++; - continue; - case 'w': - if (section == 0) { - sideToMove = White; - } - break; - case 'b': - if (section == 0) { - sideToMove = Black; - } - break; - case 'K': - castlingRights |= whiteKingRight; - break; - case 'Q': - castlingRights |= whiteQueenRight; - break; - case 'k': - castlingRights |= blackKingRight; - break; - case 'q': - castlingRights |= blackQueenRight; - break; - default: - if (*fen != '-') { - if (section == 2) { - int passantFile; - switch (*fen) - { - case 'a': - passantFile = 0; - break; - case 'b': - passantFile = 1; - break; - case 'c': - passantFile = 2; - break; - case 'd': - passantFile = 3; - break; - case 'e': - passantFile = 4; - break; - case 'f': - passantFile = 5; - break; - case 'g': - passantFile = 6; - break; - case 'h': - passantFile = 7; - break; - } - fen++; - const int passantRank = *fen - 49; - enPassantTarget = passantFile + passantRank*8; - } - } - - break; - } - fen++; - } - - occupied = (colors[White] | colors[Black]); - GenAttackMaps(*this); - hashKey = GetHashKey(*this); + occupied = colors[White] | colors[Black]; + hashKey = GetHashKey(*this); } void Board::PrintBoard() { diff --git a/source/board.h b/source/board.h index f1e097a..bb7ffdf 100644 --- a/source/board.h +++ b/source/board.h @@ -31,7 +31,7 @@ public: void Init(); void Reset(); - void SetByFen(const char* fen); + void SetByFen(std::string_view fen); void PrintBoard(); void AddMove(Move move); diff --git a/source/types.h b/source/types.h index 7cc13b4..48d28f2 100644 --- a/source/types.h +++ b/source/types.h @@ -4,9 +4,9 @@ using U64 = uint64_t; -constexpr char StartingFen[] = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; -constexpr char KiwiPeteFen[] = "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -"; -constexpr char KillerFen[] = "6k1/3q1pp1/pp5p/1r5n/8/1P3PP1/PQ4BP/2R3K1 w - - 0 1"; +constexpr std::string_view StartingFen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; +constexpr std::string_view KiwiPeteFen = "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -"; +constexpr std::string_view KillerFen = "6k1/3q1pp1/pp5p/1r5n/8/1P3PP1/PQ4BP/2R3K1 w - - 0 1"; enum COLOR { White, diff --git a/source/uci.cpp b/source/uci.cpp index 42480b0..b0f1e2c 100644 --- a/source/uci.cpp +++ b/source/uci.cpp @@ -258,5 +258,10 @@ void UCILoop(Board &board) { Perft(board, ReadParam("perft", input)); continue; } + + if (input.find("print") != std::string::npos) { + board.PrintBoard(); + continue; + } } } diff --git a/source/utils.h b/source/utils.h new file mode 100644 index 0000000..e76ea95 --- /dev/null +++ b/source/utils.h @@ -0,0 +1,19 @@ +#pragma once +#include +#include +#include +#include + +std::vector split(std::string_view str, char delim) { + std::vector results; + + std::istringstream stream(std::string{str}); + + for (std::string token{}; std::getline(stream, token, delim);) { + if (token.empty()) continue; + + results.push_back(token); + } + + return results; +} \ No newline at end of file -- 2.47.3 From ad6ee77a465a17dab41817a5a7c70fc1c300d5f5 Mon Sep 17 00:00:00 2001 From: rektdie Date: Wed, 12 Mar 2025 14:30:12 +0100 Subject: [PATCH 2/7] finished setbyfen --- source/board.cpp | 14 ++++++++++++-- source/utils.h | 11 ++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/source/board.cpp b/source/board.cpp index a976463..626650b 100644 --- a/source/board.cpp +++ b/source/board.cpp @@ -58,8 +58,18 @@ void Board::SetByFen(std::string_view fen) { sideToMove = tokens[1] == "b"; - occupied = colors[White] | colors[Black]; - hashKey = GetHashKey(*this); + for (const char piece : tokens[2]) { + if (piece == 'K') castlingRights |= whiteKingRight; + else if (piece == 'Q') castlingRights |= whiteQueenRight; + else if (piece == 'k') castlingRights |= blackKingRight; + else if (piece == 'q') castlingRights |= blackQueenRight; + } + + if (tokens[3] != "-") enPassantTarget = parseSquare(tokens[3]); + + occupied = colors[White] | colors[Black]; + hashKey = GetHashKey(*this); + GenAttackMaps(*this); } void Board::PrintBoard() { diff --git a/source/utils.h b/source/utils.h index e76ea95..6e5ffe0 100644 --- a/source/utils.h +++ b/source/utils.h @@ -16,4 +16,13 @@ std::vector split(std::string_view str, char delim) { } return results; -} \ No newline at end of file +} + +int parseSquare(std::string_view str) { + constexpr std::string_view files = "abcdefgh"; + + int file = files.find(str[0]); + int rank = str[1] - '0'; + + return file + rank * 8; +} -- 2.47.3 From 7fb413fb01de07591f54714c92301a1a60b8905d Mon Sep 17 00:00:00 2001 From: rektdie Date: Wed, 12 Mar 2025 14:39:45 +0100 Subject: [PATCH 3/7] swapped every \n with std::endl --- source/bitboards.cpp | 10 +++++----- source/board.cpp | 20 ++++++++++---------- source/perft.cpp | 8 ++++---- source/search.cpp | 2 +- source/uci.cpp | 12 ++++++------ 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/source/bitboards.cpp b/source/bitboards.cpp index 9738321..4448f7d 100644 --- a/source/bitboards.cpp +++ b/source/bitboards.cpp @@ -3,7 +3,7 @@ void Bitboard::PrintBoard() const { for (int rank = 7; rank >= 0; rank--) { - std::cout << "+---+---+---+---+---+---+---+---+\n"; + std::cout << "+---+---+---+---+---+---+---+---+" << std::endl; std::cout << "| "; for (int file = 0; file < 8; file++) { @@ -15,12 +15,12 @@ void Bitboard::PrintBoard() const { std::cout << ". | "; } } - std::cout << ' ' << rank + 1 << '\n'; + std::cout << ' ' << rank + 1 << std::endl; } - std::cout << "+---+---+---+---+---+---+---+---+\n"; - std::cout << " a b c d e f g h\n\n"; - std::cout << " Board: 0x" << std::hex << m_board << '\n'; + std::cout << "+---+---+---+---+---+---+---+---+" << std::endl; + std::cout << " a b c d e f g h" << std::endl << std::endl; + std::cout << " Board: 0x" << std::hex << m_board << std::endl; } bool Bitboard::IsSet(int square) const { diff --git a/source/board.cpp b/source/board.cpp index 626650b..598a89f 100644 --- a/source/board.cpp +++ b/source/board.cpp @@ -76,7 +76,7 @@ void Board::PrintBoard() { for (int rank = 7; rank >= 0; rank--) { - std::cout << "+---+---+---+---+---+---+---+---+\n"; + std::cout << "+---+---+---+---+---+---+---+---+" << std::endl; std::cout << "| "; for (int file = 0; file < 8; file++) { @@ -97,21 +97,21 @@ void Board::PrintBoard() { std::cout << " | "; } } - std::cout << ' ' << rank + 1 << '\n'; + std::cout << ' ' << rank + 1 << std::endl; } - std::cout << "+---+---+---+---+---+---+---+---+\n"; - std::cout << " a b c d e f g h\n\n"; + std::cout << "+---+---+---+---+---+---+---+---+" << std::endl; + std::cout << " a b c d e f g h" << std::endl << std::endl; std::cout << " Side to move: "; if (!sideToMove) { - std::cout << "White\n"; + std::cout << "White" << std::endl; } else { - std::cout << "Black\n"; + std::cout << "Black" << std::endl; } if (enPassantTarget != noEPTarget) { - std::cout << " En Passant square: " << squareCoords[enPassantTarget] << '\n'; + std::cout << " En Passant square: " << squareCoords[enPassantTarget] << std::endl; } else { - std::cout << " En Passant square: None" << '\n'; + std::cout << " En Passant square: None" << std::endl; } std::cout << " Castling rights: "; @@ -119,9 +119,9 @@ void Board::PrintBoard() { if (castlingRights & whiteQueenRight) std::cout << "Q"; else std::cout << "-"; if (castlingRights & blackKingRight) std::cout << "k"; else std::cout << "-"; if (castlingRights & blackQueenRight) std::cout << "q"; else std::cout << "-"; - std::cout << "\n\n"; + std::cout << std::endl << std::endl; - std::cout << " Hashkey: " << std::hex << hashKey << '\n'; + std::cout << " Hashkey: 0x" << std::hex << hashKey << std::dec << std::endl; } void Board::AddMove(Move move) { diff --git a/source/perft.cpp b/source/perft.cpp index b9ca8da..8c89554 100644 --- a/source/perft.cpp +++ b/source/perft.cpp @@ -32,11 +32,11 @@ void Perft(Board &board, int depth) { totalNodes += nodeCount; board.moveList[i].PrintMove(); - std::cout << ": " << nodeCount << '\n'; + std::cout << ": " << nodeCount << std::endl; } - std::cout << "\nDepth: " << depth << '\n'; - std::cout << "Total nodes: " << totalNodes << '\n'; + std::cout << std::endl << "Depth: " << depth << std::endl; + std::cout << "Total nodes: " << totalNodes << std::endl; std::cout << "Time took: " << sw.GetElapsedSec() << "s ("; - std::cout << int(totalNodes / sw.GetElapsedSec()) << " nodes/sec)\n"; + std::cout << int(totalNodes / sw.GetElapsedSec()) << " nodes/sec)" << std::endl; } diff --git a/source/search.cpp b/source/search.cpp index 518371a..bb4274d 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -314,7 +314,7 @@ void SearchPosition(Board &board, SearchParams params) { std::cout << "bestmove "; results.bestMove.PrintMove(); - std::cout << '\n'; + std::cout << std::endl; } void StopSearch() { diff --git a/source/uci.cpp b/source/uci.cpp index b0f1e2c..eb7762e 100644 --- a/source/uci.cpp +++ b/source/uci.cpp @@ -170,11 +170,11 @@ static void SetOption(std::string &command) { } static void PrintEngineInfo() { - std::cout << "id name Eleanor\n"; - std::cout << "id author rektdie\n"; - std::cout << "option name Hash type spin default 5 min 1 max 64\n"; - std::cout << "option name Threads type spin default 1 min 1 max 1\n"; - std::cout << "uciok\n"; + std::cout << "id name Eleanor" << std::endl; + std::cout << "id author rektdie" << std::endl; + std::cout << "option name Hash type spin default 5 min 1 max 64" << std::endl; + std::cout << "option name Threads type spin default 1 min 1 max 1" << std::endl; + std::cout << "uciok" << std::endl; } void UCILoop(Board &board) { @@ -200,7 +200,7 @@ void UCILoop(Board &board) { // parse UCI "isready" command if (input.find("isready") != std::string::npos) { - std::cout << "readyok\n"; + std::cout << "readyok" << std::endl; continue; } -- 2.47.3 From 842cb45f38a8c76b31ef6f47e98f54560242fbb5 Mon Sep 17 00:00:00 2001 From: rektdie Date: Wed, 12 Mar 2025 16:55:36 +0100 Subject: [PATCH 4/7] bugfix in parseSquare + rewrote parseMove --- source/uci.cpp | 77 ++---------------------------------------------- source/uci.h | 3 -- source/utils.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++ source/utils.h | 25 ++++------------ 4 files changed, 75 insertions(+), 98 deletions(-) create mode 100644 source/utils.cpp diff --git a/source/uci.cpp b/source/uci.cpp index eb7762e..b1ff1cd 100644 --- a/source/uci.cpp +++ b/source/uci.cpp @@ -10,80 +10,7 @@ #include #include "tt.h" #include "perft.h" - -Move ParseMove(Board &board, const char* moveString) { - GenerateMoves(board, board.sideToMove); - - // Source square - std::string fromString = ""; - fromString += moveString[0]; - fromString += moveString[1]; - - auto it = std::find(squareCoords.begin(), squareCoords.end(), fromString); - - int from = std::distance(squareCoords.begin(), it); - - // Target square - std::string toString = ""; - toString += moveString[2]; - toString += moveString[3]; - - it = std::find(squareCoords.begin(), squareCoords.end(), toString); - - int to = std::distance(squareCoords.begin(), it); - std::string promotionString = ""; - - // Finding the move from available moves - for (Move move : board.moveList) { - if (move.MoveFrom() == from && move.MoveTo() == to) { - // Checking for promotion - if (std::string(moveString).length() == 5) { - int promotePiece = 0; - - // Checking for capture promotion - if (board.GetPieceColor(from) != board.GetPieceColor(to)) { - switch (moveString[4]) - { - case 'r': - promotePiece = rookPromoCapture; - break; - case 'q': - promotePiece = queenPromoCapture; - break; - case 'b': - promotePiece = bishopPromoCapture; - break; - case 'n': - promotePiece = knightPromoCapture; - break; - } - } else { - switch (moveString[4]) - { - case 'r': - promotePiece = rookPromotion; - break; - case 'q': - promotePiece = queenPromotion; - break; - case 'b': - promotePiece = bishopPromotion; - break; - case 'n': - promotePiece = knightPromotion; - break; - } - } - - return Move(from, to, promotePiece); - } - - return move; - } - } - - return Move(); -} +#include "utils.h" void ParsePosition(Board &board, const char* command) { command += 9; // Skip "position" @@ -121,7 +48,7 @@ void ParsePosition(Board &board, const char* command) { } if (!moveString.empty()) { - board.MakeMove(ParseMove(board, moveString.c_str())); + board.MakeMove(parseMove(board, moveString)); } } } diff --git a/source/uci.h b/source/uci.h index a355491..9f3e383 100644 --- a/source/uci.h +++ b/source/uci.h @@ -13,9 +13,6 @@ public: SearchParams(){} }; -// Returns Move object from a string -Move ParseMove(Board &board, const char* moveString); - // Initializes the position with given parameters void ParsePosition(Board &board, const char* command); diff --git a/source/utils.cpp b/source/utils.cpp new file mode 100644 index 0000000..3911661 --- /dev/null +++ b/source/utils.cpp @@ -0,0 +1,68 @@ +#include "utils.h" + +std::vector split(std::string_view str, char delim) { + std::vector results; + + std::istringstream stream(std::string{str}); + + for (std::string token{}; std::getline(stream, token, delim);) { + if (token.empty()) continue; + + results.push_back(token); + } + + return results; +} + +int parseSquare(std::string_view str) { + constexpr std::string_view files = "abcdefgh"; + + int file = files.find(str[0]); + int rank = str[1] - '0' - 1; + + return file + rank * 8; +} + +Move parseMove(Board &board, std::string_view str) { + int from = parseSquare(str.substr(0, 2)); + int to = parseSquare(str.substr(2, 2)); + + int flag = 0; + + // Promotion + if (str.length() > 4) { + if (board.GetPieceColor(from) != board.GetPieceColor(to)) { + switch(str[4]) { + case 'r': + flag = rookPromoCapture; + break; + case 'q': + flag = queenPromoCapture; + break; + case 'b': + flag = bishopPromoCapture; + break; + case 'n': + flag = knightPromoCapture; + break; + } + } else { + switch(str[4]) { + case 'r': + flag = rookPromotion; + break; + case 'q': + flag = queenPromotion; + break; + case 'b': + flag = bishopPromotion; + break; + case 'n': + flag = knightPromotion; + break; + } + } + } + + return Move(from, to, flag); +} diff --git a/source/utils.h b/source/utils.h index 6e5ffe0..6c23585 100644 --- a/source/utils.h +++ b/source/utils.h @@ -3,26 +3,11 @@ #include #include #include +#include "move.h" +#include "board.h" -std::vector split(std::string_view str, char delim) { - std::vector results; +std::vector split(std::string_view str, char delim); - std::istringstream stream(std::string{str}); +int parseSquare(std::string_view str); - for (std::string token{}; std::getline(stream, token, delim);) { - if (token.empty()) continue; - - results.push_back(token); - } - - return results; -} - -int parseSquare(std::string_view str) { - constexpr std::string_view files = "abcdefgh"; - - int file = files.find(str[0]); - int rank = str[1] - '0'; - - return file + rank * 8; -} +Move parseMove(Board &board, std::string_view str); -- 2.47.3 From 09f648e1f8c44061c27d9e4e938aa250bad8fa14 Mon Sep 17 00:00:00 2001 From: rektdie Date: Wed, 12 Mar 2025 18:33:23 +0100 Subject: [PATCH 5/7] refactored parseposition --- source/uci.cpp | 46 +++++++++++++++------------------------------- source/uci.h | 2 +- 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/source/uci.cpp b/source/uci.cpp index b1ff1cd..9d4a6d2 100644 --- a/source/uci.cpp +++ b/source/uci.cpp @@ -12,43 +12,27 @@ #include "perft.h" #include "utils.h" -void ParsePosition(Board &board, const char* command) { - command += 9; // Skip "position" - - if (strncmp(command, "fen", 3) == 0) { - command += 4; // Skip "fen " - - std::string fen; - while (*command && strncmp(command, " moves", 6) != 0) { - fen += *command; - command++; - } - - board.SetByFen(fen.c_str()); - - if (strncmp(command, " moves", 6) == 0) { - command += 6; // Skip " moves" - } - } else if (strncmp(command, "startpos", 8) == 0) { - command += 8; // Skip "startpos" +void ParsePosition(Board &board, std::string_view command) { + if (command.find("startpos") != std::string::npos) { board.SetByFen(StartingFen); + } - if (strncmp(command, " moves", 6) == 0) { - command += 6; // Skip " moves" + int fenIndex = command.find("fen"); + int movesIndex = command.find("moves"); + + if (fenIndex != std::string::npos) { + if (movesIndex != std::string::npos) { + board.SetByFen(command.substr(fenIndex + 4, movesIndex - 2 - (fenIndex + 3))); + } else { + std::cout << (command.substr(fenIndex + 4, command.length() - (fenIndex + 3))); } } - while (*command) { - while (*command == ' ') command++; // Skip spaces + if (movesIndex != std::string::npos) { + std::vector moves = split(command.substr(movesIndex + 6, command.length() - (movesIndex + 5)), ' '); - std::string moveString; - while (*command && *command != ' ') { - moveString += *command; - command++; - } - - if (!moveString.empty()) { - board.MakeMove(parseMove(board, moveString)); + for (std::string_view move : moves) { + board.MakeMove(parseMove(board, move)); } } } diff --git a/source/uci.h b/source/uci.h index 9f3e383..a565f06 100644 --- a/source/uci.h +++ b/source/uci.h @@ -14,7 +14,7 @@ public: }; // Initializes the position with given parameters -void ParsePosition(Board &board, const char* command); +void ParsePosition(Board &board, std::string_view command); // Parse UCI "go" command // GUI sends the engine this command if it should start searching for the best move -- 2.47.3 From ebb0a79962712740aafeb1efe116f4d66ac19183 Mon Sep 17 00:00:00 2001 From: rektdie Date: Wed, 12 Mar 2025 18:45:05 +0100 Subject: [PATCH 6/7] small changes in UCILoop --- source/uci.cpp | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/source/uci.cpp b/source/uci.cpp index 9d4a6d2..df80e11 100644 --- a/source/uci.cpp +++ b/source/uci.cpp @@ -7,7 +7,6 @@ #include "movegen.h" #include "search.h" #include "benchmark.h" -#include #include "tt.h" #include "perft.h" #include "utils.h" @@ -89,25 +88,11 @@ static void PrintEngineInfo() { } void UCILoop(Board &board) { - // reset STDIN & STDOUT buffers - setbuf(stdin, NULL); - setbuf(stdout, NULL); - - // define user / GUI input buffer std::string input = ""; // main loop while (true) { - // reset user / GUI input - getline(std::cin, input); - - // make sure output reaches the GUI - fflush(stdout); - - // make sure input is available - if (input[0] == '\n') { - continue; - } + std::getline(std::cin, input); // parse UCI "isready" command if (input.find("isready") != std::string::npos) { -- 2.47.3 From 8d097058fe51feee97e12cc8925c8e422a59bd31 Mon Sep 17 00:00:00 2001 From: rektdie Date: Wed, 12 Mar 2025 19:20:45 +0100 Subject: [PATCH 7/7] major bugfix in parseposition | bench 4118297 --- source/uci.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/uci.cpp b/source/uci.cpp index df80e11..36e8b5d 100644 --- a/source/uci.cpp +++ b/source/uci.cpp @@ -23,7 +23,7 @@ void ParsePosition(Board &board, std::string_view command) { if (movesIndex != std::string::npos) { board.SetByFen(command.substr(fenIndex + 4, movesIndex - 2 - (fenIndex + 3))); } else { - std::cout << (command.substr(fenIndex + 4, command.length() - (fenIndex + 3))); + board.SetByFen(command.substr(fenIndex + 4, command.length() - (fenIndex + 3))); } } -- 2.47.3