diff --git a/Makefile b/Makefile index 542bb56..bae6a13 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,6 @@ CPPFILES := $(SRC:.c=.i) $(TSTSRC:.c=.i) CPPFLAGS := -I$(BRINCDIR) -I$(INCDIR) CPPFLAGS += -DNDEBUG # assert -CPPFLAGS += -DBUG_ON # brlib bug.h CPPFLAGS += -DWARN_ON # brlib bug.h #CPPFLAGS += -DDEBUG # global - unused @@ -79,6 +78,9 @@ CPPFLAGS += -DWARN_ON # brlib bug.h CPPFLAGS += -DDIAGRAM_SYM # UTF8 symbols in diagrams +# Never comment this one ! +CPPFLAGS += -DBUG_ON # brlib bug.h + # remove extraneous spaces (due to spaces before comments) CPPFLAGS := $(strip $(CPPFLAGS)) diff --git a/src/chessdefs.h b/src/chessdefs.h index 19d2382..59f2837 100644 --- a/src/chessdefs.h +++ b/src/chessdefs.h @@ -173,6 +173,8 @@ s64 clock_elapsed_μs(mclock_t *clock); s64 clock_elapsed_ms(mclock_t *clock); double clock_elapsed_sec(mclock_t *clock); +#define RAND_SEED_DEFAULT U64(1) + void rand_init(u64 seed); u64 rand64(void); diff --git a/src/init.c b/src/init.c new file mode 100644 index 0000000..a12957a --- /dev/null +++ b/src/init.c @@ -0,0 +1,42 @@ +/* init.c - initialize all. + * + * Copyright (C) 2024 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include +#include + +#include "chessdefs.h" + +#include "bitboard.h" +#include "hyperbola-quintessence.h" + +#include "hash.h" + +void init_all() +{ + /* for printf() numeric thousands separator */ + setlocale(LC_NUMERIC, ""); + /* line-buffered stdout */ + setlinebuf(stdout); + + /* pseudo random generator seed */ + rand_init(RAND_SEED_DEFAULT); + + /* bitboards & hq */ + bitboard_init(); + hyperbola_init(); + + /* zobrist tables & default tt hashtable */ + zobrist_init(); + hash_create(HASH_DEFAULT); + +} diff --git a/src/util.h b/src/util.h index 2036366..8ce8dd8 100644 --- a/src/util.h +++ b/src/util.h @@ -17,13 +17,19 @@ #include #include -#include "bug.h" +#include #include "chessdefs.h" #undef safe_malloc #undef safe_free +/* force BUG_ON, to get a program abort for failed malloc/free + */ +#pragma push_macro("BUG_ON") +#undef BUG_ON +#define BUG_ON + #define safe_malloc(size) ({ \ void *_ret = malloc(size); \ bug_on(_ret == NULL); \ @@ -35,4 +41,8 @@ free(ptr); \ } while (0) +/* restore BUG_ON + */ +# pragma pop_macro("BUG_ON") + #endif /* UTIL_H */