Compare commits
2 Commits
92d6909546
...
96744cea20
Author | SHA1 | Date | |
---|---|---|---|
96744cea20 | |||
24207583d1 |
@@ -100,8 +100,6 @@ u64 perft2(pos_t *pos, int depth, int ply)
|
|||||||
move_t move;
|
move_t move;
|
||||||
state_t state;
|
state_t state;
|
||||||
|
|
||||||
if (is_in_check(pos, OPPONENT(pos->turn)))
|
|
||||||
return 0;
|
|
||||||
if (depth == 0)
|
if (depth == 0)
|
||||||
return 1;
|
return 1;
|
||||||
pos->checkers = pos_checkers(pos, pos->turn);
|
pos->checkers = pos_checkers(pos, pos->turn);
|
||||||
@@ -113,14 +111,14 @@ u64 perft2(pos_t *pos, int depth, int ply)
|
|||||||
for (nmove = 0; nmove < pseudo.nmoves; ++nmove ) {
|
for (nmove = 0; nmove < pseudo.nmoves; ++nmove ) {
|
||||||
move = pseudo.move[nmove];
|
move = pseudo.move[nmove];
|
||||||
move_do(pos, move);
|
move_do(pos, move);
|
||||||
|
if (!is_in_check(pos, OPPONENT(pos->turn))) {
|
||||||
subnodes = perft2(pos, depth - 1, ply + 1);
|
subnodes = perft2(pos, depth - 1, ply + 1);
|
||||||
|
|
||||||
nodes += subnodes;
|
nodes += subnodes;
|
||||||
if (ply == 1) {
|
if (ply == 1) {
|
||||||
char movestr[8];
|
char movestr[8];
|
||||||
printf("%s: %d\n", move_str(movestr, move, 0), subnodes);
|
printf("%s: %d\n", move_str(movestr, move, 0), subnodes);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
move_undo(pos, move);
|
move_undo(pos, move);
|
||||||
pos->state = state;
|
pos->state = state;
|
||||||
}
|
}
|
||||||
|
@@ -233,11 +233,17 @@ int main(int __unused ac, __unused char**av)
|
|||||||
//move_t move;
|
//move_t move;
|
||||||
FILE *outfd;
|
FILE *outfd;
|
||||||
int depth = 6;
|
int depth = 6;
|
||||||
|
s64 ms1 = 0, ms1_total = 0, ms2 = 0, ms2_total = 0;
|
||||||
|
int run = 3;
|
||||||
|
|
||||||
if (ac > 1)
|
if (ac > 1)
|
||||||
depth = atoi(av[1]);
|
depth = atoi(av[1]);
|
||||||
printf("depth = %d\n", depth);
|
if (ac > 2)
|
||||||
|
run = atoi(av[2]);
|
||||||
|
printf("depth = %d run=%d\n", depth, run);
|
||||||
|
|
||||||
|
if (!run)
|
||||||
|
exit(0);
|
||||||
setlocale(LC_NUMERIC, "");
|
setlocale(LC_NUMERIC, "");
|
||||||
setlinebuf(stdout); /* line-buffered stdout */
|
setlinebuf(stdout); /* line-buffered stdout */
|
||||||
outfd = open_stockfish();
|
outfd = open_stockfish();
|
||||||
@@ -245,6 +251,8 @@ int main(int __unused ac, __unused char**av)
|
|||||||
bitboard_init();
|
bitboard_init();
|
||||||
hyperbola_init();
|
hyperbola_init();
|
||||||
|
|
||||||
|
|
||||||
|
CLOCK_DEFINE(clock, CLOCK_PROCESS);
|
||||||
while ((fen = next_fen(PERFT | MOVEDO))) {
|
while ((fen = next_fen(PERFT | MOVEDO))) {
|
||||||
test_line = cur_line();
|
test_line = cur_line();
|
||||||
if (!(pos = fen2pos(NULL, fen))) {
|
if (!(pos = fen2pos(NULL, fen))) {
|
||||||
@@ -256,35 +264,46 @@ int main(int __unused ac, __unused char**av)
|
|||||||
savepos = pos_dup(pos);
|
savepos = pos_dup(pos);
|
||||||
//int j = 0;
|
//int j = 0;
|
||||||
|
|
||||||
s64 μs;
|
if (run & 1) {
|
||||||
CLOCK_DEFINE(clock, CLOCK_SYSTEM);
|
|
||||||
|
|
||||||
clock_start(&clock);
|
clock_start(&clock);
|
||||||
my_count = perft(pos, depth, 1);
|
my_count = perft(pos, depth, 1);
|
||||||
μs = clock_elapsed_μs(&clock);
|
ms1 = clock_elapsed_ms(&clock);
|
||||||
|
ms1_total += ms1;
|
||||||
|
|
||||||
if (sf_count == my_count) {
|
if (sf_count == my_count) {
|
||||||
printf("pt1 OK : line=%03d perft=%lu μs=%'ldms lps=%'lu \"%s\"\n",
|
printf("pt1 OK : line=%03d perft=%lu %'ldms lps=%'lu \"%s\"\n",
|
||||||
test_line, my_count, μs, my_count*1000000l/μs, fen);
|
test_line, my_count, ms1,
|
||||||
|
ms1? my_count*1000l/ms1: 0,
|
||||||
|
fen);
|
||||||
} else {
|
} else {
|
||||||
printf("pt1 ERR: line=%03d sf=%lu me=%lu \"%s\"\n",
|
printf("pt1 ERR: line=%03d sf=%lu me=%lu \"%s\"\n",
|
||||||
test_line, sf_count, my_count, fen);
|
test_line, sf_count, my_count, fen);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (run & 2) {
|
||||||
clock_start(&clock);
|
clock_start(&clock);
|
||||||
my_count = perft2(pos, depth, 1);
|
my_count = perft2(pos, depth, 1);
|
||||||
μs = clock_elapsed_μs(&clock);
|
ms2 = clock_elapsed_ms(&clock);
|
||||||
|
ms2_total += ms2;
|
||||||
|
|
||||||
if (sf_count == my_count) {
|
if (sf_count == my_count) {
|
||||||
printf("pt2 OK : line=%03d perft=%lu μs=%'ldms lps=%'lu \"%s\"\n\n",
|
printf("pt2 OK : line=%03d perft=%lu %'ldms lps=%'lu \"%s\"\n\n",
|
||||||
test_line, my_count, μs, my_count*1000000l/μs, fen);
|
test_line, my_count, ms2,
|
||||||
|
ms2? my_count*1000l/ms2: 0,
|
||||||
|
fen);
|
||||||
} else {
|
} else {
|
||||||
printf("pt2 ERR: line=%03d sf=%lu me=%lu \"%s\"\n\n",
|
printf("pt2 ERR: line=%03d sf=%lu me=%lu \"%s\"\n\n",
|
||||||
test_line, sf_count, my_count, fen);
|
test_line, sf_count, my_count, fen);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
pos_del(savepos);
|
pos_del(savepos);
|
||||||
pos_del(pos);
|
pos_del(pos);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
if (run & 1)
|
||||||
|
printf("total perft %'ldms\n", ms1_total);
|
||||||
|
if (run & 2)
|
||||||
|
printf("total perft2 %'ldms\n", ms2_total);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user