add info in pos_print, start perft TT testing
This commit is contained in:
@@ -28,14 +28,30 @@ struct fentest {
|
||||
char *comment;
|
||||
char *fen;
|
||||
} fentest[] = {
|
||||
/*
|
||||
{ __LINE__, 1,
|
||||
"",
|
||||
""
|
||||
},
|
||||
*/
|
||||
/******************* TEMP TESTS BELOW *******************/
|
||||
|
||||
/* ***************** TEMP TESTS ABOVE ************************** */
|
||||
/*
|
||||
* { __LINE__, MOVEGEN | MOVEDO | PERFT,
|
||||
* "bug perft TT après 1.b4 f5",
|
||||
* "1nbqkbn1/ppp1p1pp/8/r1rpPpK1/1P6/8/P1PP1PPP/RNBQ1BNR w - f6 0 2"
|
||||
* },
|
||||
*/
|
||||
|
||||
/*
|
||||
* { __LINE__, MOVEGEN | MOVEDO | PERFT,
|
||||
* "bug perft TT après 1.b4",
|
||||
* "1nbqkbn1/ppp1pppp/8/r1rpP1K1/1P6/8/P1PP1PPP/RNBQ1BNR b - - 0 1",
|
||||
* },
|
||||
*/
|
||||
|
||||
{ __LINE__, MOVEGEN | MOVEDO | PERFT,
|
||||
"bug perft TT",
|
||||
"1nbqkbn1/ppp1pppp/8/r1rpP1K1/8/8/PPPP1PPP/RNBQ1BNR w - d6 0 1",
|
||||
},
|
||||
|
||||
/* ***************** END of TEMP TESTS ******************/
|
||||
/* below line ignored if first test */
|
||||
{ __LINE__, 0, NULL, NULL },
|
||||
|
||||
{ __LINE__, MOVEGEN | MOVEDO | PERFT,
|
||||
"illegal white e.p.",
|
||||
@@ -138,7 +154,7 @@ struct fentest {
|
||||
"checker: h4",
|
||||
"4k3/8/8/8/7b/8/8/4K3 w - - 0 1"
|
||||
},
|
||||
// First game moves
|
||||
// First game moves
|
||||
{ __LINE__, FEN | MOVEGEN | MOVEDO | PERFT,
|
||||
"startpos",
|
||||
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
|
||||
@@ -425,6 +441,10 @@ static int fentest_cur = -1;
|
||||
static char *next_fen(uint module)
|
||||
{
|
||||
fentest_cur++;
|
||||
|
||||
/* skip first entry if NULL - for special testing, see */
|
||||
if (fentest_cur == 0 && fentest[fentest_cur].fen == NULL)
|
||||
fentest_cur++;
|
||||
while (fentest[fentest_cur].fen && !(fentest[fentest_cur].modules & module))
|
||||
fentest_cur++;
|
||||
return fentest[fentest_cur].fen;
|
||||
|
@@ -255,8 +255,8 @@ static __unused void compare_moves(movelist_t *fish, movelist_t *me)
|
||||
|
||||
static int usage(char *prg)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-d depth] [-p pertf-modules] [-n][-v]\n", prg);
|
||||
fprintf(stderr, "\t-d: depth, -p: 1-3, -n: no SF res check, -v: output moves\n");
|
||||
fprintf(stderr, "Usage: %s [-cmv][-d depth] [-p perft-version] \n", prg);
|
||||
fprintf(stderr, "\t-c/m: print comments/moves, -n: no SF check, -d: depth, -p: 1-3, \n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -264,6 +264,7 @@ int main(int ac, char**av)
|
||||
{
|
||||
int test_line;
|
||||
u64 sf_count = 0, my_count;
|
||||
bool comment = false;
|
||||
char *fen;
|
||||
pos_t *pos = NULL, *fenpos;
|
||||
pos_t *fishpos = pos_new();
|
||||
@@ -283,8 +284,11 @@ int main(int ac, char**av)
|
||||
int opt, depth = 6, run = 3;
|
||||
bool sf_run = true, perft_output = false;
|
||||
|
||||
while ((opt = getopt(ac, av, "vnd:p:")) != -1) {
|
||||
while ((opt = getopt(ac, av, "cmnd:p:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'c':
|
||||
comment = true;
|
||||
break;
|
||||
case 'd':
|
||||
depth = atoi(optarg);
|
||||
break;
|
||||
@@ -294,7 +298,7 @@ int main(int ac, char**av)
|
||||
case 'n':
|
||||
sf_run = false;
|
||||
break;
|
||||
case 'v':
|
||||
case 'm':
|
||||
perft_output = true;
|
||||
break;
|
||||
default:
|
||||
@@ -315,7 +319,10 @@ int main(int ac, char**av)
|
||||
|
||||
CLOCK_DEFINE(clock, CLOCK_MONOTONIC);
|
||||
while ((fen = next_fen(PERFT | MOVEDO))) {
|
||||
if (comment)
|
||||
printf("%s\n", *cur_comment()? cur_comment(): "<FIXME>");
|
||||
test_line = cur_line();
|
||||
tt_clear();
|
||||
if (!(fenpos = fen2pos(pos, fen))) {
|
||||
printf("wrong fen line = %d: [%s]\n", test_line, fen);
|
||||
continue;
|
||||
@@ -370,6 +377,7 @@ int main(int ac, char**av)
|
||||
printf("pt1 ERR: line=%3d sf=%'lu me=%'lu \"%s\"\n",
|
||||
test_line, sf_count, my_count, fen);
|
||||
}
|
||||
tt_stats();
|
||||
}
|
||||
|
||||
if (run & 2) {
|
||||
|
159
test/tt-test.c
Normal file
159
test/tt-test.c
Normal file
@@ -0,0 +1,159 @@
|
||||
/* tt-test.c - transposition table test.
|
||||
*
|
||||
* Copyright (C) 2024 Bruno Raoult ("br")
|
||||
* Licensed under the GNU General Public License v3.0 or later.
|
||||
* Some rights reserved. See COPYING.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this
|
||||
* program. If not, see <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <locale.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <brlib.h>
|
||||
|
||||
#include "chessdefs.h"
|
||||
#include "fen.h"
|
||||
#include "position.h"
|
||||
#include "move.h"
|
||||
#include "move-do.h"
|
||||
#include "move-gen.h"
|
||||
#include "search.h"
|
||||
|
||||
// #include "common-test.h"
|
||||
|
||||
static move_t move_in_movelist(movelist_t *ml, square_t from, square_t to, piece_type_t pt)
|
||||
{
|
||||
const int nmoves = ml->nmoves;
|
||||
const move_t *moves = ml->move;
|
||||
int movenum = 0;
|
||||
move_t move;
|
||||
for (movenum = 0; movenum < nmoves; ++movenum) {
|
||||
move = moves[movenum];
|
||||
printf("compare %s%s to %s%s pt=%d ",
|
||||
sq_to_string(from), sq_to_string(to),
|
||||
sq_to_string(move_from(move)),
|
||||
sq_to_string(move_to(move)),
|
||||
pt
|
||||
);
|
||||
if (move_from(move) == from && move_to(move) == to) {
|
||||
printf("HIT!\n");
|
||||
if (pt != NO_PIECE_TYPE && move_promoted(move) != pt)
|
||||
continue;
|
||||
printf("move_in_movelist(%s%s) found from=%s to=%s\n",
|
||||
sq_to_string(from), sq_to_string(to),
|
||||
sq_to_string(move_from(move)),
|
||||
sq_to_string(move_to(move)));
|
||||
return move;
|
||||
} else
|
||||
puts("");
|
||||
}
|
||||
return MOVE_NONE;
|
||||
}
|
||||
|
||||
static move_t move_from_str(pos_t *pos, const char *move)
|
||||
{
|
||||
movelist_t movelist;
|
||||
square_t from = sq_from_string(move);
|
||||
square_t to = sq_from_string(move + 2);
|
||||
piece_type_t promoted = piece_t_from_char(*(move + 4));
|
||||
printf("from=%o to=%o promoted=%d\n", from, to, promoted);
|
||||
|
||||
pos_set_checkers_pinners_blockers(pos);
|
||||
pos_legal(pos, pos_gen_pseudo(pos, &movelist));
|
||||
return move_in_movelist(&movelist, from, to, promoted);
|
||||
}
|
||||
|
||||
static void pr_entry(hentry_t *entry)
|
||||
{
|
||||
if (!entry)
|
||||
printf("entry: NULL\n");
|
||||
else {
|
||||
printf("entry: key=%lx depth=%d n=%lu\n",
|
||||
entry->key, HASH_PERFT_DEPTH(entry->data),
|
||||
HASH_PERFT_VAL(entry->data));
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pos_t *pos = NULL;
|
||||
char *token, *str, buf[128];
|
||||
hentry_t *entry;
|
||||
move_t move;
|
||||
state_t state;
|
||||
//movelist_t movelist;
|
||||
|
||||
const char *moves_array[] = {
|
||||
"e2e4 e7e5 g1f3 b8c6",
|
||||
"e2e4 b8c6 g1f3 e7e5"
|
||||
};
|
||||
|
||||
init_all();
|
||||
|
||||
for (uint i = 0; i < ARRAY_SIZE(moves_array); ++i) {
|
||||
int depth = 0;
|
||||
str = strdup(moves_array[i]);
|
||||
printf("%2d: ", i + 1);
|
||||
|
||||
pos = startpos(pos);
|
||||
entry = tt_store_perft(pos->key, 0, 123 + depth);
|
||||
pr_entry(entry);
|
||||
token = strtok(str, " \t");
|
||||
while (token) {
|
||||
depth++;
|
||||
printf("%s ", token);
|
||||
|
||||
//pos_set_checkers_pinners_blockers(pos);
|
||||
//pos_legal(pos, pos_gen_pseudo(pos, &movelist));
|
||||
move = move_from_str(pos, token);
|
||||
printf("move: %s\n", move_to_str(buf, move, 0));
|
||||
move_do(pos, move, &state);
|
||||
if ((entry = tt_probe_perft(pos->key, depth))) {
|
||||
printf("tt hit: depth=%d val=%lu",
|
||||
HASH_PERFT_DEPTH(entry->data),
|
||||
HASH_PERFT_VAL(entry->data));
|
||||
} else {
|
||||
tt_store_perft(pos->key, i + 1, depth);
|
||||
printf("tt store: depth=%d val=%lu", depth, (u64)i * 123);
|
||||
};
|
||||
|
||||
token = strtok(NULL, " \t");
|
||||
}
|
||||
printf("\n");
|
||||
free(str);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ccls bug report: https://github.com/emacs-lsp/emacs-ccls/issues/126
|
||||
*/
|
||||
/*
|
||||
* int called(int), caller();
|
||||
*
|
||||
* /\**
|
||||
* * called() - test ccls.
|
||||
* * @x: int, the test value
|
||||
* *
|
||||
* * @called() description.
|
||||
* *
|
||||
* * @return: int, a very interesting value.
|
||||
* *\/
|
||||
* int called(int x) { return x; }
|
||||
*
|
||||
* int caller()
|
||||
* {
|
||||
* int i = 0;
|
||||
* called(int x)
|
||||
* return i;
|
||||
* }
|
||||
*/
|
Reference in New Issue
Block a user