3 Commits

5 changed files with 95 additions and 27 deletions

View File

@@ -129,6 +129,38 @@ DEPFLAGS = -MMD -MP -MF $(DEPDIR)/$*.d
ALL_CFLAGS = $(DEPFLAGS) $(CPPFLAGS) $(CFLAGS)
ALL_LDFLAGS = $(LDFLAGS) $(LIBS)
##################################### Multi-targets
# We can have an issue with Make's "-j" option, in some situations,
# for example "make -j2 clean testing".
# See https://stackoverflow.com/a/8496333/3079831
# Check if job server supported:
ifeq ($(filter jobserver, $(.FEATURES)),)
# Job server not supported: sub-makes will only start one job unless
# you specify a higher number here. Here we use a MS Windows environment
# variable specifying number of processors.
JOBSARG := -j $(NUMBER_OF_PROCESSORS)
else
# Job server is supported; let GNU Make work as normal.
JOBSARG :=
endif
# .FEATURES only works in GNU Make 3.81+.
# If GNU make is older, assume job server support.
ifneq ($(firstword $(sort 3.81 $(MAKE_VERSION))),3.81)
# If you are using GNU Make < 3.81 that does not support job servers, you
# might want to specify -jN parameter here instead.
JOBSARG :=
endif
ifneq ($(words $(MAKECMDGOALS)),1)
.NOTPARALLEL:
# The "all" target is required in the list,
# in case user invokes make with no targets.
$(sort all $(MAKECMDGOALS)):
@$(MAKE) $(JOBSARG) -f $(firstword $(MAKEFILE_LIST)) $@
else
##################################### General targets
.PHONY: all compile clean cleanall
@@ -379,3 +411,6 @@ wtf:
zob:
$(CC) $(LDFLAGS) $(CPPFLAGS) $(CFLAGS) $< $(LIBS) src/util.c -o util
##################################### End of multi-targets
endif

View File

@@ -316,11 +316,11 @@ bitboard_t pos_king_blockers(const pos_t *pos, const color_t color, const bitboa
* - total number of pieces > 16 or zero (per color)
* - number of kings != 1 (per color)
* - discrepancy between board and king (per color)
* - discrepancy between piece bitboards and ALL_PIECES bitboards (per color)
* - discrepancy between bitboards and board (per color)
* - side-to-move already checking opponent king
* - side-to-move in check more than twice
* - kings distance is 1
* - TODO: discrepancy between piece bitboards and ALL_PIECES bitboards (per color)
*
* In case of errors, and @strict is true, @bug_on() is called, and program will
* be terminated.
@@ -328,15 +328,20 @@ bitboard_t pos_king_blockers(const pos_t *pos, const color_t color, const bitboa
* (eg after fen parsing), and with @strict == true otherwise (as we have some data
* corruption).
*
* TODO: add more checks:
* - kings attacking each other
*
* @return: (if @strict is false) return true if check is ok, false otherwise.
*/
bool pos_ok(const pos_t *pos, const bool strict)
{
int n, count = 0, bbcount = 0, error = 0;
/* force BUG_ON and WARN_ON */
# pragma push_macro("BUG_ON")
# pragma push_macro("WARN_ON")
# undef BUG_ON
# define BUG_ON
# undef WARN_ON
# define WARN_ON
/* pawns on 1st ot 8th rank */
error += warn_on((pos->bb[WHITE][PAWN] | pos->bb[BLACK][PAWN]) &
(RANK_1bb | RANK_8bb));
@@ -357,7 +362,7 @@ bool pos_ok(const pos_t *pos, const bool strict)
}
for (square_t sq = 0; sq < 64; ++sq) {
piece_t piece = pos->board[sq];
__unused bitboard_t match;
bitboard_t match;
if (piece == EMPTY)
continue;
color_t c = COLOR(piece);
@@ -366,18 +371,22 @@ bool pos_ok(const pos_t *pos, const bool strict)
error += warn_on(!match);
count++;
}
/* occupied occupation is different from bitboards */
/* occupied board is different from bitboards */
error += warn_on(count != bbcount);
/* is opponent already in check ? */
error += warn_on(pos_checkers(pos, OPPONENT(pos->turn)));
/* is color to play in check more than twice ? */
error += warn_on(popcount64(pos_checkers(pos, OPPONENT(pos->turn))) > 2);
error += warn_on(popcount64(pos_checkers(pos, pos->turn)) > 2);
/* kings distance is less than 2 */
error += warn_on(sq_dist(pos->king[WHITE], pos->king[BLACK]) < 2);
if (strict)
if (strict) {
bug_on(error);
/* not reached */
}
return error? false: true;
# pragma pop_macro("WARN_ON")
# pragma pop_macro("BUG_ON")
}
/**

View File

@@ -32,7 +32,7 @@ typedef struct __pos_s {
/* data which cannot be recovered by move_undo (like castle_rights, ...),
* or would be expensive to recover (checkers, ...)
* following data can be accessed either directly, either via "movesave"
* following data can be accessed either directly, either via "state"
* structure name.
* For example, pos->en_passant and pos->state.en_passant are the same.
* This allows a memcpy on this data (to save/restore position state).
@@ -40,8 +40,8 @@ typedef struct __pos_s {
struct_group_tagged(state_s, state,
square_t en_passant;
castle_rights_t castle;
u16 clock_50;
u16 plycount; /* plies so far, start from 1 */
int clock_50;
int plycount; /* plies so far, start from 1 */
piece_t captured; /* only for move_undo */
bitboard_t checkers; /* opponent checkers */
bitboard_t pinners; /* opponent pinners */

View File

@@ -29,12 +29,11 @@ struct fentest {
char *fen;
} fentest[] = {
/*
{ __LINE__.
ATTACK,
"checkers: ",
{ __LINE__, 1,
"",
""
},
*/
*/
/* ***************** TEMP TESTS ABOVE ************************** */

View File

@@ -222,32 +222,55 @@ static __unused void compare_moves(movelist_t *fish, movelist_t *me)
printf("F(%2d): %s\nM(%2d): %s\n", n1, str1, n2, str2);
}
static int usage(char *prg)
{
fprintf(stderr, "Usage: %s [-d depth] [-p pertf-modules] -n\n", prg);
return 1;
}
int main(int __unused ac, __unused char**av)
{
int i = 0, test_line;
u64 sf_count, my_count;
u64 sf_count = 0, my_count;
char *fen;
pos_t *pos, *savepos, *fishpos = pos_new();
movelist_t fishmoves;
//move_t move;
FILE *outfd;
FILE *outfd = NULL;
s64 ms1 = 0, ms1_total = 0;
s64 ms2 = 0, ms2_total = 0;
int depth = 6, run = 3;
int opt, depth = 6, run = 3;
bool sf_run = true;
if (ac > 1)
depth = atoi(av[1]);
if (ac > 2)
run = atoi(av[2]) & 3;
printf("depth = %d run=%d\n", depth, run);
while ((opt = getopt(ac, av, "nd:p:")) != -1) {
switch (opt) {
case 'd':
depth = atoi(optarg);
break;
case 'p': /* 1 or 2 */
run = atoi(optarg);
break;
case 'n':
sf_run = false;
break;
default:
return usage(*av);
}
}
//if (ac > 1)
// depth = atoi(av[1]);
//if (ac > 2)
// run = atoi(av[2]) & 3;
printf("depth = %d run = %x sf = %s\n", depth, run, sf_run? "true": "false");
if (!run)
exit(0);
setlocale(LC_NUMERIC, "");
setlinebuf(stdout); /* line-buffered stdout */
outfd = open_stockfish();
if (sf_run)
outfd = open_stockfish();
bitboard_init();
hyperbola_init();
@@ -259,7 +282,9 @@ int main(int __unused ac, __unused char**av)
printf("wrong fen %d: [%s]\n", i, fen);
continue;
}
sf_count = send_stockfish_fen(outfd, fishpos, &fishmoves, fen, depth);
if (sf_run)
sf_count = send_stockfish_fen(outfd, fishpos, &fishmoves, fen, depth);
savepos = pos_dup(pos);
if (run & 1) {
@@ -268,7 +293,7 @@ int main(int __unused ac, __unused char**av)
ms1 = clock_elapsed_ms(&clock);
ms1_total += ms1;
if (sf_count == my_count) {
if (!sf_run || sf_count == my_count) {
printf("pt1 OK : line=%3d perft=%'lu %'ldms lps=%'lu \"%s\"\n",
test_line, my_count, ms1,
ms1? my_count*1000l/ms1: 0,
@@ -285,7 +310,7 @@ int main(int __unused ac, __unused char**av)
ms2 = clock_elapsed_ms(&clock);
ms2_total += ms2;
if (sf_count == my_count) {
if (!sf_run || sf_count == my_count) {
printf("pt2 OK : line=%3d perft=%'lu %'ldms lps=%'lu \"%s\"\n",
test_line, my_count, ms2,
ms2? my_count*1000l/ms2: 0,