Compare commits
3 Commits
ae198c891f
...
242b501404
Author | SHA1 | Date | |
---|---|---|---|
242b501404 | |||
f530a13481 | |||
243805f11f |
51
Makefile
51
Makefile
@@ -41,7 +41,7 @@ OBJ := $(addprefix $(OBJDIR)/,$(SRC_FN:.c=.o))
|
|||||||
TSTSRC := $(wildcard $(TSTDIR)/*.c)
|
TSTSRC := $(wildcard $(TSTDIR)/*.c)
|
||||||
|
|
||||||
LIB := br_$(shell uname -m) # library name
|
LIB := br_$(shell uname -m) # library name
|
||||||
LIBS := $(strip -l$(LIB) -lreadline)
|
LIBS := $(strip -l$(LIB) -lreadline -lncurses -ltinfo)
|
||||||
|
|
||||||
DEP_FN := $(SRC_FN)
|
DEP_FN := $(SRC_FN)
|
||||||
DEP := $(addprefix $(DEPDIR)/,$(DEP_FN:.c=.d))
|
DEP := $(addprefix $(DEPDIR)/,$(DEP_FN:.c=.d))
|
||||||
@@ -52,8 +52,38 @@ TARGET := $(addprefix $(BINDIR)/,$(TARGET_FN))
|
|||||||
ASMFILES := $(SRC:.c=.s) $(TSTSRC:.c=.s)
|
ASMFILES := $(SRC:.c=.s) $(TSTSRC:.c=.s)
|
||||||
CPPFILES := $(SRC:.c=.i) $(TSTSRC:.c=.i)
|
CPPFILES := $(SRC:.c=.i) $(TSTSRC:.c=.i)
|
||||||
|
|
||||||
|
##################################### set a version string
|
||||||
|
# inspired from:
|
||||||
|
# https://eugene-babichenko.github.io/blog/2019/09/28/nightly-versions-makefiles/
|
||||||
|
|
||||||
|
# default empty version
|
||||||
|
#VERSION :=
|
||||||
|
|
||||||
|
# last commit and date
|
||||||
|
COMMIT := $(shell git rev-parse --short HEAD)
|
||||||
|
DATE := $(shell git log -1 --format=%cd --date=format:"%Y%m%d")
|
||||||
|
|
||||||
|
# get last commit w/ tag & associated tag, if any
|
||||||
|
TAG_COMM := $(shell git rev-list --abbrev-commit --tags --max-count=1)
|
||||||
|
ifneq ($(TAG_COMMIT),)
|
||||||
|
TAG := $(shell git describe --abbrev=0 --tags ${TG_COMM} 2>/dev/null || true)
|
||||||
|
VERSION := $(TAG:v%=%)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# if no version, use last commit and date.
|
||||||
|
# else, if last commit != last tag commit, add commit and date to version number
|
||||||
|
ifeq ($(VERSION),)
|
||||||
|
VERSION := build-$(COMMIT)-$(DATE)
|
||||||
|
else ifneq ($(COMMIT), $(TAG_COMMIT))
|
||||||
|
VERSION := $(VERSION)-next-$(COMMIT)-$(DATE)
|
||||||
|
endif
|
||||||
|
# if uncommited changes, add "dirty" indicator
|
||||||
|
ifneq ($(shell git status --porcelain),)
|
||||||
|
VERSION := $(VERSION)-dirty
|
||||||
|
endif
|
||||||
|
|
||||||
##################################### pre-processor flags
|
##################################### pre-processor flags
|
||||||
CPPFLAGS := -I$(BRINCDIR) -I$(INCDIR)
|
CPPFLAGS := -I$(BRINCDIR) -I$(INCDIR) -DVERSION=\"$(VERSION)\"
|
||||||
|
|
||||||
CPPFLAGS += -DNDEBUG # assert (unused)
|
CPPFLAGS += -DNDEBUG # assert (unused)
|
||||||
CPPFLAGS += -DWARN_ON # brlib bug.h
|
CPPFLAGS += -DWARN_ON # brlib bug.h
|
||||||
@@ -319,7 +349,7 @@ $(CCLSROOT):
|
|||||||
# maybe run cleanobj cleanlibobj in commands ?
|
# maybe run cleanobj cleanlibobj in commands ?
|
||||||
$(CCLSFILE): cleanobj cleanbrlib libs | $(CCLSROOT)
|
$(CCLSFILE): cleanobj cleanbrlib libs | $(CCLSROOT)
|
||||||
@echo "Generating ccls compile commands file ($@)."
|
@echo "Generating ccls compile commands file ($@)."
|
||||||
@$(BEAR) -- $(MAKE) testing
|
@$(BEAR) -- $(MAKE)
|
||||||
|
|
||||||
##################################### valgrind (mem check)
|
##################################### valgrind (mem check)
|
||||||
.PHONY: memcheck
|
.PHONY: memcheck
|
||||||
@@ -404,12 +434,13 @@ bin/tt-test: test/tt-test.c test/common-test.h $(TT_OBJS)
|
|||||||
##################################### Makefile debug
|
##################################### Makefile debug
|
||||||
.PHONY: showflags wft
|
.PHONY: showflags wft
|
||||||
|
|
||||||
showflags:
|
info:
|
||||||
@echo CFLAGS: "$(CFLAGS)"
|
@printf "CFLAGS: +%s+\n" "$(CFLAGS)"
|
||||||
@echo CPPFLAGS: $(CPPFLAGS)
|
@printf "CPPFLAGS: +%s+\n" "$(CPPFLAGS)"
|
||||||
@echo DEPFLAGS: $(DEPFLAGS)
|
@printf "DEPFLAGS: +%s+\n" "$(DEPFLAGS)"
|
||||||
@echo LDFLAGS: $(LDFLAGS)
|
@printf "LDFLAGS: +%s+\n" "$(LDFLAGS)"
|
||||||
@echo DEPFLAGS: $(DEPFLAGS)
|
@printf "DEPFLAGS: +%s+\n" "$(DEPFLAGS)"
|
||||||
|
@printf "VERSION: +%s+\n" "$(VERSION)"
|
||||||
|
|
||||||
wtf:
|
wtf:
|
||||||
@printf "BRLIBDIR=%s\n" "$(BRLIBDIR)"
|
@printf "BRLIBDIR=%s\n" "$(BRLIBDIR)"
|
||||||
@@ -422,7 +453,7 @@ wtf:
|
|||||||
@#echo LIBSRC=$(LIBSRC)
|
@#echo LIBSRC=$(LIBSRC)
|
||||||
|
|
||||||
zob:
|
zob:
|
||||||
$(CC) $(LDFLAGS) $(CPPFLAGS) $(CFLAGS) $< $(LIBS) src/util.c -o util
|
@#$(CC) $(LDFLAGS) $(CPPFLAGS) $(CFLAGS) $< $(LIBS) src/util.c -o util
|
||||||
|
|
||||||
##################################### End of multi-targets
|
##################################### End of multi-targets
|
||||||
endif
|
endif
|
||||||
|
35
scripts/git-split.sh
Executable file
35
scripts/git-split.sh
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Duplicate file, with history (well, sort of)
|
||||||
|
#
|
||||||
|
# Copy a git file, keeping history.
|
||||||
|
# Sources:
|
||||||
|
# https://stackoverflow.com/a/53849613/3079831
|
||||||
|
# https://stackoverflow.com/a/75942970/3079831
|
||||||
|
|
||||||
|
CMDNAME=${0##*/} # script name
|
||||||
|
|
||||||
|
if (( $# != 2 )); then
|
||||||
|
printf "Usage: %s original copy\n" "$CMDNAME"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
from="$1"
|
||||||
|
to="$2"
|
||||||
|
branch="split-file"
|
||||||
|
|
||||||
|
printf "Dup from=[%s] to=[%s] branch=[%s]\n" "$from" "$to" "$branch"
|
||||||
|
|
||||||
|
git checkout -b "$branch" # create and switch to branch
|
||||||
|
|
||||||
|
git mv "$from" "$to" # make the duplicate
|
||||||
|
git commit -m "Duplicate $from to $to"
|
||||||
|
|
||||||
|
git checkout HEAD~ "$from" # bring back the original
|
||||||
|
git commit -m "Restore duplicated $from"
|
||||||
|
|
||||||
|
git checkout - # switch back to source branch
|
||||||
|
git merge --no-ff "$branch" -m "Merge $branch" # merge dup into source branch
|
||||||
|
|
||||||
|
|
||||||
|
exit 0
|
424
src/brchess.c
424
src/brchess.c
@@ -19,17 +19,19 @@
|
|||||||
#include <readline/history.h>
|
#include <readline/history.h>
|
||||||
|
|
||||||
#include <brlib.h>
|
#include <brlib.h>
|
||||||
#include <list.h>
|
//#include <list.h>
|
||||||
#include <debug.h>
|
//#include <debug.h>
|
||||||
|
|
||||||
#include "brchess.h"
|
|
||||||
#include "chessdefs.h"
|
#include "chessdefs.h"
|
||||||
#include "board.h"
|
#include "position.h"
|
||||||
#include "piece.h"
|
#include "brchess.h"
|
||||||
#include "move.h"
|
#include "hash.h"
|
||||||
|
//#include "board.h"
|
||||||
|
//#include "piece.h"
|
||||||
|
//#include "move.h"
|
||||||
#include "fen.h"
|
#include "fen.h"
|
||||||
#include "eval.h"
|
//#include "eval.h"
|
||||||
#include "eval-simple.h"
|
//#include "eval-simple.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
|
|
||||||
struct command {
|
struct command {
|
||||||
@@ -51,48 +53,49 @@ struct command *find_command (char *);
|
|||||||
char *stripwhite (char *string);
|
char *stripwhite (char *string);
|
||||||
|
|
||||||
/* The names of functions that actually do the manipulation. */
|
/* The names of functions that actually do the manipulation. */
|
||||||
|
int do_ucinewgame(pos_t *, char*);
|
||||||
|
int do_uci(pos_t *, char*);
|
||||||
|
int do_isready(pos_t *, char*);
|
||||||
|
|
||||||
|
int do_position(pos_t *, char*);
|
||||||
|
int do_prpos(pos_t *, char*);
|
||||||
|
int do_perft(pos_t *, char*);
|
||||||
|
|
||||||
int do_help(pos_t *, char*);
|
int do_help(pos_t *, char*);
|
||||||
int do_fen(pos_t *, char*);
|
|
||||||
int do_init(pos_t *, char*);
|
|
||||||
int do_pos(pos_t *, char*);
|
|
||||||
int do_genmoves(pos_t *, char*);
|
|
||||||
int do_prmoves(pos_t *, char*);
|
|
||||||
//int do_prmovepos(pos_t *pos, char *arg);
|
|
||||||
int do_prpieces(pos_t *pos, char *arg);
|
|
||||||
int do_memstats(pos_t *, char*);
|
|
||||||
int do_eval(pos_t *, char*);
|
|
||||||
int do_simple_eval(pos_t *, char*);
|
|
||||||
int do_move(pos_t *, char*);
|
|
||||||
int do_quit(pos_t *, char*);
|
int do_quit(pos_t *, char*);
|
||||||
int do_debug(pos_t *, char*);
|
|
||||||
int do_depth(pos_t *, char*);
|
|
||||||
int do_search(pos_t *, char*);
|
|
||||||
int do_pvs(pos_t *, char*);
|
|
||||||
|
|
||||||
struct command commands[] = {
|
struct command commands[] = {
|
||||||
|
{ "ucinewgame", do_ucinewgame, "new game" },
|
||||||
|
{ "uci", do_uci, "start uci" },
|
||||||
|
{ "isready", do_isready, "start uci" },
|
||||||
|
|
||||||
|
{ "position", do_position, "position startpos|fen [moves ...]" },
|
||||||
|
{ "prpos", do_prpos, "Print current position" },
|
||||||
|
{ "perft", do_perft, "perft depth [yes]" },
|
||||||
|
|
||||||
{ "help", do_help, "Display this text" },
|
{ "help", do_help, "Display this text" },
|
||||||
{ "?", do_help, "Synonym for 'help'" },
|
|
||||||
{ "fen", do_fen, "Set position to FEN" },
|
|
||||||
{ "init", do_init, "Set position to normal start position" },
|
|
||||||
{ "pos", do_pos, "Print current position" },
|
|
||||||
{ "quit", do_quit, "Quit" },
|
{ "quit", do_quit, "Quit" },
|
||||||
{ "genmove", do_genmoves, "Generate move list for " },
|
/*
|
||||||
{ "prmoves", do_prmoves, "Print position move list" },
|
* { "init", do_init, "Set position to normal start position" },
|
||||||
// { "prmovepos", do_prmovepos, "Print Nth move resulting position" },
|
|
||||||
{ "prpieces", do_prpieces, "Print Pieces (from pieces lists)" },
|
* { "genmove", do_genmoves, "Generate move list for " },
|
||||||
{ "memstats", do_memstats, "Generate next move list" },
|
* { "prmoves", do_prmoves, "Print position move list" },
|
||||||
{ "eval", do_eval, "Eval current position" },
|
* // { "prmovepos", do_prmovepos, "Print Nth move resulting position" },
|
||||||
{ "simple-eval", do_simple_eval, "Simple eval current position" },
|
* { "prpieces", do_prpieces, "Print Pieces (from pieces lists)" },
|
||||||
{ "do_move", do_move, "execute nth move on current position" },
|
* { "memstats", do_memstats, "Generate next move list" },
|
||||||
{ "debug", do_debug, "Set log level to LEVEL" },
|
* { "eval", do_eval, "Eval current position" },
|
||||||
{ "depth", do_depth, "Set search depth to N" },
|
* { "simple-eval", do_simple_eval, "Simple eval current position" },
|
||||||
{ "search", do_search, "Search best move (negamax)" },
|
* { "do_move", do_move, "execute nth move on current position" },
|
||||||
{ "pvs", do_pvs, "Search best move (Principal Variation Search)" },
|
* { "debug", do_debug, "Set log level to LEVEL" },
|
||||||
|
* { "depth", do_depth, "Set search depth to N" },
|
||||||
|
* { "search", do_search, "Search best move (negamax)" },
|
||||||
|
* { "pvs", do_pvs, "Search best move (Principal Variation Search)" },
|
||||||
|
*/
|
||||||
{ NULL, (int(*)()) NULL, NULL }
|
{ NULL, (int(*)()) NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static int done=0;
|
static int done=0;
|
||||||
static int depth=1;
|
//static int depth=1;
|
||||||
|
|
||||||
int brchess(pos_t *pos)
|
int brchess(pos_t *pos)
|
||||||
{
|
{
|
||||||
@@ -104,7 +107,7 @@ int brchess(pos_t *pos)
|
|||||||
rl_char_is_quoted_p = "e_detector;
|
rl_char_is_quoted_p = "e_detector;
|
||||||
|
|
||||||
while (!done) {
|
while (!done) {
|
||||||
buffer = readline("chess> ");
|
buffer = readline(NULL);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
break;
|
break;
|
||||||
/* Remove leading and trailing whitespace from the line.
|
/* Remove leading and trailing whitespace from the line.
|
||||||
@@ -123,7 +126,6 @@ int brchess(pos_t *pos)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//char **commands_completion(const char *text, int start, int end)
|
|
||||||
char **commands_completion(const char *text, __unused int start, __unused int end)
|
char **commands_completion(const char *text, __unused int start, __unused int end)
|
||||||
{
|
{
|
||||||
rl_attempted_completion_over = 1;
|
rl_attempted_completion_over = 1;
|
||||||
@@ -193,8 +195,8 @@ char *escape(const char *original)
|
|||||||
int quote_detector(char *line, int index)
|
int quote_detector(char *line, int index)
|
||||||
{
|
{
|
||||||
return index > 0
|
return index > 0
|
||||||
&& line[index - 1] == '\\'
|
&& line[index - 1] == '\\'
|
||||||
&&!quote_detector(line, index - 1);
|
&&!quote_detector(line, index - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Execute a command line. */
|
/* Execute a command line. */
|
||||||
@@ -204,6 +206,7 @@ int execute_line(pos_t *pos, char *line)
|
|||||||
struct command *command;
|
struct command *command;
|
||||||
char *word;
|
char *word;
|
||||||
|
|
||||||
|
/* strip multiple blank characters */
|
||||||
/* Isolate the command word. */
|
/* Isolate the command word. */
|
||||||
i = 0;
|
i = 0;
|
||||||
while (line[i] && whitespace(line[i]))
|
while (line[i] && whitespace(line[i]))
|
||||||
@@ -219,7 +222,7 @@ int execute_line(pos_t *pos, char *line)
|
|||||||
command = find_command(word);
|
command = find_command(word);
|
||||||
|
|
||||||
if (!command) {
|
if (!command) {
|
||||||
fprintf(stderr, "%s: Unknown command.\n", word);
|
fprintf(stderr, "%s: Unknown command. Try 'help'.\n", word);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +253,7 @@ struct command *find_command(char *name)
|
|||||||
into STRING. */
|
into STRING. */
|
||||||
char *stripwhite(char *string)
|
char *stripwhite(char *string)
|
||||||
{
|
{
|
||||||
register char *s, *t;
|
char *s, *t;
|
||||||
|
|
||||||
for (s = string; whitespace(*s); s++)
|
for (s = string; whitespace(*s); s++)
|
||||||
;
|
;
|
||||||
@@ -266,61 +269,55 @@ char *stripwhite(char *string)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
int do_eval(__unused pos_t *pos, __unused char *arg)
|
/*
|
||||||
{
|
* int do_eval(__unused pos_t *pos, __unused char *arg)
|
||||||
eval_t material[2], control[2], mobility[2];
|
* {
|
||||||
for (int color = WHITE; color <= BLACK; ++color) {
|
* eval_t material[2], control[2], mobility[2];
|
||||||
material[color] = eval_material(pos, color);
|
* for (int color = WHITE; color <= BLACK; ++color) {
|
||||||
control[color] = eval_square_control(pos, color);
|
* material[color] = eval_material(pos, color);
|
||||||
mobility[color] = eval_mobility(pos, color);
|
* control[color] = eval_square_control(pos, color);
|
||||||
printf("%s: material=%d mobility=%d controlled=%d\n",
|
* mobility[color] = eval_mobility(pos, color);
|
||||||
color? "Black": "White", material[color],
|
* printf("%s: material=%d mobility=%d controlled=%d\n",
|
||||||
mobility[color], control[color]);
|
* color? "Black": "White", material[color],
|
||||||
}
|
* mobility[color], control[color]);
|
||||||
eval_t res = eval(pos);
|
* }
|
||||||
printf("eval = %d centipawns\n", res);
|
* eval_t res = eval(pos);
|
||||||
return 1;
|
* printf("eval = %d centipawns\n", res);
|
||||||
}
|
* return 1;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* int do_simple_eval(__unused pos_t *pos, __unused char *arg)
|
||||||
|
* {
|
||||||
|
* eval_t eval = eval_simple(pos);
|
||||||
|
* printf("eval = %d centipawns\n", eval);
|
||||||
|
* return 1;
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
int do_simple_eval(__unused pos_t *pos, __unused char *arg)
|
/*
|
||||||
{
|
* int do_init(pos_t *pos, __unused char *arg)
|
||||||
eval_t eval = eval_simple(pos);
|
* {
|
||||||
printf("eval = %d centipawns\n", eval);
|
* startpos(pos);
|
||||||
return 1;
|
* return 1;
|
||||||
}
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
int do_fen(pos_t *pos, char *arg)
|
/*
|
||||||
{
|
* int do_genmoves(pos_t *pos, __unused char *arg)
|
||||||
fen2pos(pos, arg);
|
* {
|
||||||
return 1;
|
* moves_gen_all(pos);
|
||||||
}
|
* return 1;
|
||||||
|
* }
|
||||||
int do_init(pos_t *pos, __unused char *arg)
|
*
|
||||||
{
|
* int do_prmoves(pos_t *pos, __unused char *arg)
|
||||||
pos_startpos(pos);
|
* {
|
||||||
return 1;
|
* uint debug_level = debug_level_get();
|
||||||
}
|
* debug_level_set(1);
|
||||||
|
* moves_print(pos, M_PR_SEPARATE | M_PR_NUM | M_PR_LONG);
|
||||||
int do_pos(pos_t *pos, __unused char *arg)
|
* debug_level_set(debug_level);
|
||||||
{
|
* return 1;
|
||||||
pos_print(pos);
|
* }
|
||||||
return 1;
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
int do_genmoves(pos_t *pos, __unused char *arg)
|
|
||||||
{
|
|
||||||
moves_gen_all(pos);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int do_prmoves(pos_t *pos, __unused char *arg)
|
|
||||||
{
|
|
||||||
uint debug_level = debug_level_get();
|
|
||||||
debug_level_set(1);
|
|
||||||
moves_print(pos, M_PR_SEPARATE | M_PR_NUM | M_PR_LONG);
|
|
||||||
debug_level_set(debug_level);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* int do_prmovepos(pos_t *pos, char *arg)
|
* int do_prmovepos(pos_t *pos, char *arg)
|
||||||
@@ -342,58 +339,98 @@ int do_prmoves(pos_t *pos, __unused char *arg)
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int do_prpieces(pos_t *pos, __unused char *arg)
|
/*
|
||||||
|
* int do_prpieces(pos_t *pos, __unused char *arg)
|
||||||
|
* {
|
||||||
|
* log_f(1, "%s\n", arg);
|
||||||
|
* pos_pieces_print(pos);
|
||||||
|
* return 1;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* int do_memstats(__unused pos_t *pos,__unused char *arg)
|
||||||
|
* {
|
||||||
|
* moves_pool_stats();
|
||||||
|
* piece_pool_stats();
|
||||||
|
* pos_pool_stats();
|
||||||
|
* return 1;
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* int do_move(__unused pos_t *pos, __unused char *arg)
|
||||||
|
* {
|
||||||
|
* int i = 1, nmove = atoi(arg);
|
||||||
|
* move_t *move;
|
||||||
|
* pos_t *newpos;
|
||||||
|
*
|
||||||
|
* if (list_empty(&pos->moves[pos->turn])) {
|
||||||
|
* log_f(1, "No moves list.\n");
|
||||||
|
* return 0;
|
||||||
|
* }
|
||||||
|
* list_for_each_entry(move, &pos->moves[pos->turn], list) {
|
||||||
|
* if (i == nmove)
|
||||||
|
* goto doit;
|
||||||
|
* i++;
|
||||||
|
* }
|
||||||
|
* log_f(1, "Invalid <%d> move, should be <1-%d>.\n", nmove, i);
|
||||||
|
* return 0;
|
||||||
|
* doit:
|
||||||
|
* newpos = move_do(pos, move);
|
||||||
|
* pos_print(newpos);
|
||||||
|
*
|
||||||
|
* return 1;
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
|
int do_ucinewgame(__unused pos_t *pos, __unused char *arg)
|
||||||
{
|
{
|
||||||
log_f(1, "%s\n", arg);
|
tt_clear();
|
||||||
pos_pieces_print(pos);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int do_memstats(__unused pos_t *pos,__unused char *arg)
|
int do_uci(__unused pos_t *pos, __unused char *arg)
|
||||||
{
|
{
|
||||||
moves_pool_stats();
|
printf("id name brchess " VERSION "\n");
|
||||||
piece_pool_stats();
|
printf("id author Bruno Raoult\n");
|
||||||
pos_pool_stats();
|
printf("option option name Hash type spin default %d min %d max %d\n",
|
||||||
|
hash_tt.mb, HASH_SIZE_MIN, HASH_SIZE_MAX);
|
||||||
|
printf("uciok\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int do_move(__unused pos_t *pos, __unused char *arg)
|
int do_isready(__unused pos_t *pos, __unused char *arg)
|
||||||
{
|
{
|
||||||
int i = 1, nmove = atoi(arg);
|
printf("readyok\n");
|
||||||
move_t *move;
|
|
||||||
pos_t *newpos;
|
|
||||||
|
|
||||||
if (list_empty(&pos->moves[pos->turn])) {
|
|
||||||
log_f(1, "No moves list.\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
list_for_each_entry(move, &pos->moves[pos->turn], list) {
|
|
||||||
if (i == nmove)
|
|
||||||
goto doit;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
log_f(1, "Invalid <%d> move, should be <1-%d>.\n", nmove, i);
|
|
||||||
return 0;
|
|
||||||
doit:
|
|
||||||
newpos = move_do(pos, move);
|
|
||||||
pos_print(newpos);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int do_quit(__unused pos_t *pos, __unused char *arg)
|
int do_position(pos_t *pos, char *arg)
|
||||||
{
|
{
|
||||||
return done = 1;
|
printf("position:[%s]\n", arg);
|
||||||
}
|
fen2pos(pos, arg);
|
||||||
|
|
||||||
int do_debug(__unused pos_t *pos, __unused char *arg)
|
|
||||||
{
|
|
||||||
debug_level_set(atoi(arg));
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print out help for ARG, or for all of the commands if ARG is
|
int do_prpos(pos_t *pos, __unused char *arg)
|
||||||
not present. */
|
{
|
||||||
|
pos_print(pos);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int do_perft(pos_t *pos, __unused char *arg)
|
||||||
|
{
|
||||||
|
pos_print(pos);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* int do_debug(__unused pos_t *pos, __unused char *arg)
|
||||||
|
* {
|
||||||
|
* debug_level_set(atoi(arg));
|
||||||
|
* return 1;
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
int do_help(__unused pos_t *pos, __unused char *arg)
|
int do_help(__unused pos_t *pos, __unused char *arg)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -426,57 +463,68 @@ int do_help(__unused pos_t *pos, __unused char *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int do_depth(__unused pos_t *pos, char *arg)
|
int do_quit(__unused pos_t *pos, __unused char *arg)
|
||||||
{
|
{
|
||||||
depth = atoi(arg);
|
return done = 1;
|
||||||
printf("depth = %d\n", depth);
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int do_search(pos_t *pos, __unused char *arg)
|
/* Print out help for ARG, or for all of the commands if ARG is
|
||||||
{
|
not present. */
|
||||||
int debug_level = debug_level_get();
|
/*
|
||||||
float timer1, timer2, nodes_sec;
|
* int do_depth(__unused pos_t *pos, char *arg)
|
||||||
|
* {
|
||||||
|
* depth = atoi(arg);
|
||||||
|
* printf("depth = %d\n", depth);
|
||||||
|
* return 1;
|
||||||
|
*
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* int do_search(pos_t *pos, __unused char *arg)
|
||||||
|
* {
|
||||||
|
* int debug_level = debug_level_get();
|
||||||
|
* float timer1, timer2, nodes_sec;
|
||||||
|
*
|
||||||
|
* timer1 = debug_timer_elapsed();
|
||||||
|
* negamax(pos, depth, pos->turn == WHITE ? 1 : -1);
|
||||||
|
* timer2 = debug_timer_elapsed();
|
||||||
|
* nodes_sec = (float) pos->node_count / ((float) (timer2 - timer1) / (float)NANOSEC);
|
||||||
|
* log(1, "best=");
|
||||||
|
* debug_level_set(1);
|
||||||
|
* move_print(0, pos->bestmove, 0);
|
||||||
|
* debug_level_set(debug_level);
|
||||||
|
* log(1, " negamax=%d\n", pos->bestmove->negamax);
|
||||||
|
* printf("Depth:%d Nodes:%luK time:%.02fs (%.0f kn/s)\n", depth,
|
||||||
|
* pos->node_count / 1000, (timer2 - timer1)/NANOSEC, nodes_sec/1000);
|
||||||
|
* return 1;
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
timer1 = debug_timer_elapsed();
|
/*
|
||||||
negamax(pos, depth, pos->turn == WHITE ? 1 : -1);
|
* int do_pvs(pos_t *pos, __unused char *arg)
|
||||||
timer2 = debug_timer_elapsed();
|
* {
|
||||||
nodes_sec = (float) pos->node_count / ((float) (timer2 - timer1) / (float)NANOSEC);
|
* int debug_level = debug_level_get();
|
||||||
log(1, "best=");
|
* float timer1, timer2, nodes_sec;
|
||||||
debug_level_set(1);
|
* eval_t _pvs;
|
||||||
move_print(0, pos->bestmove, 0);
|
*
|
||||||
debug_level_set(debug_level);
|
* timer1 = debug_timer_elapsed();
|
||||||
log(1, " negamax=%d\n", pos->bestmove->negamax);
|
* moves_gen_eval_sort(pos);
|
||||||
printf("Depth:%d Nodes:%luK time:%.02fs (%.0f kn/s)\n", depth,
|
* _pvs = pvs(pos, depth, EVAL_MIN, EVAL_MAX, pos->turn == WHITE ? 1 : -1);
|
||||||
pos->node_count / 1000, (timer2 - timer1)/NANOSEC, nodes_sec/1000);
|
* timer2 = debug_timer_elapsed();
|
||||||
return 1;
|
* nodes_sec = (float) pos->node_count / ((float) (timer2 - timer1) / (float)NANOSEC);
|
||||||
}
|
* log(1, "best=");
|
||||||
|
* if (pos->bestmove) {
|
||||||
int do_pvs(pos_t *pos, __unused char *arg)
|
* debug_level_set(1);
|
||||||
{
|
* move_print(0, pos->bestmove, 0);
|
||||||
int debug_level = debug_level_get();
|
* debug_level_set(debug_level);
|
||||||
float timer1, timer2, nodes_sec;
|
* log(1, " pvs=%d stored=%d\n", _pvs, pos->bestmove->negamax);
|
||||||
eval_t _pvs;
|
* } else {
|
||||||
|
* log(1, "<no-best-move>");
|
||||||
timer1 = debug_timer_elapsed();
|
* }
|
||||||
moves_gen_eval_sort(pos);
|
* printf("Depth:%d Nodes:%luK time:%.02fs (%.0f kn/s)\n", depth,
|
||||||
_pvs = pvs(pos, depth, EVAL_MIN, EVAL_MAX, pos->turn == WHITE ? 1 : -1);
|
* pos->node_count / 1000, (timer2 - timer1)/NANOSEC, nodes_sec/1000);
|
||||||
timer2 = debug_timer_elapsed();
|
* return 1;
|
||||||
nodes_sec = (float) pos->node_count / ((float) (timer2 - timer1) / (float)NANOSEC);
|
* }
|
||||||
log(1, "best=");
|
*/
|
||||||
if (pos->bestmove) {
|
|
||||||
debug_level_set(1);
|
|
||||||
move_print(0, pos->bestmove, 0);
|
|
||||||
debug_level_set(debug_level);
|
|
||||||
log(1, " pvs=%d stored=%d\n", _pvs, pos->bestmove->negamax);
|
|
||||||
} else {
|
|
||||||
log(1, "<no-best-move>");
|
|
||||||
}
|
|
||||||
printf("Depth:%d Nodes:%luK time:%.02fs (%.0f kn/s)\n", depth,
|
|
||||||
pos->node_count / 1000, (timer2 - timer1)/NANOSEC, nodes_sec/1000);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** main()
|
/** main()
|
||||||
* options:
|
* options:
|
||||||
@@ -493,20 +541,16 @@ static int usage(char *prg)
|
|||||||
|
|
||||||
int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
{
|
{
|
||||||
pos_t *pos;
|
pos_t *pos = pos_new();
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
piece_pool_init();
|
init_all();
|
||||||
moves_pool_init();
|
printf("brchess " VERSION "\n");
|
||||||
pos_pool_init();
|
|
||||||
pos = pos_get();
|
|
||||||
debug_init(1, stderr, true);
|
|
||||||
eval_simple_init();
|
|
||||||
|
|
||||||
while ((opt = getopt(ac, av, "d:f:")) != -1) {
|
while ((opt = getopt(ac, av, "d:f:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'd':
|
case 'd':
|
||||||
debug_level_set(atoi(optarg));
|
//debug_level_set(atoi(optarg));
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
fen2pos(pos, optarg);
|
fen2pos(pos, optarg);
|
||||||
|
@@ -1,199 +1,201 @@
|
|||||||
/* eval-simple.c - simple position evaluation.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 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 "br.h"
|
|
||||||
#include "debug.h"
|
|
||||||
|
|
||||||
#include "piece.h"
|
|
||||||
#include "eval-simple.h"
|
|
||||||
#include "position.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tables are from https://www.chessprogramming.org/Simplified_Evaluation_Function
|
* /\* eval-simple.c - simple position evaluation.
|
||||||
|
* *
|
||||||
|
* * Copyright (C) 2023 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>
|
||||||
|
* *
|
||||||
|
* *\/
|
||||||
*
|
*
|
||||||
* Attention! Tables are black point of view (to be visually easier to read).
|
* #include "br.h"
|
||||||
*/
|
* #include "debug.h"
|
||||||
|
|
||||||
static int mg_pawn[] = {
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
50, 50, 50, 50, 50, 50, 50, 50,
|
|
||||||
10, 10, 20, 30, 30, 20, 10, 10,
|
|
||||||
5, 5, 10, 25, 25, 10, 5, 5,
|
|
||||||
0, 0, 0, 20, 20, 0, 0, 0,
|
|
||||||
5, -5, -10, 0, 0, -10, -5, 5,
|
|
||||||
5, 10, 10, -20, -20, 10, 10, 5,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0
|
|
||||||
};
|
|
||||||
|
|
||||||
static int mg_knight[] = {
|
|
||||||
-50, -40, -30, -30, -30, -30, -40, -50,
|
|
||||||
-40, -20, 0, 0, 0, 0, -20, -40,
|
|
||||||
-30, 0, 10, 15, 15, 10, 0, -30,
|
|
||||||
-30, 5, 15, 20, 20, 15, 5, -30,
|
|
||||||
-30, 0, 15, 20, 20, 15, 0, -30,
|
|
||||||
-30, 5, 10, 15, 15, 10, 5, -30,
|
|
||||||
-40, -20, 0, 5, 5, 0, -20, -40,
|
|
||||||
-50, -40, -30, -30, -30, -30, -40, -50
|
|
||||||
};
|
|
||||||
|
|
||||||
static int mg_bishop[] = {
|
|
||||||
-20, -10, -10, -10, -10, -10, -10, -20,
|
|
||||||
-10, 0, 0, 0, 0, 0, 0, -10,
|
|
||||||
-10, 0, 5, 10, 10, 5, 0, -10,
|
|
||||||
-10, 5, 5, 10, 10, 5, 5, -10,
|
|
||||||
-10, 0, 10, 10, 10, 10, 0, -10,
|
|
||||||
-10, 10, 10, 10, 10, 10, 10, -10,
|
|
||||||
-10, 5, 0, 0, 0, 0, 5, -10,
|
|
||||||
-20, -10, -10, -10, -10, -10, -10, -20
|
|
||||||
};
|
|
||||||
|
|
||||||
static int mg_rook[] = {
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
5, 10, 10, 10, 10, 10, 10, 5,
|
|
||||||
-5, 0, 0, 0, 0, 0, 0, -5,
|
|
||||||
-5, 0, 0, 0, 0, 0, 0, -5,
|
|
||||||
-5, 0, 0, 0, 0, 0, 0, -5,
|
|
||||||
-5, 0, 0, 0, 0, 0, 0, -5,
|
|
||||||
-5, 0, 0, 0, 0, 0, 0, -5,
|
|
||||||
0, 0, 0, 5, 5, 0, 0, 0
|
|
||||||
};
|
|
||||||
|
|
||||||
static int mg_queen[] = {
|
|
||||||
-20, -10, -10, -5, -5, -10, -10, -20,
|
|
||||||
-10, 0, 0, 0, 0, 0, 0, -10,
|
|
||||||
-10, 0, 5, 5, 5, 5, 0, -10,
|
|
||||||
-5, 0, 5, 5, 5, 5, 0, -5,
|
|
||||||
0, 0, 5, 5, 5, 5, 0, -5,
|
|
||||||
-10, 5, 5, 5, 5, 5, 0, -10,
|
|
||||||
-10, 0, 5, 0, 0, 0, 0, -10,
|
|
||||||
-20, -10, -10, -5, -5, -10, -10, -20
|
|
||||||
};
|
|
||||||
|
|
||||||
static int mg_king[] = {
|
|
||||||
-30, -40, -40, -50, -50, -40, -40, -30,
|
|
||||||
-30, -40, -40, -50, -50, -40, -40, -30,
|
|
||||||
-30, -40, -40, -50, -50, -40, -40, -30,
|
|
||||||
-30, -40, -40, -50, -50, -40, -40, -30,
|
|
||||||
-20, -30, -30, -40, -40, -30, -30, -20,
|
|
||||||
-10, -20, -20, -20, -20, -20, -20, -10,
|
|
||||||
20, 20, 0, 0, 0, 0, 20, 20,
|
|
||||||
20, 30, 10, 0, 0, 10, 30, 20
|
|
||||||
};
|
|
||||||
|
|
||||||
static int eg_king[] = {
|
|
||||||
-50, -40, -30, -20, -20, -30, -40, -50,
|
|
||||||
-30, -20, -10, 0, 0, -10, -20, -30,
|
|
||||||
-30, -10, 20, 30, 30, 20, -10, -30,
|
|
||||||
-30, -10, 30, 40, 40, 30, -10, -30,
|
|
||||||
-30, -10, 30, 40, 40, 30, -10, -30,
|
|
||||||
-30, -10, 20, 30, 30, 20, -10, -30,
|
|
||||||
-30, -30, 0, 0, 0, 0, -30, -30,
|
|
||||||
-50, -30, -30, -30, -30, -30, -30, -50
|
|
||||||
};
|
|
||||||
|
|
||||||
/* as pieces bitboard tables start at position 2; we make these tables
|
|
||||||
* bigger.
|
|
||||||
*/
|
|
||||||
static int *mg_tables[] = {
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
mg_pawn,
|
|
||||||
mg_knight,
|
|
||||||
mg_bishop,
|
|
||||||
mg_rook,
|
|
||||||
mg_queen,
|
|
||||||
mg_king
|
|
||||||
};
|
|
||||||
|
|
||||||
static int *eg_tables[] = {
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
mg_pawn,
|
|
||||||
mg_knight,
|
|
||||||
mg_bishop,
|
|
||||||
mg_rook,
|
|
||||||
mg_queen,
|
|
||||||
eg_king
|
|
||||||
};
|
|
||||||
|
|
||||||
/* to flip vertically a square, we need to XOR it with 56
|
|
||||||
*/
|
|
||||||
static int mg_table[2][6 + 2][64];
|
|
||||||
static int eg_table[2][6 + 2][64];
|
|
||||||
|
|
||||||
void eval_simple_init(void)
|
|
||||||
{
|
|
||||||
# ifdef DEBUG_EVAL
|
|
||||||
log_f(1, "initializing piece tables\n");
|
|
||||||
# endif
|
|
||||||
for (int piece = BB_PAWN; piece <= BB_KING; ++piece) {
|
|
||||||
for (int square = 0; square < 64; ++square) {
|
|
||||||
mg_table[WHITE][piece][square] = mg_tables[piece][FLIP_V(square)];
|
|
||||||
eg_table[WHITE][piece][square] = eg_tables[piece][FLIP_V(square)];
|
|
||||||
mg_table[BLACK][piece][square] = mg_tables[piece][square];
|
|
||||||
eg_table[BLACK][piece][square] = eg_tables[piece][square];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* eval_simple() - simple and fast position evaluation
|
|
||||||
* @pos: &position to evaluate
|
|
||||||
*
|
*
|
||||||
* This function is normally used only during initialization,
|
* #include "piece.h"
|
||||||
* or when changing phase (middlegame <--> endgame), as the eval
|
* #include "eval-simple.h"
|
||||||
* will be done increntally when doing moves.
|
* #include "position.h"
|
||||||
*
|
*
|
||||||
* @return: the @pos evaluation in centipawns
|
* /\*
|
||||||
|
* * Tables are from https://www.chessprogramming.org/Simplified_Evaluation_Function
|
||||||
|
* *
|
||||||
|
* * Attention! Tables are black point of view (to be visually easier to read).
|
||||||
|
* *\/
|
||||||
|
*
|
||||||
|
* static int mg_pawn[] = {
|
||||||
|
* 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
* 50, 50, 50, 50, 50, 50, 50, 50,
|
||||||
|
* 10, 10, 20, 30, 30, 20, 10, 10,
|
||||||
|
* 5, 5, 10, 25, 25, 10, 5, 5,
|
||||||
|
* 0, 0, 0, 20, 20, 0, 0, 0,
|
||||||
|
* 5, -5, -10, 0, 0, -10, -5, 5,
|
||||||
|
* 5, 10, 10, -20, -20, 10, 10, 5,
|
||||||
|
* 0, 0, 0, 0, 0, 0, 0, 0
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* static int mg_knight[] = {
|
||||||
|
* -50, -40, -30, -30, -30, -30, -40, -50,
|
||||||
|
* -40, -20, 0, 0, 0, 0, -20, -40,
|
||||||
|
* -30, 0, 10, 15, 15, 10, 0, -30,
|
||||||
|
* -30, 5, 15, 20, 20, 15, 5, -30,
|
||||||
|
* -30, 0, 15, 20, 20, 15, 0, -30,
|
||||||
|
* -30, 5, 10, 15, 15, 10, 5, -30,
|
||||||
|
* -40, -20, 0, 5, 5, 0, -20, -40,
|
||||||
|
* -50, -40, -30, -30, -30, -30, -40, -50
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* static int mg_bishop[] = {
|
||||||
|
* -20, -10, -10, -10, -10, -10, -10, -20,
|
||||||
|
* -10, 0, 0, 0, 0, 0, 0, -10,
|
||||||
|
* -10, 0, 5, 10, 10, 5, 0, -10,
|
||||||
|
* -10, 5, 5, 10, 10, 5, 5, -10,
|
||||||
|
* -10, 0, 10, 10, 10, 10, 0, -10,
|
||||||
|
* -10, 10, 10, 10, 10, 10, 10, -10,
|
||||||
|
* -10, 5, 0, 0, 0, 0, 5, -10,
|
||||||
|
* -20, -10, -10, -10, -10, -10, -10, -20
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* static int mg_rook[] = {
|
||||||
|
* 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
* 5, 10, 10, 10, 10, 10, 10, 5,
|
||||||
|
* -5, 0, 0, 0, 0, 0, 0, -5,
|
||||||
|
* -5, 0, 0, 0, 0, 0, 0, -5,
|
||||||
|
* -5, 0, 0, 0, 0, 0, 0, -5,
|
||||||
|
* -5, 0, 0, 0, 0, 0, 0, -5,
|
||||||
|
* -5, 0, 0, 0, 0, 0, 0, -5,
|
||||||
|
* 0, 0, 0, 5, 5, 0, 0, 0
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* static int mg_queen[] = {
|
||||||
|
* -20, -10, -10, -5, -5, -10, -10, -20,
|
||||||
|
* -10, 0, 0, 0, 0, 0, 0, -10,
|
||||||
|
* -10, 0, 5, 5, 5, 5, 0, -10,
|
||||||
|
* -5, 0, 5, 5, 5, 5, 0, -5,
|
||||||
|
* 0, 0, 5, 5, 5, 5, 0, -5,
|
||||||
|
* -10, 5, 5, 5, 5, 5, 0, -10,
|
||||||
|
* -10, 0, 5, 0, 0, 0, 0, -10,
|
||||||
|
* -20, -10, -10, -5, -5, -10, -10, -20
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* static int mg_king[] = {
|
||||||
|
* -30, -40, -40, -50, -50, -40, -40, -30,
|
||||||
|
* -30, -40, -40, -50, -50, -40, -40, -30,
|
||||||
|
* -30, -40, -40, -50, -50, -40, -40, -30,
|
||||||
|
* -30, -40, -40, -50, -50, -40, -40, -30,
|
||||||
|
* -20, -30, -30, -40, -40, -30, -30, -20,
|
||||||
|
* -10, -20, -20, -20, -20, -20, -20, -10,
|
||||||
|
* 20, 20, 0, 0, 0, 0, 20, 20,
|
||||||
|
* 20, 30, 10, 0, 0, 10, 30, 20
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* static int eg_king[] = {
|
||||||
|
* -50, -40, -30, -20, -20, -30, -40, -50,
|
||||||
|
* -30, -20, -10, 0, 0, -10, -20, -30,
|
||||||
|
* -30, -10, 20, 30, 30, 20, -10, -30,
|
||||||
|
* -30, -10, 30, 40, 40, 30, -10, -30,
|
||||||
|
* -30, -10, 30, 40, 40, 30, -10, -30,
|
||||||
|
* -30, -10, 20, 30, 30, 20, -10, -30,
|
||||||
|
* -30, -30, 0, 0, 0, 0, -30, -30,
|
||||||
|
* -50, -30, -30, -30, -30, -30, -30, -50
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* /\* as pieces bitboard tables start at position 2; we make these tables
|
||||||
|
* * bigger.
|
||||||
|
* *\/
|
||||||
|
* static int *mg_tables[] = {
|
||||||
|
* NULL,
|
||||||
|
* NULL,
|
||||||
|
* mg_pawn,
|
||||||
|
* mg_knight,
|
||||||
|
* mg_bishop,
|
||||||
|
* mg_rook,
|
||||||
|
* mg_queen,
|
||||||
|
* mg_king
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* static int *eg_tables[] = {
|
||||||
|
* NULL,
|
||||||
|
* NULL,
|
||||||
|
* mg_pawn,
|
||||||
|
* mg_knight,
|
||||||
|
* mg_bishop,
|
||||||
|
* mg_rook,
|
||||||
|
* mg_queen,
|
||||||
|
* eg_king
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* /\* to flip vertically a square, we need to XOR it with 56
|
||||||
|
* *\/
|
||||||
|
* static int mg_table[2][6 + 2][64];
|
||||||
|
* static int eg_table[2][6 + 2][64];
|
||||||
|
*
|
||||||
|
* void eval_simple_init(void)
|
||||||
|
* {
|
||||||
|
* # ifdef DEBUG_EVAL
|
||||||
|
* log_f(1, "initializing piece tables\n");
|
||||||
|
* # endif
|
||||||
|
* for (int piece = BB_PAWN; piece <= BB_KING; ++piece) {
|
||||||
|
* for (int square = 0; square < 64; ++square) {
|
||||||
|
* mg_table[WHITE][piece][square] = mg_tables[piece][FLIP_V(square)];
|
||||||
|
* eg_table[WHITE][piece][square] = eg_tables[piece][FLIP_V(square)];
|
||||||
|
* mg_table[BLACK][piece][square] = mg_tables[piece][square];
|
||||||
|
* eg_table[BLACK][piece][square] = eg_tables[piece][square];
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* /\**
|
||||||
|
* * eval_simple() - simple and fast position evaluation
|
||||||
|
* * @pos: &position to evaluate
|
||||||
|
* *
|
||||||
|
* * This function is normally used only during initialization,
|
||||||
|
* * or when changing phase (middlegame <--> endgame), as the eval
|
||||||
|
* * will be done increntally when doing moves.
|
||||||
|
* *
|
||||||
|
* * @return: the @pos evaluation in centipawns
|
||||||
|
* *\/
|
||||||
|
* eval_t eval_simple(pos_t *pos)
|
||||||
|
* {
|
||||||
|
* eval_t eval[2] = { 0, 0 };
|
||||||
|
* int eg = simple_is_endgame(pos);
|
||||||
|
* int (*gg)[6 + 2][64]= eg? eg_table: mg_table;
|
||||||
|
*
|
||||||
|
* pos->eval_simple_phase = ENDGAME;
|
||||||
|
* # ifdef DEBUG_EVAL
|
||||||
|
* log_f(5, "phase = %s.\n", eg? "endgame": "midgame");
|
||||||
|
* # endif
|
||||||
|
*
|
||||||
|
* for (int color = WHITE; color <= BLACK; ++color) {
|
||||||
|
* for (uint piece = PAWN; piece <= KING; piece <<= 1) {
|
||||||
|
* int bb = PIECETOBB(piece), cur;
|
||||||
|
* u64 _t;
|
||||||
|
*
|
||||||
|
* # ifdef DEBUG_EVAL
|
||||||
|
* log_f(5, "p=%u bb=%d %s %s: count=%d val=%ld ", piece, bb, color? "black": "white",
|
||||||
|
* P_SYM(piece), popcount64(pos->bb[color][bb]),
|
||||||
|
* popcount64(pos->bb[color][bb]) * P_VALUE(piece));
|
||||||
|
* # endif
|
||||||
|
*
|
||||||
|
* eval[color] += popcount64(pos->bb[color][bb]) * P_LETTER(piece);
|
||||||
|
* bit_for_each64(cur, _t, pos->bb[color][bb]) {
|
||||||
|
* # ifdef DEBUG_EVAL
|
||||||
|
* log(5, "sq=%d:%d ", cur, gg[color][bb][cur]);
|
||||||
|
* # endif
|
||||||
|
* eval[color] += gg[color][bb][cur];
|
||||||
|
* }
|
||||||
|
* # ifdef DEBUG_EVAL
|
||||||
|
* log(5, "\n");
|
||||||
|
* # endif
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* # ifdef DEBUG_EVAL
|
||||||
|
* log_f(2, "eval:%d white:%d black:%d\n", eval[WHITE] - eval[BLACK],
|
||||||
|
* eval[WHITE], eval[BLACK]);
|
||||||
|
* # endif
|
||||||
|
*
|
||||||
|
* return eval[WHITE] - eval[BLACK];
|
||||||
|
* }
|
||||||
*/
|
*/
|
||||||
eval_t eval_simple(pos_t *pos)
|
|
||||||
{
|
|
||||||
eval_t eval[2] = { 0, 0 };
|
|
||||||
int eg = simple_is_endgame(pos);
|
|
||||||
int (*gg)[6 + 2][64]= eg? eg_table: mg_table;
|
|
||||||
|
|
||||||
pos->eval_simple_phase = ENDGAME;
|
|
||||||
# ifdef DEBUG_EVAL
|
|
||||||
log_f(5, "phase = %s.\n", eg? "endgame": "midgame");
|
|
||||||
# endif
|
|
||||||
|
|
||||||
for (int color = WHITE; color <= BLACK; ++color) {
|
|
||||||
for (uint piece = PAWN; piece <= KING; piece <<= 1) {
|
|
||||||
int bb = PIECETOBB(piece), cur;
|
|
||||||
u64 _t;
|
|
||||||
|
|
||||||
# ifdef DEBUG_EVAL
|
|
||||||
log_f(5, "p=%u bb=%d %s %s: count=%d val=%ld ", piece, bb, color? "black": "white",
|
|
||||||
P_SYM(piece), popcount64(pos->bb[color][bb]),
|
|
||||||
popcount64(pos->bb[color][bb]) * P_VALUE(piece));
|
|
||||||
# endif
|
|
||||||
|
|
||||||
eval[color] += popcount64(pos->bb[color][bb]) * P_LETTER(piece);
|
|
||||||
bit_for_each64(cur, _t, pos->bb[color][bb]) {
|
|
||||||
# ifdef DEBUG_EVAL
|
|
||||||
log(5, "sq=%d:%d ", cur, gg[color][bb][cur]);
|
|
||||||
# endif
|
|
||||||
eval[color] += gg[color][bb][cur];
|
|
||||||
}
|
|
||||||
# ifdef DEBUG_EVAL
|
|
||||||
log(5, "\n");
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
# ifdef DEBUG_EVAL
|
|
||||||
log_f(2, "eval:%d white:%d black:%d\n", eval[WHITE] - eval[BLACK],
|
|
||||||
eval[WHITE], eval[BLACK]);
|
|
||||||
# endif
|
|
||||||
|
|
||||||
return eval[WHITE] - eval[BLACK];
|
|
||||||
}
|
|
||||||
|
182
src/eval.c
182
src/eval.c
@@ -1,95 +1,97 @@
|
|||||||
/* eval.c - static position evaluation.
|
/*
|
||||||
|
* /\* eval.c - static position evaluation.
|
||||||
|
* *
|
||||||
|
* * Copyright (C) 2021-2023 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>
|
||||||
|
* *
|
||||||
|
* *\/
|
||||||
*
|
*
|
||||||
* Copyright (C) 2021-2023 Bruno Raoult ("br")
|
* #include <stdio.h>
|
||||||
* 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
|
* #include <list.h>
|
||||||
* program. If not, see <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
|
* #include <debug.h>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
|
* #include "position.h"
|
||||||
|
* #include "eval.h"
|
||||||
|
* #include "eval-simple.h"
|
||||||
*
|
*
|
||||||
|
* inline eval_t eval_material(pos_t *pos, bool color)
|
||||||
|
* {
|
||||||
|
* eval_t res = 0;
|
||||||
|
*
|
||||||
|
* /\* I need to do something about the king, if it can be potentially taken
|
||||||
|
* * if pseudo-moves include a pinned piece on King.
|
||||||
|
* *\/
|
||||||
|
* for (uint piece = PAWN; piece < KING; piece <<= 1) {
|
||||||
|
* uint bb = PIECETOBB(piece);
|
||||||
|
* # ifdef DEBUG_EVAL
|
||||||
|
* log_f(2, "color=%u piece=%u bb=%u=%c count=%ul val=%ld\n",
|
||||||
|
* color, piece, bb, P_LETTER(piece), popcount64(pos->bb[color][bb]),
|
||||||
|
* P_VALUE(piece));
|
||||||
|
* # endif
|
||||||
|
* /\* attention here *\/
|
||||||
|
* res += popcount64(pos->bb[color][bb]) * P_VALUE(piece);
|
||||||
|
* }
|
||||||
|
* return res;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* inline eval_t eval_mobility(pos_t *pos, bool color)
|
||||||
|
* {
|
||||||
|
* return pos->mobility[color];
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* inline eval_t eval_square_control(pos_t *pos, bool color)
|
||||||
|
* {
|
||||||
|
* return popcount64(pos->controlled[color]);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* eval_t eval(pos_t *pos)
|
||||||
|
* {
|
||||||
|
* eval_t simple = 0, control[2] = {0};
|
||||||
|
*
|
||||||
|
* if (pos->eval != EVAL_INVALID)
|
||||||
|
* return pos->eval;
|
||||||
|
*
|
||||||
|
* /\* 1) pieces value *\/
|
||||||
|
* //material[WHITE] = eval_material(pos, WHITE);
|
||||||
|
* //material[BLACK] = eval_material(pos, BLACK);
|
||||||
|
* simple = eval_simple(pos);
|
||||||
|
*
|
||||||
|
* # ifdef DEBUG_EVAL
|
||||||
|
* log_f(2, "eval_simple=%d\n", simple);
|
||||||
|
* # endif
|
||||||
|
*
|
||||||
|
* /\* 2) square control: 10 square controls diff = 1 pawn *\/
|
||||||
|
* control[WHITE] = eval_square_control(pos, WHITE);
|
||||||
|
* control[BLACK] = eval_square_control(pos, BLACK);
|
||||||
|
*
|
||||||
|
* # ifdef DEBUG_EVAL
|
||||||
|
* log_f(2, "square control: W:%d B:%d diff=%d\n",
|
||||||
|
* control[WHITE], control[BLACK],
|
||||||
|
* (control[WHITE] - control[BLACK]) * 10);
|
||||||
|
* # endif
|
||||||
|
*
|
||||||
|
* /\* 3) mobility: 10 mobility diff = 1 pawn
|
||||||
|
* *\/
|
||||||
|
* # ifdef DEBUG_EVAL
|
||||||
|
* log_f(2, "mobility: W:%u B:%u diff=%d\n",
|
||||||
|
* pos->mobility[WHITE], pos->mobility[BLACK],
|
||||||
|
* (pos->mobility[WHITE] - pos->mobility[BLACK]) * 10);
|
||||||
|
* # endif
|
||||||
|
*
|
||||||
|
* eval_t res = simple +
|
||||||
|
* (control[WHITE] - control[BLACK]) * 10 +
|
||||||
|
* (pos->mobility[WHITE] - pos->mobility[BLACK]) * 10;
|
||||||
|
* # ifdef DEBUG_EVAL
|
||||||
|
* log_f(2, "eval: %d\n", res);
|
||||||
|
* # endif
|
||||||
|
* pos->eval = res;
|
||||||
|
* return res;
|
||||||
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include <list.h>
|
|
||||||
#include <debug.h>
|
|
||||||
|
|
||||||
#include "position.h"
|
|
||||||
#include "eval.h"
|
|
||||||
#include "eval-simple.h"
|
|
||||||
|
|
||||||
inline eval_t eval_material(pos_t *pos, bool color)
|
|
||||||
{
|
|
||||||
eval_t res = 0;
|
|
||||||
|
|
||||||
/* I need to do something about the king, if it can be potentially taken
|
|
||||||
* if pseudo-moves include a pinned piece on King.
|
|
||||||
*/
|
|
||||||
for (uint piece = PAWN; piece < KING; piece <<= 1) {
|
|
||||||
uint bb = PIECETOBB(piece);
|
|
||||||
# ifdef DEBUG_EVAL
|
|
||||||
log_f(2, "color=%u piece=%u bb=%u=%c count=%ul val=%ld\n",
|
|
||||||
color, piece, bb, P_LETTER(piece), popcount64(pos->bb[color][bb]),
|
|
||||||
P_VALUE(piece));
|
|
||||||
# endif
|
|
||||||
/* attention here */
|
|
||||||
res += popcount64(pos->bb[color][bb]) * P_VALUE(piece);
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline eval_t eval_mobility(pos_t *pos, bool color)
|
|
||||||
{
|
|
||||||
return pos->mobility[color];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline eval_t eval_square_control(pos_t *pos, bool color)
|
|
||||||
{
|
|
||||||
return popcount64(pos->controlled[color]);
|
|
||||||
}
|
|
||||||
|
|
||||||
eval_t eval(pos_t *pos)
|
|
||||||
{
|
|
||||||
eval_t simple = 0, control[2] = {0};
|
|
||||||
|
|
||||||
if (pos->eval != EVAL_INVALID)
|
|
||||||
return pos->eval;
|
|
||||||
|
|
||||||
/* 1) pieces value */
|
|
||||||
//material[WHITE] = eval_material(pos, WHITE);
|
|
||||||
//material[BLACK] = eval_material(pos, BLACK);
|
|
||||||
simple = eval_simple(pos);
|
|
||||||
|
|
||||||
# ifdef DEBUG_EVAL
|
|
||||||
log_f(2, "eval_simple=%d\n", simple);
|
|
||||||
# endif
|
|
||||||
|
|
||||||
/* 2) square control: 10 square controls diff = 1 pawn */
|
|
||||||
control[WHITE] = eval_square_control(pos, WHITE);
|
|
||||||
control[BLACK] = eval_square_control(pos, BLACK);
|
|
||||||
|
|
||||||
# ifdef DEBUG_EVAL
|
|
||||||
log_f(2, "square control: W:%d B:%d diff=%d\n",
|
|
||||||
control[WHITE], control[BLACK],
|
|
||||||
(control[WHITE] - control[BLACK]) * 10);
|
|
||||||
# endif
|
|
||||||
|
|
||||||
/* 3) mobility: 10 mobility diff = 1 pawn
|
|
||||||
*/
|
|
||||||
# ifdef DEBUG_EVAL
|
|
||||||
log_f(2, "mobility: W:%u B:%u diff=%d\n",
|
|
||||||
pos->mobility[WHITE], pos->mobility[BLACK],
|
|
||||||
(pos->mobility[WHITE] - pos->mobility[BLACK]) * 10);
|
|
||||||
# endif
|
|
||||||
|
|
||||||
eval_t res = simple +
|
|
||||||
(control[WHITE] - control[BLACK]) * 10 +
|
|
||||||
(pos->mobility[WHITE] - pos->mobility[BLACK]) * 10;
|
|
||||||
# ifdef DEBUG_EVAL
|
|
||||||
log_f(2, "eval: %d\n", res);
|
|
||||||
# endif
|
|
||||||
pos->eval = res;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
@@ -191,7 +191,6 @@ int tt_create(s32 sizemb)
|
|||||||
if (sizemb <= 0)
|
if (sizemb <= 0)
|
||||||
sizemb = HASH_SIZE_DEFAULT;
|
sizemb = HASH_SIZE_DEFAULT;
|
||||||
sizemb = clamp(sizemb, HASH_SIZE_MIN, HASH_SIZE_MAX);
|
sizemb = clamp(sizemb, HASH_SIZE_MIN, HASH_SIZE_MAX);
|
||||||
//printf("-> %'6d ", sizemb);
|
|
||||||
|
|
||||||
bytes = sizemb * 1024ull * 1024ull; /* bytes wanted */
|
bytes = sizemb * 1024ull * 1024ull; /* bytes wanted */
|
||||||
target_nbuckets = bytes / sizeof(bucket_t); /* target buckets */
|
target_nbuckets = bytes / sizeof(bucket_t); /* target buckets */
|
||||||
@@ -199,7 +198,7 @@ int tt_create(s32 sizemb)
|
|||||||
nbits = msb64(target_nbuckets); /* adjust to power of 2 */
|
nbits = msb64(target_nbuckets); /* adjust to power of 2 */
|
||||||
|
|
||||||
if (hash_tt.nbits != nbits) {
|
if (hash_tt.nbits != nbits) {
|
||||||
if (hash_tt.nbits)
|
if (hash_tt.keys)
|
||||||
tt_delete();
|
tt_delete();
|
||||||
|
|
||||||
hash_tt.nbits = nbits;
|
hash_tt.nbits = nbits;
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
#define ENTRIES_PER_BUCKET 4 /* buckets per hash table entry */
|
#define ENTRIES_PER_BUCKET 4 /* buckets per hash table entry */
|
||||||
|
|
||||||
#define HASH_SIZE_DEFAULT 32 /* default: 32Mb */
|
#define HASH_SIZE_DEFAULT 32 /* default: 32Mb */
|
||||||
#define HASH_SIZE_MIN 4
|
#define HASH_SIZE_MIN 1
|
||||||
#define HASH_SIZE_MAX 32768 /* 32Gb */
|
#define HASH_SIZE_MAX 32768 /* 32Gb */
|
||||||
|
|
||||||
#define TT_MISS NULL
|
#define TT_MISS NULL
|
||||||
|
@@ -70,7 +70,7 @@ u64 perft(pos_t *pos, int depth, int ply, bool output)
|
|||||||
movelist_t movelist2;
|
movelist_t movelist2;
|
||||||
pos_set_checkers_pinners_blockers(pos);
|
pos_set_checkers_pinners_blockers(pos);
|
||||||
subnodes = pos_legal(pos, pos_gen_pseudo(pos, &movelist2))->nmoves;
|
subnodes = pos_legal(pos, pos_gen_pseudo(pos, &movelist2))->nmoves;
|
||||||
} else if (ply >= 4) {
|
} else if (ply >= 3) {
|
||||||
hentry_t *entry = tt_probe_perft(pos->key, depth);
|
hentry_t *entry = tt_probe_perft(pos->key, depth);
|
||||||
if (entry != TT_MISS) {
|
if (entry != TT_MISS) {
|
||||||
subnodes = HASH_PERFT_VAL(entry->data);
|
subnodes = HASH_PERFT_VAL(entry->data);
|
||||||
|
@@ -43,6 +43,31 @@ struct fentest {
|
|||||||
* },
|
* },
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* { __LINE__, MOVEGEN | MOVEDO | PERFT,
|
||||||
|
* "from https://talkchess.com/viewtopic.php?t=74153",
|
||||||
|
* "8/p7/8/1P6/K1k3p1/6P1/7P/8 w - - 0 1", // Perft(8) == 8,103,790
|
||||||
|
* },
|
||||||
|
* 8/5p2/8/2k3P1/p3K3/8/1P6/8 b - - // Perft(8) == 64,451,405
|
||||||
|
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* { __LINE__, MOVEGEN | MOVEDO | PERFT,
|
||||||
|
* "from https://talkchess.com/viewtopic.php?t=74153",
|
||||||
|
* "n1n5/PPPk4/8/8/8/8/4Kppp/5N1N b - - 0 1" // Perft(6) == 71,179,139
|
||||||
|
* },
|
||||||
|
* { __LINE__, MOVEGEN | MOVEDO | PERFT,
|
||||||
|
* "from https://talkchess.com/viewtopic.php?t=74153",
|
||||||
|
* "r3k2r/p6p/8/B7/1pp1p3/3b4/P6P/R3K2R w KQkq - 0 1" // Perft(6) == 77,054,993
|
||||||
|
* },
|
||||||
|
*/
|
||||||
|
{ __LINE__, FEN | MOVEGEN | MOVEDO | PERFT,
|
||||||
|
"from https://www.talkchess.com/forum/viewtopic.php?t=42463",
|
||||||
|
"rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6"
|
||||||
|
},
|
||||||
|
/*
|
||||||
|
r3k2r/pb3p2/5npp/n2p4/1p1PPB2/6P1/P2N1PBP/R3K2R w KQkq - // Perft(5) == 29,179,893
|
||||||
|
*/
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
* DO NOT DELETE NEXT LINE - sentinel entry for temp tests above. *
|
* DO NOT DELETE NEXT LINE - sentinel entry for temp tests above. *
|
||||||
* ignored if first array entry. *
|
* ignored if first array entry. *
|
||||||
@@ -249,12 +274,16 @@ struct fentest {
|
|||||||
"",
|
"",
|
||||||
"6k1/6pp/R2p4/p1p5/8/1P1r3P/6P1/6K1 b - - 3 3"
|
"6k1/6pp/R2p4/p1p5/8/1P1r3P/6P1/6K1 b - - 3 3"
|
||||||
},
|
},
|
||||||
|
{ __LINE__, FEN | MOVEGEN | MOVEDO | PERFT,
|
||||||
|
"from https://www.talkchess.com/forum/viewtopic.php?t=42463",
|
||||||
|
"rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6"
|
||||||
|
},
|
||||||
|
|
||||||
// some of tests below are from:
|
// some of tests below are from:
|
||||||
// - Rodent IV
|
// - Rodent IV
|
||||||
// - https://www.chessprogramming.net/perfect-perft/
|
// - https://www.chessprogramming.net/perfect-perft/
|
||||||
{ __LINE__, FEN | MOVEGEN | MOVEDO | PERFT,
|
{ __LINE__, FEN | MOVEGEN | MOVEDO | PERFT,
|
||||||
"",
|
"\"kiwipete\"",
|
||||||
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1"
|
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1"
|
||||||
},
|
},
|
||||||
{ __LINE__, FEN | MOVEGEN | MOVEDO | PERFT,
|
{ __LINE__, FEN | MOVEGEN | MOVEDO | PERFT,
|
||||||
|
@@ -277,7 +277,7 @@ int main(int ac, char**av)
|
|||||||
movelist_t fishmoves;
|
movelist_t fishmoves;
|
||||||
FILE *outfd = NULL;
|
FILE *outfd = NULL;
|
||||||
s64 ms, lps;
|
s64 ms, lps;
|
||||||
int opt, depth = 6, run = 3, tt = 32, newtt = 32;
|
int opt, depth = 6, run = 3, tt, newtt = HASH_SIZE_DEFAULT;
|
||||||
struct {
|
struct {
|
||||||
s64 count, ms;
|
s64 count, ms;
|
||||||
s64 minlps, maxlps;
|
s64 minlps, maxlps;
|
||||||
@@ -321,9 +321,12 @@ int main(int ac, char**av)
|
|||||||
}
|
}
|
||||||
|
|
||||||
init_all();
|
init_all();
|
||||||
if (newtt != 32 && newtt > 1) {
|
tt = hash_tt.mb;
|
||||||
printf("changing TT size from %d to %d\n", tt, newtt);
|
|
||||||
|
if (run & 1 && newtt != tt) {
|
||||||
tt_create(newtt);
|
tt_create(newtt);
|
||||||
|
|
||||||
|
printf("changing TT size from %d to %d\n", tt, newtt);
|
||||||
tt = newtt;
|
tt = newtt;
|
||||||
}
|
}
|
||||||
printf("%s: depth:%d tt_size:%d run:%x SF:%s\n",
|
printf("%s: depth:%d tt_size:%d run:%x SF:%s\n",
|
||||||
@@ -334,8 +337,6 @@ int main(int ac, char**av)
|
|||||||
tt_info();
|
tt_info();
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
printf("move_t size:%lu\n", sizeof(move_t));
|
|
||||||
|
|
||||||
if (sf_run)
|
if (sf_run)
|
||||||
outfd = open_stockfish();
|
outfd = open_stockfish();
|
||||||
|
|
||||||
@@ -346,11 +347,10 @@ int main(int ac, char**av)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
curtest++;
|
curtest++;
|
||||||
printf("test:%d line:%d", curtest, cur_line());
|
printf("test:%d line:%d fen:%s\n", curtest, cur_line(), fen);
|
||||||
if (comment)
|
if (comment)
|
||||||
printf(" comment:%s\n",
|
printf("\t\"%s\"\n",
|
||||||
*cur_comment()? cur_comment(): "no test desc");
|
*cur_comment()? cur_comment(): "no test desc");
|
||||||
printf("\t%s\n", fen);
|
|
||||||
|
|
||||||
tt_clear();
|
tt_clear();
|
||||||
|
|
||||||
@@ -432,7 +432,7 @@ int main(int ac, char**av)
|
|||||||
if (sf_run) {
|
if (sf_run) {
|
||||||
if (!res[2].ms)
|
if (!res[2].ms)
|
||||||
res[2].ms = 1;
|
res[2].ms = 1;
|
||||||
printf("total Stockfish : perft:%'lums ms:%'lums lps:%'lu min:%'lu max:%'lu "
|
printf("total Stockfish : perft:%'lu ms:%'lu lps:%'lu min:%'lu max:%'lu "
|
||||||
"(skipped %d/%d)\n",
|
"(skipped %d/%d)\n",
|
||||||
res[2].count, res[2].ms,
|
res[2].count, res[2].ms,
|
||||||
res[2].count * 1000l / res[2].ms,
|
res[2].count * 1000l / res[2].ms,
|
||||||
@@ -442,7 +442,7 @@ int main(int ac, char**av)
|
|||||||
if (run & 1) {
|
if (run & 1) {
|
||||||
if (!res[0].ms)
|
if (!res[0].ms)
|
||||||
res[0].ms = 1;
|
res[0].ms = 1;
|
||||||
printf("total perft : perft:%'lums ms:%'lums lps:%'lu min:%'lu max:%'lu "
|
printf("total perft : perft:%'lu ms:%'lu lps:%'lu min:%'lu max:%'lu "
|
||||||
"(skipped %d/%d)\n",
|
"(skipped %d/%d)\n",
|
||||||
res[0].count, res[0].ms,
|
res[0].count, res[0].ms,
|
||||||
res[0].count * 1000l / res[0].ms,
|
res[0].count * 1000l / res[0].ms,
|
||||||
@@ -452,7 +452,7 @@ int main(int ac, char**av)
|
|||||||
if (run & 2) {
|
if (run & 2) {
|
||||||
if (!res[1].ms)
|
if (!res[1].ms)
|
||||||
res[1].ms = 1;
|
res[1].ms = 1;
|
||||||
printf("total perft_alt : perft:%'lums ms:%'lums lps:%'lu min:%'lu max:%'lu "
|
printf("total perft_alt : perft:%'lu ms:%'lu lps:%'lu min:%'lu max:%'lu "
|
||||||
"(skipped %d/%d)\n",
|
"(skipped %d/%d)\n",
|
||||||
res[1].count, res[1].ms,
|
res[1].count, res[1].ms,
|
||||||
res[1].count * 1000l / res[1].ms,
|
res[1].count * 1000l / res[1].ms,
|
||||||
|
Reference in New Issue
Block a user