brchess func calls changes, always run perft() & perft2()

This commit is contained in:
2024-03-27 12:53:42 +01:00
parent 65fe74c9c5
commit 26b9a5b58a
2 changed files with 39 additions and 19 deletions

View File

@@ -43,28 +43,33 @@ int main(int __unused ac, __unused char**av)
printf("wrong fen %d: [%s]\n", i, fen); printf("wrong fen %d: [%s]\n", i, fen);
continue; continue;
} }
pos->checkers = pos_checkers(pos, pos->turn);
pos_set_pinners_blockers(pos);
pos_gen_pseudomoves(pos, &pseudo); pos_gen_pseudomoves(pos, &pseudo);
savepos = pos_dup(pos); savepos = pos_dup(pos);
state_t state = pos->state;
int tmp = 0, j = 0; int tmp = 0, j = 0;
while ((move = pos_next_legal(pos, &pseudo, &tmp)) != MOVE_NONE) { while ((move = pos_next_legal(pos, &pseudo, &tmp)) != MOVE_NONE) {
state_t state;
move_str(movebuf, move, 0);
//pos_print(pos); //pos_print(pos);
//printf("i=%d j=%d turn=%d move=[%s]\n", i, j, pos->turn, //printf("i=%d j=%d turn=%d move=[%s]\n", i, j, pos->turn,
// move_str(movebuf, move, 0)); // move_str(movebuf, move, 0));
//move_p //move_p
move_do(pos, move, &state); move_do(pos, move);
//pos_print(pos); //pos_print(pos);
//fflush(stdout); //fflush(stdout);
if (pos_check(pos, false)) { if (!pos_ok(pos, false)) {
printf("*** fen %d move %d [%s] invalid position after move_do\n", printf("*** fen %d move %d [%s] invalid position after move_do\n",
test_line, j, movebuf); test_line, j, movebuf);
exit(0); exit(0);
} }
//printf("%d/%d move_do check ok\n", i, j); //printf("%d/%d move_do check ok\n", i, j);
move_undo(pos, move, &state); move_undo(pos, move);
if (pos_check(pos, false)) { pos->state = state;
if (!pos_ok(pos, false)) {
printf("*** fen %d move %d [%s] invalid position after move_undo\n", printf("*** fen %d move %d [%s] invalid position after move_undo\n",
test_line, j, movebuf); test_line, j, movebuf);
exit(0); exit(0);

View File

@@ -259,26 +259,41 @@ int main(int __unused ac, __unused char**av)
#define NANOSEC 1000000000 /* nano sec in sec */ #define NANOSEC 1000000000 /* nano sec in sec */
#define MILLISEC 1000000 /* milli 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 sec = 1000 millisec
// 1 millisec = 1000 microsec // 1 millisec = 1000 microsec
// 1 microsec = 1000 nanosec // 1 microsec = 1000 nanosec
// milli = sec * 1000 + nanosec / 1000000 // 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 ; + ((s64)ts2.tv_nsec - (s64)ts1.tv_nsec) / 1000l ;
if (sf_count == my_count) { if (sf_count == my_count) {
printf("OK : fen line=%03d \"%s\" perft=%lu in %'ldms (LPS: %'lu)\n", printf("pt1 OK : line=%03d perft=%lu ms=%'ldms lps=%'lu \"%s\"\n",
test_line, fen, my_count, microsecs/1000l, test_line, my_count, microsecs/1000l,
my_count*1000000l/microsecs); my_count*1000000l/microsecs, fen);
} else { } else {
printf("ERR: fen line=%03d [%s] sf=%lu me=%lu\n", printf("pt1 ERR: line=%03d sf=%lu me=%lu \"%s\"\n",
test_line, fen, sf_count, my_count); 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(savepos);
pos_del(pos); pos_del(pos);