From 26b9a5b58a4d5a569306ef569397bc682a20f0fb Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Wed, 27 Mar 2024 12:53:42 +0100 Subject: [PATCH] brchess func calls changes, always run perft() & perft2() --- test/movedo-test.c | 17 +++++++++++------ test/perft-test.c | 41 ++++++++++++++++++++++++++++------------- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/test/movedo-test.c b/test/movedo-test.c index c470af4..ac24e44 100644 --- a/test/movedo-test.c +++ b/test/movedo-test.c @@ -43,28 +43,33 @@ int main(int __unused ac, __unused char**av) printf("wrong fen %d: [%s]\n", i, fen); continue; } + + pos->checkers = pos_checkers(pos, pos->turn); + pos_set_pinners_blockers(pos); + pos_gen_pseudomoves(pos, &pseudo); savepos = pos_dup(pos); + + state_t state = pos->state; int tmp = 0, j = 0; while ((move = pos_next_legal(pos, &pseudo, &tmp)) != MOVE_NONE) { - state_t state; - move_str(movebuf, move, 0); //pos_print(pos); //printf("i=%d j=%d turn=%d move=[%s]\n", i, j, pos->turn, // move_str(movebuf, move, 0)); //move_p - move_do(pos, move, &state); + move_do(pos, move); //pos_print(pos); //fflush(stdout); - if (pos_check(pos, false)) { + if (!pos_ok(pos, false)) { printf("*** fen %d move %d [%s] invalid position after move_do\n", test_line, j, movebuf); exit(0); } //printf("%d/%d move_do check ok\n", i, j); - move_undo(pos, move, &state); - if (pos_check(pos, false)) { + move_undo(pos, move); + pos->state = state; + if (!pos_ok(pos, false)) { printf("*** fen %d move %d [%s] invalid position after move_undo\n", test_line, j, movebuf); exit(0); diff --git a/test/perft-test.c b/test/perft-test.c index 3647f8b..e93847f 100644 --- a/test/perft-test.c +++ b/test/perft-test.c @@ -259,26 +259,41 @@ int main(int __unused ac, __unused char**av) #define NANOSEC 1000000000 /* nano sec in sec */ #define MILLISEC 1000000 /* milli sec in sec */ - struct timespec ts1, ts2; - clock_gettime(CLOCK_MONOTONIC_RAW, &ts1); - - my_count = perft(pos, depth, 1); - - clock_gettime(CLOCK_MONOTONIC_RAW, &ts2); - // 1 sec = 1000 millisec // 1 millisec = 1000 microsec // 1 microsec = 1000 nanosec // milli = sec * 1000 + nanosec / 1000000 - s64 microsecs = ((s64)ts2.tv_sec - (s64)ts1.tv_sec) * 1000000l + struct timespec ts1, ts2; + s64 microsecs; + + clock_gettime(CLOCK_MONOTONIC_RAW, &ts1); + my_count = perft(pos, depth, 1); + clock_gettime(CLOCK_MONOTONIC_RAW, &ts2); + + microsecs = ((s64)ts2.tv_sec - (s64)ts1.tv_sec) * 1000000l + ((s64)ts2.tv_nsec - (s64)ts1.tv_nsec) / 1000l ; if (sf_count == my_count) { - printf("OK : fen line=%03d \"%s\" perft=%lu in %'ldms (LPS: %'lu)\n", - test_line, fen, my_count, microsecs/1000l, - my_count*1000000l/microsecs); + printf("pt1 OK : line=%03d perft=%lu ms=%'ldms lps=%'lu \"%s\"\n", + test_line, my_count, microsecs/1000l, + my_count*1000000l/microsecs, fen); } else { - printf("ERR: fen line=%03d [%s] sf=%lu me=%lu\n", - test_line, fen, sf_count, my_count); + printf("pt1 ERR: line=%03d sf=%lu me=%lu \"%s\"\n", + test_line, sf_count, my_count, fen); + } + + clock_gettime(CLOCK_MONOTONIC_RAW, &ts1); + my_count = perft2(pos, depth, 1); + clock_gettime(CLOCK_MONOTONIC_RAW, &ts2); + + microsecs = ((s64)ts2.tv_sec - (s64)ts1.tv_sec) * 1000000l + + ((s64)ts2.tv_nsec - (s64)ts1.tv_nsec) / 1000l ; + if (sf_count == my_count) { + printf("pt2 OK : line=%03d perft=%lu ms=%'ldms lps=%'lu \"%s\"\n\n", + test_line, my_count, microsecs/1000l, + my_count*1000000l/microsecs, fen); + } else { + printf("pt2 ERR: line=%03d sf=%lu me=%lu \"%s\"\n\n", + test_line, sf_count, my_count, fen); } pos_del(savepos); pos_del(pos);