diff options
| author | Adam <adammegarules1@gmail.com> | 2026-08-15 20:47:22 +0200 |
|---|---|---|
| committer | Adam <adammegarules1@gmail.com> | 2026-08-15 20:47:22 +0200 |
| commit | 242b2022ae234e252fe410b276e6d7c971147980 (patch) | |
| tree | 6352cc5b7247d1d7ca688b15ec71122696682f94 | |
| parent | 831411d0a4fd7f67d6a27a6275dec0c6513a23f2 (diff) | |
renaming things
| -rw-r--r-- | src/board/board.cpp | 6 | ||||
| -rw-r--r-- | src/board/board.hpp | 6 | ||||
| -rw-r--r-- | src/bot.cpp | 12 | ||||
| -rw-r--r-- | src/misc.cpp | 31 | ||||
| -rw-r--r-- | src/moves.cpp | 4 | ||||
| -rw-r--r-- | src/uci.cpp | 9 |
6 files changed, 42 insertions, 26 deletions
diff --git a/src/board/board.cpp b/src/board/board.cpp index a533b63..7538a9b 100644 --- a/src/board/board.cpp +++ b/src/board/board.cpp @@ -88,12 +88,12 @@ uint8_t getToValueFromMove(uint16_t move) { return (move >> 8) & 63; }; Position FindKing(Game *g, bool color) { return IndexToPosition(__builtin_ctzll(g->PieceBitboards[color][KING])); } -UndoMove MakeMove(uint16_t move, Game *g) { +Undo MakeMove(uint16_t move, Game *g) { uint8_t fromSquare = getFromValueFromMove(move); uint8_t toSquare = getToValueFromMove(move); PieceType promotion = getPromotionTypeFromMove(move); - UndoMove undo = {}; + Undo undo = {}; undo.from = fromSquare; undo.to = toSquare; @@ -340,7 +340,7 @@ UndoMove MakeMove(uint16_t move, Game *g) { } return undo; }; -void UnMakeMove(UndoMove undo, Game *g) { +void UndoMove(Undo undo, Game *g) { g->pieces[undo.from] = undo.movedPiece; g->pieces[undo.to] = undo.capturedPiece; diff --git a/src/board/board.hpp b/src/board/board.hpp index b24811c..133a280 100644 --- a/src/board/board.hpp +++ b/src/board/board.hpp @@ -71,7 +71,7 @@ struct Game { std::unordered_map<uint64_t, TranspositionsEntry> *Transpositions = nullptr; }; -struct UndoMove { +struct Undo { Piece movedPiece; Piece capturedPiece; @@ -102,8 +102,8 @@ struct UndoMove { }; int PositionToIndex(Position i); -UndoMove MakeMove(uint16_t move, Game *g); -void UnMakeMove(UndoMove undo, Game *g); +Undo MakeMove(uint16_t move, Game *g); +void UndoMove(Undo undo, Game *g); Position FindKing(Game *g, bool color); void UpdateHelpers(Game *g); diff --git a/src/bot.cpp b/src/bot.cpp index 42fa4b6..03a0727 100644 --- a/src/bot.cpp +++ b/src/bot.cpp @@ -123,11 +123,11 @@ static int quiescenceSearch(Game *b, int qdepth, int alpha, int beta, int ply) { auto moves = GetSortedLegalMoves(b, false, nullptr); for (uint16_t move : moves) { - UndoMove undo = MakeMove(move, b); + Undo undo = MakeMove(move, b); int score = -quiescenceSearch(b, qdepth + 1, -beta, -alpha, ply + 1); - UnMakeMove(undo, b); + UndoMove(undo, b); if (score >= beta) { return beta; @@ -198,11 +198,11 @@ static int search(int depth, Game *b, int alpha, int beta, int ply) { int bestScore = -INF; for (uint16_t move : moves) { - UndoMove undo = MakeMove(move, b); + Undo undo = MakeMove(move, b); int score = -search(depth - 1, b, -beta, -alpha, ply + 1); - UnMakeMove(undo, b); + UndoMove(undo, b); if (searchStopped) { break; } @@ -254,11 +254,11 @@ static SearchResult SearchDepth(Game *b, int depth, int alpha = -INF; int beta = INF; for (uint16_t move : moves) { - UndoMove undo = MakeMove(move, b); + Undo undo = MakeMove(move, b); int eval = -search(depth - 1, b, -beta, -alpha, 1); - UnMakeMove(undo, b); + UndoMove(undo, b); if (searchStopped) { break; diff --git a/src/misc.cpp b/src/misc.cpp index 79cf74f..6737777 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -2,19 +2,32 @@ #include "moves.hpp" #include <cstdint> #include <string_view> +#include <vector> +/* + * Return engine name with version number + */ std::string_view engine_info() { return "Mono 1\n"; } -uint64_t MoveGenTest(int depth, Game *g) { - uint64_t num = 0; - if (depth <= 0) { +/* + * Returns total possible branches with depth X + */ +uint64_t MoveGenTest(uint32_t depth, Game *g) { + if (depth == 0) { return 1; } - auto moves = GetLegalMoves(g); - for (auto move : moves) { - UndoMove undo = MakeMove(move, g); - num += MoveGenTest(depth - 1, g); - UnMakeMove(undo, g); + + uint64_t positionCount = 0; + + std::vector<uint16_t> moves = GetLegalMoves(g); + + // for each possible move create new branch + for (uint16_t move : moves) { + Undo undo = MakeMove(move, g); + + positionCount += MoveGenTest(depth - 1, g); + + UndoMove(undo, g); } - return num; + return positionCount; } diff --git a/src/moves.cpp b/src/moves.cpp index a80f4c7..9e45ff5 100644 --- a/src/moves.cpp +++ b/src/moves.cpp @@ -328,7 +328,7 @@ std::vector<uint16_t> GetLegalMoves(Game *g, bool quietMove) { legalMoves.reserve(moves.size()); for (const uint16_t &move : moves) { - UndoMove undo = MakeMove(move, g); + Undo undo = MakeMove(move, g); bool legal = true; @@ -339,7 +339,7 @@ std::vector<uint16_t> GetLegalMoves(Game *g, bool quietMove) { legal = false; } - UnMakeMove(undo, g); + UndoMove(undo, g); if (legal) { legalMoves.push_back(move); diff --git a/src/uci.cpp b/src/uci.cpp index 92c7072..f435a06 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -145,12 +145,15 @@ static void printPromotionLetter(PieceType p) { assert(false && "Unexpected promotion type"); } } -static void printBoard(Game *g) { +/* + * Prints nice looking board + */ +static void printBoard(const Game &g) { for (int rank = 7; rank >= 0; --rank) { std::print("{0} |", rank + 1); for (int file = 0; file < 8; file++) { - Piece piece = g->pieces[(rank * 8) + file]; + Piece piece = g.pieces[(rank * 8) + file]; if (piece.type == NONEPIECE) { std::print(" 00"); @@ -277,7 +280,7 @@ void Uci() { return; } if (cmd == "board") { - printBoard(&game); + printBoard(game); } if (cmd == "bits") { DebugBitboards(&game); |
