diff --git a/Makefile b/Makefile index 6dba1e9..8550f52 100644 --- a/Makefile +++ b/Makefile @@ -89,10 +89,10 @@ CFLAGS := -std=gnu11 ### dev OR release # dev -#CFLAGS += -O1 +CFLAGS += -O1 #CFLAGS += -g # release -CFLAGS += -Ofast +#CFLAGS += -Ofast CFLAGS += -march=native CFLAGS += -flto @@ -100,7 +100,7 @@ CFLAGS += -Wall CFLAGS += -Wextra CFLAGS += -Wmissing-declarations # for gprof -#CFLAGS += -pg +CFLAGS += -pg # Next one may be useful for valgrind (when invalid instructions) # CFLAGS += -mno-tbm diff --git a/src/fen.c b/src/fen.c index 8b34afa..741b2ed 100644 --- a/src/fen.c +++ b/src/fen.c @@ -75,7 +75,7 @@ static const char *castle_str = "KQkq"; static int fen_check(pos_t *pos) { char *colstr[2] = { "white", "black"}; - int error = 0, warning = 0; + int warning = 0; /* en passant, depends on who plays next */ if (pos->en_passant != SQUARE_NONE) { @@ -130,13 +130,7 @@ static int fen_check(pos_t *pos) } } } - if (!(error = pos_check(pos, 0))) { - /* TODO: Should it really be here ? */ - pos->checkers = pos_checkers(pos, pos->turn); - pos->pinners = pos_king_pinners(pos, pos->turn); - pos->blockers = pos_king_blockers(pos, pos->turn, pos->pinners); - } - return error ? -1: warning; + return pos_ok(pos, 0) ? warning: -1; } /** diff --git a/src/move-gen.c b/src/move-gen.c index 14f1d23..1c62ffc 100644 --- a/src/move-gen.c +++ b/src/move-gen.c @@ -169,7 +169,7 @@ movelist_t *pos_all_legal(const pos_t *pos, movelist_t *movelist, movelist_t *de * - castling, if king passes an enemy-controlled square (not final square). * When immediately known, a few move flags are also applied in these cases: * - castling: M_CASTLE_{K,Q} - * - pawn capture (excl. en-passant): M_CAPTURE + * - capture (excl. en-passant): M_CAPTURE * - en-passant: M_EN_PASSANT * - pawn double push: M_DPUSH * - promotion: M_PROMOTION diff --git a/src/position.c b/src/position.c index 3ffb827..969e1ae 100644 --- a/src/position.c +++ b/src/position.c @@ -187,11 +187,30 @@ bitboard_t pos_checkers(const pos_t *pos, const color_t color) } /** - * pos_king_pinners_blockers() - set position "pinners" and "blockers". + * pos_set_checkers_pinners_blockers() - calculate checkers, pinners and blockers. * @pos: &position * - * set position "pinners" on player-to-play king. + * Set position checkers, pinners and blockers on player-to-play king. + * It should be faster than @pos_checkers + @pos_set_pinners_blockers, as + * some calculation will be done once. + */ +/* + * void pos_set_checkers_pinners_blockers(pos_t *pos) + * { + * bitboard_t b_bb = pos->bb[WHITE][BISHOP] | pos->bb[BLACK][BISHOP]; + * bitboard_t r_bb = pos->bb[WHITE][ROOK] | pos->bb[BLACK][ROOK]; + * bitboard_t q_bb = pos->bb[WHITE][QUEEN] | pos->bb[BLACK][QUEEN]; * + * /\* find out first piece on every diagonal *\/ + * + * } + */ + +/** + * pos_set_pinners_blockers() - set position pinners and blockers. + * @pos: &position + * + * set position pinners and blockers on player-to-play king. */ void pos_set_pinners_blockers(pos_t *pos) { @@ -253,7 +272,7 @@ bitboard_t pos_king_blockers(const pos_t *pos, const color_t color, const bitboa } /** - * pos_check() - extensive position consistency check. + * pos_ok() - extensive position consistency check. * @pos: &position * @strict: if true, call bug_on() on any error. * @@ -278,9 +297,9 @@ bitboard_t pos_king_blockers(const pos_t *pos, const color_t color, const bitboa * TODO: add more checks: * - kings attacking each other * - * @Return: Number of detected error (only if @strict is false). + * @return: (if @strict is false) return true if check is ok, false otherwise. */ -int pos_check(const pos_t *pos, const bool strict) +bool pos_ok(const pos_t *pos, const bool strict) { int n, count = 0, bbcount = 0, error = 0; bitboard_t tmp; @@ -324,7 +343,7 @@ int pos_check(const pos_t *pos, const bool strict) error += warn_on(sq_dist(pos->king[WHITE], pos->king[BLACK]) < 2); bug_on(strict && error); - return error; + return error? false: true; } /** diff --git a/src/position.h b/src/position.h index 2a41a68..0e76a06 100644 --- a/src/position.h +++ b/src/position.h @@ -165,7 +165,7 @@ bitboard_t pos_checkers(const pos_t *pos, const color_t color); bitboard_t pos_king_pinners(const pos_t *pos, const color_t color); bitboard_t pos_king_blockers(const pos_t *pos, const color_t color, const bitboard_t ); -int pos_check(const pos_t *pos, const bool strict); +bool pos_ok(const pos_t *pos, const bool strict); void pos_print(const pos_t *pos); void pos_print_mask(const pos_t *pos, const bitboard_t mask);