From 92cd6b4cd6321437bcbccb6b7f4396e60ff888b7 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 27 Jul 2026 13:28:57 +0200 Subject: adding bot and fixing bugs --- src/repl.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/repl.cpp') diff --git a/src/repl.cpp b/src/repl.cpp index 783d96c..76f921e 100644 --- a/src/repl.cpp +++ b/src/repl.cpp @@ -25,8 +25,8 @@ bool isValidChessFile(char rank) { } int startREPL(Board *b) { printBoard(b); - GetLegalMoves(b); while (true) { + GetLegalMoves(b); if (b->state == STALEMATE) { printBoard(b); std::println(); @@ -36,14 +36,29 @@ int startREPL(Board *b) { } if (b->state == WHITE_WON) { printBoard(b); - std::cout << "\033[1mWhite won\033[0m" << "\n"; + std::cout << "\033[1mChechmate White won\033[0m" << "\n"; return 0; } if (b->state == BLACK_WON) { printBoard(b); - std::cout << "\033[1mBlack won\033[0m" << "\n"; + std::cout << "\033[1mCheckmate Black won\033[0m" << "\n"; return 0; } + if (b->state == TURN) { + if (!b->turn) { + auto moves = GetLegalMoves(b); + std::srand( + std::time(0)); // use current time as seed for random generator + int random_pos = std::rand() % + moves.size(); // Modulo to restrict the number of + // random values to be at most A.size()-1 + Move move = moves[random_pos]; + PlayMove(move, b); + b->turn = !b->turn; + printBoard(b); + continue; + } + } std::cout << "> "; std::string command; if (!(std::cin >> command)) { -- cgit v1.2.3