From 9e662e8e0c3baa35229034677232a2036cdefd5c Mon Sep 17 00:00:00 2001 From: rektdie Date: Fri, 7 Mar 2025 09:19:15 +0100 Subject: [PATCH 1/7] changed every cutoff to fail-soft --- source/search.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index 68be313..171de64 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -99,7 +99,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta) { int staticScore = Evaluate(board); if (staticScore >= beta) { - return beta; + return staticScore; } if (staticScore > alpha) { @@ -119,7 +119,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta) { int score = -Quiescence(copy, -beta, -alpha).score; if (score >= beta) { - return beta; + return score; } if (score > alpha) { @@ -236,7 +236,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { killerMoves[0][ply] = board.moveList[i]; WriteEntry(board.hashKey, depth, beta, CutNode, Move()); - return beta; + return score; } if (score > alpha) { From 8aa244da16b1279ea7ad079c887ae7f516ce1f27 Mon Sep 17 00:00:00 2001 From: rektdie Date: Fri, 7 Mar 2025 10:09:00 +0100 Subject: [PATCH 2/7] changed TT writing and reading to fail-soft --- README.md | 65 ----------------------------------------------- source/search.cpp | 3 +-- source/tt.cpp | 4 +-- 3 files changed, 3 insertions(+), 69 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 57c3b17..0000000 --- a/README.md +++ /dev/null @@ -1,65 +0,0 @@ -![Eleanor](https://i.ibb.co/T1ZV9wN/91dea356-a725-45fd-b7a2-cd92afddcba4-1.jpg) -# Eleanor is a chess engine -## Features - -- Bitboard board representation -- Magic Bitboards -- Legal move generation -- Precalculated attack tables -- Storing moves in a 16 bit word -- Copy/make moving -- Simple evaluation (material and piece-square tables, MVV-LVA) -- Principal Variation Search -- Move ordering -- Time management -- UCI - -## Installation - -> Prerequisites: -> - A C++ compiler -> - Access to `make` command - - 1. Clone the repo to your PC - - 2. Run the command `make` in the root directory - > You can specify the compiler with the flag `CXX` - > and the executable name with `EXE`. - > By default they are `g++` and `Eleanor` respectively. - -3. Run the executable - -## How to use -There are some commands that you can use the engine with. - -- **`position`**: Set the current position of the board with [FEN](https://www.chess.com/terms/fen-chess). -`position [FEN]` or `position startpos` can be used. -- **`ucinewgame`** resets the position and game state -- **`quit`** terminates the program -- **`go`** is the command that asks what is the best move in the current position (search), -but we have to give it some parameters: -`wtime` `btime` `winc` `binc` -The first letter tells the color of player -wtime sets the remaining time of the white player -and winc sets the increments for the white player. -**It's important that these parameters are given in milliseconds!** -- **`stop`** stops the current search -- **`bench`** tests the search speed of the engine on a set of positions - -Also, the engine can be connected to any GUI software that has UCI support. - -## Sources I used -[Chess Programming Wiki](https://www.chessprogramming.org/Main_Page "Chess Programming Wiki") - -[Maksim Korzh's chess engine in C series](https://www.youtube.com/watch?v=QUNP-UjujBM&list=PLmN0neTso3Jxh8ZIylk74JpwfiWNI76Cs "Maksim Korzh's chess engine in C series") - -[Stockfish discord helping community](https://discord.com/invite/GWDRS3kU6R "Stockfish discord community") - -[Logo is generated by AI](https://deepai.org/ "Logo is generated by AI") - -
- -**The project is still in progress and developed constantly. Contributions are highly appreciated.** - -###### Last edited: 2025-01-23 - diff --git a/source/search.cpp b/source/search.cpp index 171de64..3c4c210 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -184,7 +184,6 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { } } } - } int score = -inf; @@ -235,7 +234,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { killerMoves[1][ply] = killerMoves[0][ply]; killerMoves[0][ply] = board.moveList[i]; - WriteEntry(board.hashKey, depth, beta, CutNode, Move()); + WriteEntry(board.hashKey, depth, score, CutNode, Move()); return score; } diff --git a/source/tt.cpp b/source/tt.cpp index b19461f..e7c1047 100644 --- a/source/tt.cpp +++ b/source/tt.cpp @@ -87,9 +87,9 @@ SearchResults ReadEntry(U64 &hashKey, int depth, int alpha, int beta) { if (current->nodeType == PV){ return {current->score, current->bestMove}; } else if (current->nodeType == AllNode && current->score <= alpha) { - return alpha; + return current->score; } else if (current->nodeType == CutNode && current->score >= beta) { - return beta; + return current->score; } } } From 02b28b25981b4ff9a2cbbcdd8f1ba2804084a336 Mon Sep 17 00:00:00 2001 From: rektdie Date: Sun, 9 Mar 2025 04:04:50 +0100 Subject: [PATCH 3/7] PVS fail-soft not working, but QS now does --- source/search.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index 3c4c210..af127f0 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -102,8 +102,10 @@ static SearchResults Quiescence(Board board, int alpha, int beta) { return staticScore; } - if (staticScore > alpha) { - alpha = staticScore; + int bestScore = alpha; + + if (staticScore > bestScore) { + bestScore = staticScore; } GenerateMoves(board, board.sideToMove); @@ -129,7 +131,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta) { } } - results.score = alpha; + results.score = bestScore; if (searchStopped) return 0; return results; } @@ -202,6 +204,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { } } + int bestScore = alpha; SearchResults results; // For all moves @@ -238,15 +241,14 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { return score; } - if (score > alpha) { + if (score > bestScore) { nodeType = PV; - alpha = score; + bestScore = score; results.bestMove = board.moveList[i]; } } - - results.score = alpha; + results.score = bestScore; WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove); if (searchStopped) return 0; return results; From 28bec280cc9a35adaf2946caa61dcb456e904543 Mon Sep 17 00:00:00 2001 From: rektdie Date: Sun, 9 Mar 2025 04:39:11 +0100 Subject: [PATCH 4/7] fixed both PVS and QS --- source/search.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index af127f0..cca5501 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -97,13 +97,12 @@ static SearchResults Quiescence(Board board, int alpha, int beta) { nodes++; int staticScore = Evaluate(board); + int bestScore = alpha; if (staticScore >= beta) { return staticScore; } - int bestScore = alpha; - if (staticScore > bestScore) { bestScore = staticScore; } @@ -118,7 +117,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta) { if (board.moveList[i].IsCapture()) { Board copy = board; copy.MakeMove(board.moveList[i]); - int score = -Quiescence(copy, -beta, -alpha).score; + int score = -Quiescence(copy, -beta, -bestScore).score; if (score >= beta) { return score; @@ -155,10 +154,10 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { } } - const int staticEval = Evaluate(board); - if (depth <= 0) return Quiescence(board, alpha, beta); + const int staticEval = Evaluate(board); + if (board.InCheck(board.sideToMove)) { depth++; } else { @@ -204,8 +203,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { } } - int bestScore = alpha; - SearchResults results; + SearchResults results(-inf); // For all moves for (int i = 0; i < board.currentMoveIndex; i++) { @@ -241,14 +239,15 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { return score; } - if (score > bestScore) { + results.score = std::max(score, results.score); + + if (score > alpha) { nodeType = PV; - bestScore = score; + alpha = score; results.bestMove = board.moveList[i]; } } - results.score = bestScore; WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove); if (searchStopped) return 0; return results; @@ -331,4 +330,4 @@ void SearchPosition(Board &board, SearchParams params) { void StopSearch() { searchStopped = true; -} +} \ No newline at end of file From 15676a09e058390fd9af0bdd3ab186f9ad3883ea Mon Sep 17 00:00:00 2001 From: rektdie Date: Sun, 9 Mar 2025 04:42:54 +0100 Subject: [PATCH 5/7] counting nodes on MakeMove | bench 4096824 --- source/board.cpp | 1 + source/search.cpp | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/source/board.cpp b/source/board.cpp index f09aa42..b531a49 100644 --- a/source/board.cpp +++ b/source/board.cpp @@ -334,6 +334,7 @@ void Board::Promote(int square, int pieceType, int color, bool isCapture) { } void Board::MakeMove(Move move) { + nodes++; // Null Move if (!move) { diff --git a/source/search.cpp b/source/search.cpp index cca5501..45d99cc 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -94,8 +94,6 @@ static SearchResults Quiescence(Board board, int alpha, int beta) { } } - nodes++; - int staticScore = Evaluate(board); int bestScore = alpha; @@ -190,8 +188,6 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { int score = -inf; int nodeType = AllNode; - nodes++; - GenerateMoves(board, board.sideToMove); SortMoves(board); From ec9c2e7348c7e8bad890297f671126a23467be12 Mon Sep 17 00:00:00 2001 From: rektdie Date: Sun, 9 Mar 2025 05:03:31 +0100 Subject: [PATCH 6/7] init bestScore to staticScore in QS | bench 3786359 --- source/search.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index 45d99cc..1545578 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -95,15 +95,12 @@ static SearchResults Quiescence(Board board, int alpha, int beta) { } int staticScore = Evaluate(board); - int bestScore = alpha; if (staticScore >= beta) { return staticScore; } - if (staticScore > bestScore) { - bestScore = staticScore; - } + int bestScore = staticScore; GenerateMoves(board, board.sideToMove); @@ -115,7 +112,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta) { if (board.moveList[i].IsCapture()) { Board copy = board; copy.MakeMove(board.moveList[i]); - int score = -Quiescence(copy, -beta, -bestScore).score; + int score = -Quiescence(copy, -beta, -alpha).score; if (score >= beta) { return score; From f29a0761a90bff9b42207b356961bd4b099c15ff Mon Sep 17 00:00:00 2001 From: rektdie Date: Sun, 9 Mar 2025 05:26:02 +0100 Subject: [PATCH 7/7] missed bestScore in QS move loop | bench 4110983 --- source/search.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index 1545578..ceda5a0 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -96,11 +96,15 @@ static SearchResults Quiescence(Board board, int alpha, int beta) { int staticScore = Evaluate(board); - if (staticScore >= beta) { - return staticScore; + int bestScore = staticScore; + + if (bestScore>= beta) { + return bestScore; } - int bestScore = staticScore; + if (alpha < bestScore) { + alpha = bestScore; + } GenerateMoves(board, board.sideToMove); @@ -118,6 +122,8 @@ static SearchResults Quiescence(Board board, int alpha, int beta) { return score; } + bestScore = std::max(score, bestScore); + if (score > alpha) { alpha = score; results.bestMove = board.moveList[i];