position add: pos_set_pinners_blockers()
This commit is contained in:
50
Makefile
50
Makefile
@@ -86,23 +86,36 @@ CPPFLAGS := $(strip $(CPPFLAGS))
|
|||||||
|
|
||||||
##################################### compiler flags
|
##################################### compiler flags
|
||||||
CFLAGS := -std=gnu11
|
CFLAGS := -std=gnu11
|
||||||
#CFLAGS += -flto
|
|
||||||
CFLAGS += -O1
|
### dev OR release
|
||||||
CFLAGS += -g
|
# dev
|
||||||
|
#CFLAGS += -O1
|
||||||
|
#CFLAGS += -g
|
||||||
|
# release
|
||||||
|
CFLAGS += -Ofast
|
||||||
|
|
||||||
|
CFLAGS += -march=native
|
||||||
|
CFLAGS += -flto
|
||||||
CFLAGS += -Wall
|
CFLAGS += -Wall
|
||||||
CFLAGS += -Wextra
|
CFLAGS += -Wextra
|
||||||
CFLAGS += -march=native
|
|
||||||
CFLAGS += -Wmissing-declarations
|
CFLAGS += -Wmissing-declarations
|
||||||
# for gprof
|
# for gprof
|
||||||
# CFLAGS += -pg
|
#CFLAGS += -pg
|
||||||
# Next one may be useful for valgrind (when invalid instructions)
|
# Next one may be useful for valgrind (when invalid instructions)
|
||||||
# CFLAGS += -mno-tbm
|
# CFLAGS += -mno-tbm
|
||||||
|
|
||||||
CFLAGS := $(strip $(CFLAGS))
|
CFLAGS := $(strip $(CFLAGS))
|
||||||
|
|
||||||
|
# development CFLAGS - unused - TODO
|
||||||
|
#DEV_CFLAGS := -O1
|
||||||
|
#DEV_CFLAGS += -g
|
||||||
|
|
||||||
|
# release CFLAGS - unused - TODO
|
||||||
|
#REL_CFLAGS := -Ofast
|
||||||
|
|
||||||
##################################### linker flags
|
##################################### linker flags
|
||||||
LDFLAGS := -L$(BRLIBDIR)
|
LDFLAGS := -L$(BRLIBDIR)
|
||||||
#LDFLAGS += -flto
|
LDFLAGS += -flto
|
||||||
|
|
||||||
LDFLAGS := $(strip $(LDFLAGS))
|
LDFLAGS := $(strip $(LDFLAGS))
|
||||||
|
|
||||||
@@ -286,19 +299,17 @@ memcheck: targets
|
|||||||
##################################### test binaries
|
##################################### test binaries
|
||||||
.PHONY: testing test
|
.PHONY: testing test
|
||||||
|
|
||||||
TEST := piece-test fen-test bitboard-test movegen-test attack-test movedo-test
|
TEST := piece-test fen-test bitboard-test movegen-test attack-test
|
||||||
|
TEST += movedo-test perft-test
|
||||||
|
|
||||||
PIECE_OBJS := piece.o
|
PIECE_OBJS := piece.o
|
||||||
FEN_OBJS := fen.o position.o piece.o bitboard.o board.o hyperbola-quintessence.o \
|
FEN_OBJS := $(PIECE_OBJS) fen.o position.o bitboard.o board.o \
|
||||||
attack.o
|
hyperbola-quintessence.o attack.o
|
||||||
BB_OBJS := fen.o position.o piece.o bitboard.o board.o hyperbola-quintessence.o \
|
BB_OBJS := $(FEN_OBJS)
|
||||||
attack.o
|
MOVEGEN_OBJS := $(BB_OBJS) move.o move-gen.o
|
||||||
MOVEGEN_OBJS := fen.o position.o piece.o bitboard.o board.o hyperbola-quintessence.o \
|
ATTACK_OBJS := $(MOVEGEN_OBJS)
|
||||||
attack.o move.o move-gen.o
|
MOVEDO_OBJS := $(ATTACK_OBJS) move-do.o
|
||||||
ATTACK_OBJS := fen.o position.o piece.o bitboard.o board.o hyperbola-quintessence.o \
|
PERFT_OBJS := $(MOVEDO_OBJS) search.o
|
||||||
attack.o move.o move-gen.o
|
|
||||||
MOVEDO_OBJS := fen.o position.o piece.o bitboard.o board.o hyperbola-quintessence.o \
|
|
||||||
attack.o move.o move-gen.o move-do.o
|
|
||||||
|
|
||||||
TEST := $(addprefix $(BINDIR)/,$(TEST))
|
TEST := $(addprefix $(BINDIR)/,$(TEST))
|
||||||
|
|
||||||
@@ -308,6 +319,7 @@ BB_OBJS := $(addprefix $(OBJDIR)/,$(BB_OBJS))
|
|||||||
MOVEGEN_OBJS := $(addprefix $(OBJDIR)/,$(MOVEGEN_OBJS))
|
MOVEGEN_OBJS := $(addprefix $(OBJDIR)/,$(MOVEGEN_OBJS))
|
||||||
ATTACK_OBJS := $(addprefix $(OBJDIR)/,$(ATTACK_OBJS))
|
ATTACK_OBJS := $(addprefix $(OBJDIR)/,$(ATTACK_OBJS))
|
||||||
MOVEDO_OBJS := $(addprefix $(OBJDIR)/,$(MOVEDO_OBJS))
|
MOVEDO_OBJS := $(addprefix $(OBJDIR)/,$(MOVEDO_OBJS))
|
||||||
|
PERFT_OBJS := $(addprefix $(OBJDIR)/,$(PERFT_OBJS))
|
||||||
|
|
||||||
test:
|
test:
|
||||||
echo TEST=$(TEST)
|
echo TEST=$(TEST)
|
||||||
@@ -339,6 +351,10 @@ bin/movedo-test: test/movedo-test.c test/common-test.h $(MOVEDO_OBJS)
|
|||||||
@echo compiling $@ test executable.
|
@echo compiling $@ test executable.
|
||||||
@$(CC) $(ALL_CFLAGS) $< $(MOVEDO_OBJS) $(ALL_LDFLAGS) -o $@
|
@$(CC) $(ALL_CFLAGS) $< $(MOVEDO_OBJS) $(ALL_LDFLAGS) -o $@
|
||||||
|
|
||||||
|
bin/perft-test: test/perft-test.c test/common-test.h $(PERFT_OBJS)
|
||||||
|
@echo compiling $@ test executable.
|
||||||
|
@$(CC) $(ALL_CFLAGS) $< $(PERFT_OBJS) $(ALL_LDFLAGS) -o $@
|
||||||
|
|
||||||
##################################### Makefile debug
|
##################################### Makefile debug
|
||||||
.PHONY: showflags wft
|
.PHONY: showflags wft
|
||||||
|
|
||||||
|
@@ -186,6 +186,30 @@ bitboard_t pos_checkers(const pos_t *pos, const color_t color)
|
|||||||
return sq_attackers(pos, occ, pos->king[color], OPPONENT(color));
|
return sq_attackers(pos, occ, pos->king[color], OPPONENT(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pos_king_pinners_blockers() - set position "pinners" and "blockers".
|
||||||
|
* @pos: &position
|
||||||
|
*
|
||||||
|
* set position "pinners" on player-to-play king.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void pos_set_pinners_blockers(pos_t *pos)
|
||||||
|
{
|
||||||
|
color_t color = pos->turn;
|
||||||
|
square_t king = pos->king[color];
|
||||||
|
bitboard_t tmp, occ = pos_occ(pos), blockers = 0;
|
||||||
|
int pinner;
|
||||||
|
|
||||||
|
pos->pinners = sq_pinners(pos, king, OPPONENT(pos->turn));
|
||||||
|
bit_for_each64(pinner, tmp, pos->pinners) {
|
||||||
|
//bitboard_t blocker =
|
||||||
|
// warn_on(popcount64(blocker) != 1);
|
||||||
|
blockers |= bb_between_excl[pinner][king] & occ;
|
||||||
|
}
|
||||||
|
pos->blockers = blockers;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pos_king_pinners() - get the "pinners" on a king "pinners".
|
* pos_king_pinners() - get the "pinners" on a king "pinners".
|
||||||
* @pos: &position
|
* @pos: &position
|
||||||
@@ -218,13 +242,12 @@ bitboard_t pos_king_blockers(const pos_t *pos, const color_t color, const bitboa
|
|||||||
square_t pinner, king = pos->king[color];
|
square_t pinner, king = pos->king[color];
|
||||||
|
|
||||||
bit_for_each64(pinner, tmp, pinners) {
|
bit_for_each64(pinner, tmp, pinners) {
|
||||||
bitboard_t blocker = bb_between_excl[pinner][king] & occ;
|
//warn_on(popcount64(blocker) != 1);
|
||||||
warn_on(popcount64(blocker) != 1);
|
//if (popcount64(blocker) != 1) {
|
||||||
if (popcount64(blocker) != 1) {
|
// printf("n blockers = %d\n", popcount64(blocker));
|
||||||
printf("n blockers = %d\n", popcount64(blocker));
|
// bb_print("blockers", blocker);
|
||||||
bb_print("blockers", blocker);
|
//}
|
||||||
}
|
blockers |= bb_between_excl[pinner][king] & occ;
|
||||||
blockers |= blocker;
|
|
||||||
}
|
}
|
||||||
return blockers;
|
return blockers;
|
||||||
}
|
}
|
||||||
@@ -333,7 +356,7 @@ void pos_print_mask(const pos_t *pos, const bitboard_t mask)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pos_print_board_raw - print simple position board (octal/FEN symbol values)
|
* pos_print_raw - print simple position board (octal/FEN symbol values)
|
||||||
* @bb: the bitboard
|
* @bb: the bitboard
|
||||||
* @type: int, 0 for octal, 1 for fen symbol
|
* @type: int, 0 for octal, 1 for fen symbol
|
||||||
*/
|
*/
|
||||||
|
@@ -30,7 +30,8 @@ typedef struct __pos_s {
|
|||||||
u64 node_count; /* evaluated nodes */
|
u64 node_count; /* evaluated nodes */
|
||||||
int turn; /* WHITE or BLACK */
|
int turn; /* WHITE or BLACK */
|
||||||
|
|
||||||
/* data which cannot be recovered by move_undo
|
/* data which cannot be recovered by move_undo (like castle_rights, ...),
|
||||||
|
* or would be expensive to recover (checkers, ...)
|
||||||
* following data can be accessed either directly, either via "movesave"
|
* following data can be accessed either directly, either via "movesave"
|
||||||
* structure name.
|
* structure name.
|
||||||
* For example, pos->en_passant and pos->state.en_passant are the same.
|
* For example, pos->en_passant and pos->state.en_passant are the same.
|
||||||
@@ -48,7 +49,6 @@ typedef struct __pos_s {
|
|||||||
);
|
);
|
||||||
|
|
||||||
piece_t board[BOARDSIZE];
|
piece_t board[BOARDSIZE];
|
||||||
|
|
||||||
bitboard_t bb[2][PIECE_TYPE_MAX]; /* bb[0][PAWN], bb[1][ALL_PIECES] */
|
bitboard_t bb[2][PIECE_TYPE_MAX]; /* bb[0][PAWN], bb[1][ALL_PIECES] */
|
||||||
//bitboard_t controlled[2]; /* unsure */
|
//bitboard_t controlled[2]; /* unsure */
|
||||||
square_t king[2]; /* dup with bb, faster retrieval */
|
square_t king[2]; /* dup with bb, faster retrieval */
|
||||||
@@ -159,12 +159,11 @@ void pos_del(pos_t *pos);
|
|||||||
pos_t *pos_clear(pos_t *pos);
|
pos_t *pos_clear(pos_t *pos);
|
||||||
bool pos_cmp(const pos_t *pos1, const pos_t *pos2);
|
bool pos_cmp(const pos_t *pos1, const pos_t *pos2);
|
||||||
|
|
||||||
|
//bitboard_t set_king_pinners_blockers(pos_t *pos);
|
||||||
|
void pos_set_pinners_blockers(pos_t *pos);
|
||||||
bitboard_t pos_checkers(const pos_t *pos, const color_t color);
|
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_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 );
|
bitboard_t pos_king_blockers(const pos_t *pos, const color_t color, const bitboard_t );
|
||||||
//bitboard_t set_king_pinners_blockers(pos_t *pos);
|
|
||||||
//char *pos_checkers2str(const pos_t *pos, char *str);
|
|
||||||
//char *pos_pinners2str(const pos_t *pos, char *str);
|
|
||||||
|
|
||||||
int pos_check(const pos_t *pos, const bool strict);
|
int pos_check(const pos_t *pos, const bool strict);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user