Compare commits
2 Commits
00fc61020c
...
660d181e41
Author | SHA1 | Date | |
---|---|---|---|
660d181e41 | |||
5a2cdfca56 |
4
Makefile
4
Makefile
@@ -11,9 +11,9 @@
|
||||
#
|
||||
|
||||
SHELL := /bin/bash
|
||||
CC := gcc
|
||||
#CC := gcc
|
||||
CC := gcc-13
|
||||
#CC := clang
|
||||
LD := ld
|
||||
BEAR := bear
|
||||
TOUCH := touch
|
||||
RM := rm
|
||||
|
@@ -18,9 +18,10 @@
|
||||
|
||||
#define ONE 1ull
|
||||
#define U64(const_u64) const_u64##ULL
|
||||
#define BIT(i) ( (u64) (ONE << (i)) )
|
||||
#define BIT(i) ( (u64) (ONE << (i)) )
|
||||
|
||||
#define BOARDSIZE (8*8)
|
||||
#define GAMESIZE 1024 /* max game size (512 moves) */
|
||||
|
||||
/**
|
||||
* sq_rel - get relative square
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/* 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.
|
||||
* Some rights reserved. See COPYING.
|
||||
*
|
||||
|
@@ -123,7 +123,8 @@ pos_t *pos_clear(pos_t *pos)
|
||||
pos->pinners = 0;
|
||||
pos->blockers = 0;
|
||||
|
||||
//pos->moves.nmoves = 0;
|
||||
pos->repeat.moves = 0;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
@@ -131,9 +132,11 @@ pos_t *pos_clear(pos_t *pos)
|
||||
* pos_cmp() - compare two positions..
|
||||
* @pos1, @pos2: The two &position.
|
||||
*
|
||||
* Used only for move_{do,undo} test/debug.
|
||||
*
|
||||
* @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)
|
||||
bool ret = false;
|
||||
@@ -142,8 +145,11 @@ bool pos_cmp(__unused const pos_t *pos1, __unused const pos_t *pos2)
|
||||
goto end;
|
||||
|
||||
/* move_do/undo position state */
|
||||
if (_cmpf(en_passant) || _cmpf(castle) ||
|
||||
_cmpf(clock_50) || _cmpf(plycount))
|
||||
if (_cmpf(key) || _cmpf(en_passant) || _cmpf(castle) ||
|
||||
_cmpf(clock_50) || _cmpf(plycount) || _cmpf(captured))
|
||||
goto end;
|
||||
|
||||
if (_cmpf(checkers) || _cmpf(pinners) || _cmpf(blockers))
|
||||
goto end;
|
||||
|
||||
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;
|
||||
|
||||
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]))
|
||||
goto end;
|
||||
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))
|
||||
goto end;
|
||||
|
||||
if (_cmpf(repeat.moves) ||
|
||||
memcmp(pos1->repeat.key, pos2->repeat.key,
|
||||
pos1->repeat.moves * sizeof pos1->repeat.key))
|
||||
goto end;
|
||||
|
||||
ret = true;
|
||||
end:
|
||||
return ret;
|
||||
|
@@ -43,6 +43,6 @@
|
||||
|
||||
/* restore BUG_ON
|
||||
*/
|
||||
# pragma pop_macro("BUG_ON")
|
||||
#pragma pop_macro("BUG_ON")
|
||||
|
||||
#endif /* UTIL_H */
|
||||
|
@@ -44,6 +44,9 @@ static FILE *open_stockfish()
|
||||
int rpipe[2], wpipe[2];
|
||||
FILE *out_desc;
|
||||
pid_t pid;
|
||||
char *buf = NULL;
|
||||
size_t alloc = 0;
|
||||
ssize_t buflen;
|
||||
|
||||
if ((pipe(rpipe) < 0) || (pipe(wpipe) < 0)) {
|
||||
perror("pipe");
|
||||
@@ -84,11 +87,36 @@ static FILE *open_stockfish()
|
||||
out_desc = fdopen(wpipe[WR], "w");
|
||||
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;
|
||||
}
|
||||
|
||||
static u64 send_stockfish_fen(FILE *desc, pos_t *pos, movelist_t *movelist,
|
||||
char *fen, int depth)
|
||||
static void stockfish_fen(FILE *desc, char *fen)
|
||||
{
|
||||
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;
|
||||
u64 count, mycount = 0, fishcount;
|
||||
@@ -102,10 +130,11 @@ static u64 send_stockfish_fen(FILE *desc, pos_t *pos, movelist_t *movelist,
|
||||
*nmoves = 0;
|
||||
//char nodescount[] = "Nodes searched";
|
||||
//printf("nmoves = %d\n", nmoves);
|
||||
fflush(stdout);
|
||||
//fflush(stdout);
|
||||
//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);
|
||||
fprintf(desc, "go perft %d\n", depth);
|
||||
|
||||
while ((buflen = getline(&buf, &alloc, stdin)) > 0) {
|
||||
buf[--buflen] = 0;
|
||||
@@ -293,8 +322,9 @@ int main(int ac, char**av)
|
||||
}
|
||||
pos = fenpos;
|
||||
if (sf_run) {
|
||||
stockfish_fen(outfd, fen);
|
||||
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);
|
||||
if (!ms) {
|
||||
res[2].skipped++;
|
||||
|
Reference in New Issue
Block a user