From 26337b6f13e0e1c65d00894f3276130456aa8a08 Mon Sep 17 00:00:00 2001 From: ProgramciDusunur Date: Tue, 18 Feb 2025 00:26:58 +0300 Subject: [PATCH 1/9] try to fix a couple problems --- src/search.h | 2 -- src/structs.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/search.h b/src/search.h index 3c8ed690..53f725eb 100644 --- a/src/search.h +++ b/src/search.h @@ -17,8 +17,6 @@ #include #include "utils.h" -#define maxPly 64 - extern int lmr_full_depth_moves; extern int lmr_reduction_limit; extern int lateMovePruningBaseReduction; diff --git a/src/structs.h b/src/structs.h index 16073235..f3b2d6be 100644 --- a/src/structs.h +++ b/src/structs.h @@ -12,7 +12,7 @@ #define U64 unsigned long long #endif -#define maxPly 64 +#define maxPly 256 typedef struct { U64 bitboards[12]; From 580124897d95b5416979d3f6f946aedb523a7d45 Mon Sep 17 00:00:00 2001 From: ProgramciDusunur Date: Tue, 18 Feb 2025 00:39:49 +0300 Subject: [PATCH 2/9] do proper struct init --- src/search.c | 2 +- src/uci.c | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/search.c b/src/search.c index a264d8a6..6b4e52f1 100644 --- a/src/search.c +++ b/src/search.c @@ -1026,7 +1026,7 @@ int negamax(int alpha, int beta, int depth, board* pos, time* time, bool cutNode //captureMoves++; } - const int new_depth = depth - 1 + extensions; + int new_depth = depth - 1 + extensions; // full-depth search diff --git a/src/uci.c b/src/uci.c index a4c90517..cb651f47 100644 --- a/src/uci.c +++ b/src/uci.c @@ -375,12 +375,16 @@ void communicate(time* time) { void uciProtocol(int argc, char *argv[]) { - board position; + board *position = (board *)malloc(sizeof(board)); - time time; + position->ply = 0; + + clearStaticEvaluationHistory(position); + + time *time_ctrl = (time *)malloc(sizeof(time)); // init time control - initTimeControl(&time); + initTimeControl(time_ctrl); // max hash MB int max_hash = 32768; @@ -400,7 +404,7 @@ void uciProtocol(int argc, char *argv[]) { if (argc >= 2 && strncmp(argv[1], "bench", 5) == 0) { printf("bench running..\n"); - benchmark(14, &position, &time); + benchmark(14, position, time_ctrl); return; } @@ -434,7 +438,7 @@ void uciProtocol(int argc, char *argv[]) { else if (strncmp(input, "position", 8) == 0) { // call parse position function - parse_position(input, &position); + parse_position(input, position); // clear hash table clearHashTable(); @@ -443,7 +447,7 @@ void uciProtocol(int argc, char *argv[]) { clearQuietHistory(); //clear static eval history - clearStaticEvaluationHistory(&position); + clearStaticEvaluationHistory(position); //clear counter moves clearCounterMoves(); @@ -452,7 +456,7 @@ void uciProtocol(int argc, char *argv[]) { else if (strncmp(input, "ucinewgame", 10) == 0) { // call parse position function - parse_position("position startpos", &position); + parse_position("position startpos", position); // clear hash table clearHashTable(); @@ -461,7 +465,7 @@ void uciProtocol(int argc, char *argv[]) { clearQuietHistory(); //clear static eval history - clearStaticEvaluationHistory(&position); + clearStaticEvaluationHistory(position); //clear counter moves clearCounterMoves(); @@ -469,7 +473,7 @@ void uciProtocol(int argc, char *argv[]) { // parse UCI "go" command else if (strncmp(input, "go", 2) == 0) { // call parse go function - goCommand(input, &position, &time); + goCommand(input, position, time_ctrl); // clear hash table clearHashTable(); @@ -478,7 +482,7 @@ void uciProtocol(int argc, char *argv[]) { clearQuietHistory(); //clear static eval history - clearStaticEvaluationHistory(&position); + clearStaticEvaluationHistory(position); //clear counter moves clearCounterMoves(); @@ -515,7 +519,7 @@ void uciProtocol(int argc, char *argv[]) { printf("uciok\n"); } else if (strncmp(input, "bench", 5) == 0) { - benchmark(14, &position, &time); + benchmark(14, position, time_ctrl); } } } From bac1de36b56db2243c79808f47f51c2e919aafa6 Mon Sep 17 00:00:00 2001 From: ProgramciDusunur Date: Tue, 18 Feb 2025 00:43:16 +0300 Subject: [PATCH 3/9] init whole mailbox --- src/uci.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/uci.c b/src/uci.c index cb651f47..a070f1ac 100644 --- a/src/uci.c +++ b/src/uci.c @@ -379,6 +379,10 @@ void uciProtocol(int argc, char *argv[]) { position->ply = 0; + for (int i = 0; i < 64;i++) { + position->mailbox[i] = NO_PIECE; + } + clearStaticEvaluationHistory(position); time *time_ctrl = (time *)malloc(sizeof(time)); From 91f3792b81d7fd7af09b8ce85a46a68d8a0c770b Mon Sep 17 00:00:00 2001 From: ProgramciDusunur Date: Tue, 18 Feb 2025 00:59:04 +0300 Subject: [PATCH 4/9] fix a few remaining bugs --- src/move.c | 5 +++++ src/search.c | 1 + 2 files changed, 6 insertions(+) diff --git a/src/move.c b/src/move.c index 952be758..b019dd63 100644 --- a/src/move.c +++ b/src/move.c @@ -702,6 +702,11 @@ void noisyGenerator(moves *moveList, board* position) { } } } + // if noisy generates can't create any move, then we can't let zero to zero length array init + if (moveList->count == 0) { + moveList->count = 10; + + } } diff --git a/src/search.c b/src/search.c index 6b4e52f1..18d10364 100644 --- a/src/search.c +++ b/src/search.c @@ -1200,6 +1200,7 @@ void searchPosition(int depth, board* position, bool benchmark, time* time) { position->scorePv = 0; memset(position->killerMoves, 0, sizeof(position->killerMoves)); + memset(position->mailbox, NO_PIECE, sizeof(position->mailbox)); memset(quietHistory, 0, sizeof(quietHistory)); memset(rootHistory, 0, sizeof(rootHistory)); memset(pawnCorrectionHistory, 0, sizeof(pawnCorrectionHistory)); From 2f0beda5043c2744139b718f8d048ade817b5ade Mon Sep 17 00:00:00 2001 From: ProgramciDusunur Date: Tue, 18 Feb 2025 01:01:00 +0300 Subject: [PATCH 5/9] fix wrong comment --- src/move.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/move.c b/src/move.c index b019dd63..be1aa65b 100644 --- a/src/move.c +++ b/src/move.c @@ -702,10 +702,9 @@ void noisyGenerator(moves *moveList, board* position) { } } } - // if noisy generates can't create any move, then we can't let zero to zero length array init + // if noisy generates can't create any move, then we can't allow the array to start with zero if (moveList->count == 0) { moveList->count = 10; - } } From 4592298f5376b129a396ed588f477b162aaa3e78 Mon Sep 17 00:00:00 2001 From: ProgramciDusunur Date: Tue, 18 Feb 2025 01:11:34 +0300 Subject: [PATCH 6/9] fix wrong approach --- src/move.c | 4 ---- src/search.c | 5 ++++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/move.c b/src/move.c index be1aa65b..952be758 100644 --- a/src/move.c +++ b/src/move.c @@ -702,10 +702,6 @@ void noisyGenerator(moves *moveList, board* position) { } } } - // if noisy generates can't create any move, then we can't allow the array to start with zero - if (moveList->count == 0) { - moveList->count = 10; - } } diff --git a/src/search.c b/src/search.c index 18d10364..7b2d5b90 100644 --- a/src/search.c +++ b/src/search.c @@ -600,7 +600,10 @@ int quiescence(int alpha, int beta, board* position, time* time) { noisyGenerator(moveList, position); // sort moves - quiescence_sort_moves(moveList, position); + if (moveList->count > 0) { + quiescence_sort_moves(moveList, position); + } + // legal moves counter //int legal_moves = 0; From 1cd7b9f5f534724ba913701572a67b4b5359b2a4 Mon Sep 17 00:00:00 2001 From: ProgramciDusunur Date: Tue, 18 Feb 2025 01:28:56 +0300 Subject: [PATCH 7/9] bench: 9977346 --- src/search.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/search.c b/src/search.c index 7b2d5b90..acdbba24 100644 --- a/src/search.c +++ b/src/search.c @@ -1031,7 +1031,6 @@ int negamax(int alpha, int beta, int depth, board* pos, time* time, bool cutNode int new_depth = depth - 1 + extensions; - // full-depth search if (moves_searched == 0) { // do normal alpha beta search From f1d741be9d06a0d31262b284deac012a9515873b Mon Sep 17 00:00:00 2001 From: ProgramciDusunur Date: Tue, 18 Feb 2025 01:36:49 +0300 Subject: [PATCH 8/9] bench: 9977346 --- src/search.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/search.c b/src/search.c index acdbba24..961ea54b 100644 --- a/src/search.c +++ b/src/search.c @@ -600,9 +600,8 @@ int quiescence(int alpha, int beta, board* position, time* time) { noisyGenerator(moveList, position); // sort moves - if (moveList->count > 0) { - quiescence_sort_moves(moveList, position); - } + quiescence_sort_moves(moveList, position); + // legal moves counter From e1326a38c7d84a7263f50e93b04d9088b640d9b4 Mon Sep 17 00:00:00 2001 From: ProgramciDusunur Date: Tue, 18 Feb 2025 01:44:06 +0300 Subject: [PATCH 9/9] bench: 8323324 --- src/search.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/search.c b/src/search.c index 961ea54b..42636a03 100644 --- a/src/search.c +++ b/src/search.c @@ -600,7 +600,10 @@ int quiescence(int alpha, int beta, board* position, time* time) { noisyGenerator(moveList, position); // sort moves - quiescence_sort_moves(moveList, position); + if (moveList->count > 0) { + quiescence_sort_moves(moveList, position); + } + @@ -1201,7 +1204,7 @@ void searchPosition(int depth, board* position, bool benchmark, time* time) { position->scorePv = 0; memset(position->killerMoves, 0, sizeof(position->killerMoves)); - memset(position->mailbox, NO_PIECE, sizeof(position->mailbox)); + //memset(position->mailbox, NO_PIECE, sizeof(position->mailbox)); memset(quietHistory, 0, sizeof(quietHistory)); memset(rootHistory, 0, sizeof(rootHistory)); memset(pawnCorrectionHistory, 0, sizeof(pawnCorrectionHistory));