aboutsummaryrefslogtreecommitdiff
path: root/src/uci.cpp
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-07-28 19:03:20 +0200
committerAdam <adammegarules1@gmail.com>2026-07-28 19:03:20 +0200
commit40e242dc5450e1661c817b0bad8f9748388c278a (patch)
tree569053925f92516b1ee52a7e21ed9e1c75e1e3a0 /src/uci.cpp
parentb2dbf812cb9e6da5f69a2b74c24c97d09fa7a684 (diff)
removing repl and unsuded featuares
Diffstat (limited to 'src/uci.cpp')
-rw-r--r--src/uci.cpp167
1 files changed, 11 insertions, 156 deletions
diff --git a/src/uci.cpp b/src/uci.cpp
index 6f0e5e6..1f634fe 100644
--- a/src/uci.cpp
+++ b/src/uci.cpp
@@ -7,8 +7,6 @@
#include <algorithm>
#include <cassert>
#include <cctype>
-#include <cstdint>
-#include <cstdlib>
#include <iostream>
#include <print>
#include <sstream>
@@ -33,20 +31,7 @@ void LogUci(const std::string &message) {
uciLog.flush();
}
using namespace std;
-bool isValidChessRank(char rank) {
- if (rank >= '1' && rank <= '8') {
- return true;
- } else {
- return false;
- }
-}
-bool isValidChessFile(char rank) {
- if (rank >= 'A' && rank <= 'H') {
- return true;
- } else {
- return false;
- }
-}
+
Move UciToMove(string uci) {
Position from;
Position to;
@@ -69,6 +54,16 @@ static Game initBoard(string startingFEN) {
b.halfMoveClock = 0;
b.MoveClock = 0;
setBoardFen(startingFEN, &b);
+
+ Piece EmptyPiece = {
+ false,
+ NONE,
+ false,
+ };
+ for (int i = 0; i < 64; i++) {
+ b.pieces[i] = EmptyPiece;
+ };
+
return b;
};
void Uci() {
@@ -161,143 +156,3 @@ void Uci() {
}
}
}
-int startREPL() {
-
- Game g =
- initBoard("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
- Game *b = &g;
- printBoard(b);
- while (true) {
- GetLegalMoves(b);
- if (b->state == STALEMATE) {
- printBoard(b);
- std::println();
- std::cout << "\033[1mStalemate\033[0m" << "\n";
- std::println();
- return 0;
- }
- if (b->state == DRAW) {
- printBoard(b);
- std::println();
- std::cout << "\033[1mDraw\033[0m" << "\n";
- std::println();
- return 0;
- }
- if (b->state == WHITE_WON) {
- printBoard(b);
- std::cout << "\033[1mChechmate White won\033[0m" << "\n";
- return 0;
- }
- if (b->state == BLACK_WON) {
- printBoard(b);
- std::cout << "\033[1mCheckmate Black won\033[0m" << "\n";
- return 0;
- }
- if (b->state == TURN) {
- if (true) {
- Move move = EngineGetBestMove(b);
- MakeMove(move, b);
- printBoard(b);
- continue;
- }
- }
- std::cout << "> ";
- std::string command;
- if (!(std::cin >> command)) {
- std::println();
- std::cout << "Exiting...\n";
- return EXIT_SUCCESS;
- }
-
- std::transform(command.begin(), command.end(), command.begin(), ::toupper);
-
- std::cout << command << "\n";
- if (command == "EXIT") {
- std::println();
- std::cout << "Exiting...\n";
- return EXIT_SUCCESS;
- }
- if (command == "RESING") {
- std::cout << "\033[1mOK\033[0m" << "\n";
- if (b->turn) {
- b->state = BLACK_WON;
- } else {
- b->state = WHITE_WON;
- }
- continue;
- }
- if (command == "BOARD") {
- printBoard(b);
- continue;
- }
- if (command == "MOVES" || command == "MOVE") {
- auto moves = GetLegalMoves(b);
- PrintMoves(moves);
- continue;
- }
- if (command.length() != 4) {
- std::cout << "Unknown Command, use EXIT to exit";
- std::println();
- continue;
- }
- if (b->state == TURN) {
- if (!isValidChessFile(command[0])) {
- std::cout << "ERROR: Expected valid file at first place";
- std::println();
- continue;
- }
-
- if (!isValidChessRank(command[1])) {
- std::cout << "ERROR: Expected valid rank at second place";
- std::println();
- continue;
- }
-
- if (!isValidChessFile(command[2])) {
- std::cout << "ERROR: Expected valid file at third place";
- std::println();
- continue;
- }
-
- if (!isValidChessRank(command[3])) {
- std::cout << "ERROR: Expected valid rank at four place";
- std::println();
- continue;
- }
-
- // we know its a valid chess pos
- int fromFile = command[0] - 'A';
- int fromRank = '8' - command[1];
- int toFile = command[2] - 'A';
- int toRank = '8' - command[3];
- std::cout << fromFile << "\n";
- std::cout << fromRank << "\n";
- std::cout << toFile << "\n";
- std::cout << toRank << "\n";
- Move move = {
- {static_cast<uint8_t>(fromRank), static_cast<uint8_t>(fromFile)},
- {static_cast<uint8_t>(toRank), static_cast<uint8_t>(toFile)}};
-
- auto moves = GetLegalMoves(b);
- if (!(std::ranges::find(moves, move) != moves.end())) {
- std::cout << "Invalid move!";
- std::println();
- PrintMoves(moves);
- continue;
- }
- std::println();
- MakeMove(move, b);
- printBoard(b);
- }
- }
-}
-
-void PrintMoves(const std::vector<Move> &moves) {
- std::cout << "Moves (" << moves.size() << "):\n";
-
- for (const Move &move : moves) {
- std::cout << (char)((int)move.From.file + 'A') << 8 - (int)move.From.rank
- << " -> " << (char)((int)move.To.file + 'A')
- << 8 - (int)move.To.rank << "\n";
- }
-}