diff options
Diffstat (limited to 'src/repl.cpp')
| -rw-r--r-- | src/repl.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
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)) { |
