diff --git a/Makefile b/Makefile index 3effa97..1004916 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ OBJ := $(addprefix $(OBJDIR)/,$(SRC_FN:.c=.o)) TSTSRC := $(wildcard $(TSTDIR)/*.c) LIB := br_$(shell uname -m) # library name -LIBS := $(strip -l$(LIB) -lreadline) +LIBS := $(strip -l$(LIB) -lreadline -lncurses -ltinfo) DEP_FN := $(SRC_FN) DEP := $(addprefix $(DEPDIR)/,$(DEP_FN:.c=.d)) @@ -52,8 +52,38 @@ TARGET := $(addprefix $(BINDIR)/,$(TARGET_FN)) ASMFILES := $(SRC:.c=.s) $(TSTSRC:.c=.s) 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 -CPPFLAGS := -I$(BRINCDIR) -I$(INCDIR) +CPPFLAGS := -I$(BRINCDIR) -I$(INCDIR) -DVERSION=\"$(VERSION)\" CPPFLAGS += -DNDEBUG # assert (unused) CPPFLAGS += -DWARN_ON # brlib bug.h @@ -319,7 +349,7 @@ $(CCLSROOT): # maybe run cleanobj cleanlibobj in commands ? $(CCLSFILE): cleanobj cleanbrlib libs | $(CCLSROOT) @echo "Generating ccls compile commands file ($@)." - @$(BEAR) -- $(MAKE) testing + @$(BEAR) -- $(MAKE) ##################################### valgrind (mem check) .PHONY: memcheck @@ -404,12 +434,13 @@ bin/tt-test: test/tt-test.c test/common-test.h $(TT_OBJS) ##################################### Makefile debug .PHONY: showflags wft -showflags: - @echo CFLAGS: "$(CFLAGS)" - @echo CPPFLAGS: $(CPPFLAGS) - @echo DEPFLAGS: $(DEPFLAGS) - @echo LDFLAGS: $(LDFLAGS) - @echo DEPFLAGS: $(DEPFLAGS) +info: + @printf "CFLAGS: +%s+\n" "$(CFLAGS)" + @printf "CPPFLAGS: +%s+\n" "$(CPPFLAGS)" + @printf "DEPFLAGS: +%s+\n" "$(DEPFLAGS)" + @printf "LDFLAGS: +%s+\n" "$(LDFLAGS)" + @printf "DEPFLAGS: +%s+\n" "$(DEPFLAGS)" + @printf "VERSION: +%s+\n" "$(VERSION)" wtf: @printf "BRLIBDIR=%s\n" "$(BRLIBDIR)" @@ -422,7 +453,7 @@ wtf: @#echo LIBSRC=$(LIBSRC) 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 endif diff --git a/src/hash.c b/src/hash.c index 6615ba4..dfdb50a 100644 --- a/src/hash.c +++ b/src/hash.c @@ -191,7 +191,6 @@ int tt_create(s32 sizemb) if (sizemb <= 0) sizemb = HASH_SIZE_DEFAULT; sizemb = clamp(sizemb, HASH_SIZE_MIN, HASH_SIZE_MAX); - //printf("-> %'6d ", sizemb); bytes = sizemb * 1024ull * 1024ull; /* bytes wanted */ 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 */ if (hash_tt.nbits != nbits) { - if (hash_tt.nbits) + if (hash_tt.keys) tt_delete(); hash_tt.nbits = nbits; diff --git a/src/hash.h b/src/hash.h index c57eed8..6615710 100644 --- a/src/hash.h +++ b/src/hash.h @@ -21,7 +21,7 @@ #define ENTRIES_PER_BUCKET 4 /* buckets per hash table entry */ #define HASH_SIZE_DEFAULT 32 /* default: 32Mb */ -#define HASH_SIZE_MIN 4 +#define HASH_SIZE_MIN 1 #define HASH_SIZE_MAX 32768 /* 32Gb */ #define TT_MISS NULL diff --git a/src/search.c b/src/search.c index 411272b..65cf9a7 100644 --- a/src/search.c +++ b/src/search.c @@ -70,7 +70,7 @@ u64 perft(pos_t *pos, int depth, int ply, bool output) movelist_t movelist2; pos_set_checkers_pinners_blockers(pos); 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); if (entry != TT_MISS) { subnodes = HASH_PERFT_VAL(entry->data); diff --git a/test/common-test.h b/test/common-test.h index 6328899..c4b5f66 100644 --- a/test/common-test.h +++ b/test/common-test.h @@ -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. * * ignored if first array entry. * @@ -249,12 +274,16 @@ struct fentest { "", "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: // - Rodent IV // - https://www.chessprogramming.net/perfect-perft/ { __LINE__, FEN | MOVEGEN | MOVEDO | PERFT, - "", + "\"kiwipete\"", "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1" }, { __LINE__, FEN | MOVEGEN | MOVEDO | PERFT, diff --git a/test/perft-test.c b/test/perft-test.c index 8db151d..17b9cfc 100644 --- a/test/perft-test.c +++ b/test/perft-test.c @@ -277,7 +277,7 @@ int main(int ac, char**av) movelist_t fishmoves; FILE *outfd = NULL; 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 { s64 count, ms; s64 minlps, maxlps; @@ -321,9 +321,12 @@ int main(int ac, char**av) } init_all(); - if (newtt != 32 && newtt > 1) { - printf("changing TT size from %d to %d\n", tt, newtt); + tt = hash_tt.mb; + + if (run & 1 && newtt != tt) { tt_create(newtt); + + printf("changing TT size from %d to %d\n", tt, newtt); tt = newtt; } printf("%s: depth:%d tt_size:%d run:%x SF:%s\n", @@ -334,8 +337,6 @@ int main(int ac, char**av) tt_info(); printf("\n"); - printf("move_t size:%lu\n", sizeof(move_t)); - if (sf_run) outfd = open_stockfish(); @@ -346,11 +347,10 @@ int main(int ac, char**av) continue; } curtest++; - printf("test:%d line:%d", curtest, cur_line()); + printf("test:%d line:%d fen:%s\n", curtest, cur_line(), fen); if (comment) - printf(" comment:%s\n", + printf("\t\"%s\"\n", *cur_comment()? cur_comment(): "no test desc"); - printf("\t%s\n", fen); tt_clear(); @@ -432,7 +432,7 @@ int main(int ac, char**av) if (sf_run) { if (!res[2].ms) 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", res[2].count, res[2].ms, res[2].count * 1000l / res[2].ms, @@ -442,7 +442,7 @@ int main(int ac, char**av) if (run & 1) { if (!res[0].ms) 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", res[0].count, res[0].ms, res[0].count * 1000l / res[0].ms, @@ -452,7 +452,7 @@ int main(int ac, char**av) if (run & 2) { if (!res[1].ms) 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", res[1].count, res[1].ms, res[1].count * 1000l / res[1].ms,