Added makefile and rook mask generation

This commit is contained in:
rektdie committed 2024-03-03 12:45:01 +01:00
1 parent 9976cb0968
commit 78fe989180
11 files changed
+76 -10

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
# Ignore object files
obj/
# Ignore executable files
*.exe
Chess-Test
Executable
BIN
View File
Binary file not shown.
+33
View File
@@ -0,0 +1,33 @@
# Define the directories
SRC_DIR := source
OBJ_DIR := obj
# Determine platform
ifeq ($(OS),Windows_NT)
EXE_EXT := .exe
else
EXE_EXT :=
endif
# List of source files
SRCS := $(wildcard $(SRC_DIR)/*.cpp)
# List of object files
OBJS := $(addprefix $(OBJ_DIR)/, $(notdir $(SRCS:.cpp=.o)))
# Target executable
Chess-Test$(EXE_EXT): $(OBJS)
g++ -o $@ $^
# Rule to compile source files to object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
g++ -c -o $@ $<
# Dependencies
main.o: $(SRC_DIR)/main.cpp $(SRC_DIR)/types.h $(SRC_DIR)/board.h $(SRC_DIR)/movegen.h
bitboards.o: $(SRC_DIR)/bitboards.cpp $(SRC_DIR)/bitboards.h
board.o: $(SRC_DIR)/board.cpp $(SRC_DIR)/board.h
movegen.o: $(SRC_DIR)/movegen.cpp $(SRC_DIR)/movegen.h
# Create the object directory if it doesn't exist
$(shell mkdir -p $(OBJ_DIR))
File renamed without changes.
View File
File renamed without changes.
View File
File renamed without changes.
View File
File renamed without changes.
+1 -3
View File
@@ -8,9 +8,7 @@ int main() {
board.Init(); board.Init();
initLeaperAttacks(); initLeaperAttacks();
maskRookAttacks(e4).PrintBoard();
system("Color 0a");
maskBishopAttacks(e6).PrintBoard();
return 0; return 0;
} }
+33 -7
View File
@@ -63,9 +63,6 @@ Bitboard maskKingAttacks(int square) {
Bitboard maskBishopAttacks(int square) { Bitboard maskBishopAttacks(int square) {
Bitboard attacks; Bitboard attacks;
// ranks and files
int r, f;
// target rank and files // target rank and files
int tr = square / 8; int tr = square / 8;
int tf = square % 8; int tf = square % 8;
@@ -73,25 +70,54 @@ Bitboard maskBishopAttacks(int square) {
// mask relevant occupancy bits // mask relevant occupancy bits
// North West // North West
for (r = tr + 1, f = tf - 1; r <= 6 && f >= 1; r++, f--) { for (int r = tr + 1, f = tf - 1; r <= 6 && f >= 1; r++, f--) {
attacks |= (1ULL << (r * 8 + f)); attacks |= (1ULL << (r * 8 + f));
} }
// North East // North East
for (r = tr + 1, f = tf + 1; r <= 6 && f <= 6; r++, f++) { for (int r = tr + 1, f = tf + 1; r <= 6 && f <= 6; r++, f++) {
attacks |= (1ULL << (r * 8 + f)); attacks |= (1ULL << (r * 8 + f));
} }
//South West //South West
for (r = tr - 1, f = tf - 1; r >= 1 && f >= 1; r--, f--) { for (int r = tr - 1, f = tf - 1; r >= 1 && f >= 1; r--, f--) {
attacks |= (1ULL << (r * 8 + f)); attacks |= (1ULL << (r * 8 + f));
} }
//South East //South East
for (r = tr - 1, f = tf + 1; r >= 1 && f <= 6; r--, f++) { for (int r = tr - 1, f = tf + 1; r >= 1 && f <= 6; r--, f++) {
attacks |= (1ULL << (r * 8 + f)); attacks |= (1ULL << (r * 8 + f));
} }
return attacks; return attacks;
} }
Bitboard maskRookAttacks(int square) {
Bitboard attacks;
// target rank and files
int tr = square / 8;
int tf = square % 8;
// mask relevant occupancy bits
// North
for (int r = tr + 1; r <= 6; r++) {
attacks |= (1ULL << (r * 8 + tf));
}
// South
for (int r = tr - 1; r >= 1; r--) {
attacks |= (1ULL << (r * 8 + tf));
}
// East
for (int f = tf + 1; f <= 6; f++) {
attacks |= (1ULL << (tr * 8 + f));
}
// West
for (int f = tf - 1; f >= 1; f--) {
attacks |= (1ULL << (tr * 8 + f));
}
return attacks;
}
void initLeaperAttacks() { void initLeaperAttacks() {
for (int square = 0; square < 64; square++) { for (int square = 0; square < 64; square++) {
pawnAttacks[White][square] = maskPawnAttacks(White, square); pawnAttacks[White][square] = maskPawnAttacks(White, square);
+3
View File
@@ -19,4 +19,7 @@ Bitboard maskKingAttacks(int square);
// generate bishop attacks // generate bishop attacks
Bitboard maskBishopAttacks(int square); Bitboard maskBishopAttacks(int square);
// generate rook attacks
Bitboard maskRookAttacks(int square);
void initLeaperAttacks(); void initLeaperAttacks();
View File
File renamed without changes.