2 Commits

6 changed files with 57 additions and 15 deletions

View File

@@ -11,9 +11,9 @@
# #
SHELL := /bin/bash SHELL := /bin/bash
CC := gcc #CC := gcc
CC := gcc-13
#CC := clang #CC := clang
LD := ld
BEAR := bear BEAR := bear
TOUCH := touch TOUCH := touch
RM := rm RM := rm

View File

@@ -21,6 +21,7 @@
#define BIT(i) ( (u64) (ONE << (i)) ) #define BIT(i) ( (u64) (ONE << (i)) )
#define BOARDSIZE (8*8) #define BOARDSIZE (8*8)
#define GAMESIZE 1024 /* max game size (512 moves) */
/** /**
* sq_rel - get relative square * sq_rel - get relative square

View File

@@ -1,6 +1,6 @@
/* eval.h - static position evaluation. /* eval.h - static position evaluation.
* *
* Copyright (C) 2021 Bruno Raoult ("br") * Copyright (C) 2021-2024 Bruno Raoult ("br")
* Licensed under the GNU General Public License v3.0 or later. * Licensed under the GNU General Public License v3.0 or later.
* Some rights reserved. See COPYING. * Some rights reserved. See COPYING.
* *

View File

@@ -123,7 +123,8 @@ pos_t *pos_clear(pos_t *pos)
pos->pinners = 0; pos->pinners = 0;
pos->blockers = 0; pos->blockers = 0;
//pos->moves.nmoves = 0; pos->repeat.moves = 0;
return pos; return pos;
} }
@@ -131,9 +132,11 @@ pos_t *pos_clear(pos_t *pos)
* pos_cmp() - compare two positions.. * pos_cmp() - compare two positions..
* @pos1, @pos2: The two &position. * @pos1, @pos2: The two &position.
* *
* Used only for move_{do,undo} test/debug.
*
* @return: true if equal, false otherwise. * @return: true if equal, false otherwise.
*/ */
bool pos_cmp(__unused const pos_t *pos1, __unused const pos_t *pos2) bool pos_cmp(const pos_t *pos1, const pos_t *pos2)
{ {
#define _cmpf(a) (pos1->a != pos2->a) #define _cmpf(a) (pos1->a != pos2->a)
bool ret = false; bool ret = false;
@@ -142,8 +145,11 @@ bool pos_cmp(__unused const pos_t *pos1, __unused const pos_t *pos2)
goto end; goto end;
/* move_do/undo position state */ /* move_do/undo position state */
if (_cmpf(en_passant) || _cmpf(castle) || if (_cmpf(key) || _cmpf(en_passant) || _cmpf(castle) ||
_cmpf(clock_50) || _cmpf(plycount)) _cmpf(clock_50) || _cmpf(plycount) || _cmpf(captured))
goto end;
if (_cmpf(checkers) || _cmpf(pinners) || _cmpf(blockers))
goto end; goto end;
for (square_t sq = A1; sq <= H8; ++sq) for (square_t sq = A1; sq <= H8; ++sq)
@@ -151,7 +157,7 @@ bool pos_cmp(__unused const pos_t *pos1, __unused const pos_t *pos2)
goto end; goto end;
for (color_t color = WHITE; color <= BLACK; ++color) { for (color_t color = WHITE; color <= BLACK; ++color) {
for (piece_type_t piece = 0; piece <= KING; ++piece) for (piece_type_t piece = ALL_PIECES; piece <= KING; ++piece)
if (_cmpf(bb[color][piece])) if (_cmpf(bb[color][piece]))
goto end; goto end;
if (_cmpf(king[color])) if (_cmpf(king[color]))
@@ -161,6 +167,11 @@ bool pos_cmp(__unused const pos_t *pos1, __unused const pos_t *pos2)
if (_cmpf(checkers) ||_cmpf(pinners) || _cmpf(blockers)) if (_cmpf(checkers) ||_cmpf(pinners) || _cmpf(blockers))
goto end; goto end;
if (_cmpf(repeat.moves) ||
memcmp(pos1->repeat.key, pos2->repeat.key,
pos1->repeat.moves * sizeof pos1->repeat.key))
goto end;
ret = true; ret = true;
end: end:
return ret; return ret;

View File

@@ -44,6 +44,9 @@ static FILE *open_stockfish()
int rpipe[2], wpipe[2]; int rpipe[2], wpipe[2];
FILE *out_desc; FILE *out_desc;
pid_t pid; pid_t pid;
char *buf = NULL;
size_t alloc = 0;
ssize_t buflen;
if ((pipe(rpipe) < 0) || (pipe(wpipe) < 0)) { if ((pipe(rpipe) < 0) || (pipe(wpipe) < 0)) {
perror("pipe"); perror("pipe");
@@ -84,11 +87,36 @@ static FILE *open_stockfish()
out_desc = fdopen(wpipe[WR], "w"); out_desc = fdopen(wpipe[WR], "w");
setvbuf(out_desc, NULL, _IOLBF, 0); setvbuf(out_desc, NULL, _IOLBF, 0);
fprintf(out_desc, "uci\n");
while (true) {
if ((buflen = getline(&buf, &alloc, stdin)) < 0) {
perror("getline");
exit(1);
}
if (!strncmp(buf, "uciok", 5))
break;
}
free(buf);
return out_desc; return out_desc;
} }
static u64 send_stockfish_fen(FILE *desc, pos_t *pos, movelist_t *movelist, static void stockfish_fen(FILE *desc, char *fen)
char *fen, int depth) {
char *buf = NULL;
size_t alloc = 0;
ssize_t buflen;
fprintf(desc, "ucinewgame\nisready\n");
while ((buflen = getline(&buf, &alloc, stdin)) > 0) {
if (!strncmp(buf, "readyok", 7))
break;
}
fprintf(desc, "position fen %s\n", fen);
free(buf);
}
static u64 stockfish_perft(FILE *desc, pos_t *pos, movelist_t *movelist,
int depth)
{ {
char *buf = NULL; char *buf = NULL;
u64 count, mycount = 0, fishcount; u64 count, mycount = 0, fishcount;
@@ -102,10 +130,11 @@ static u64 send_stockfish_fen(FILE *desc, pos_t *pos, movelist_t *movelist,
*nmoves = 0; *nmoves = 0;
//char nodescount[] = "Nodes searched"; //char nodescount[] = "Nodes searched";
//printf("nmoves = %d\n", nmoves); //printf("nmoves = %d\n", nmoves);
fflush(stdout); //fflush(stdout);
//sprintf(str, "stockfish \"position fen %s\ngo perft depth\n\"", fen); //sprintf(str, "stockfish \"position fen %s\ngo perft depth\n\"", fen);
fprintf(desc, "position fen %s\ngo perft %d\n", fen, depth); //fprintf(desc, "position fen %s\ngo perft %d\n", fen, depth);
//fflush(desc); //fflush(desc);
fprintf(desc, "go perft %d\n", depth);
while ((buflen = getline(&buf, &alloc, stdin)) > 0) { while ((buflen = getline(&buf, &alloc, stdin)) > 0) {
buf[--buflen] = 0; buf[--buflen] = 0;
@@ -293,8 +322,9 @@ int main(int ac, char**av)
} }
pos = fenpos; pos = fenpos;
if (sf_run) { if (sf_run) {
stockfish_fen(outfd, fen);
clock_start(&clock); clock_start(&clock);
sf_count = send_stockfish_fen(outfd, fishpos, &fishmoves, fen, depth); sf_count = stockfish_perft(outfd, fishpos, &fishmoves, depth);
ms = clock_elapsed_ms(&clock); ms = clock_elapsed_ms(&clock);
if (!ms) { if (!ms) {
res[2].skipped++; res[2].skipped++;