diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fa103f5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# Ignore object files +obj/ + +# Ignore executable files +*.exe +Chess-Test diff --git a/Chess-Test b/Chess-Test new file mode 100755 index 0000000..1c3dbea Binary files /dev/null and b/Chess-Test differ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..36c1614 --- /dev/null +++ b/Makefile @@ -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)) diff --git a/bitboards.cpp b/source/bitboards.cpp similarity index 100% rename from bitboards.cpp rename to source/bitboards.cpp diff --git a/bitboards.h b/source/bitboards.h similarity index 100% rename from bitboards.h rename to source/bitboards.h diff --git a/board.cpp b/source/board.cpp similarity index 100% rename from board.cpp rename to source/board.cpp diff --git a/board.h b/source/board.h similarity index 100% rename from board.h rename to source/board.h diff --git a/main.cpp b/source/main.cpp similarity index 68% rename from main.cpp rename to source/main.cpp index b688637..b7ece75 100644 --- a/main.cpp +++ b/source/main.cpp @@ -8,9 +8,7 @@ int main() { board.Init(); initLeaperAttacks(); - - system("Color 0a"); - maskBishopAttacks(e6).PrintBoard(); + maskRookAttacks(e4).PrintBoard(); return 0; } \ No newline at end of file diff --git a/movegen.cpp b/source/movegen.cpp similarity index 77% rename from movegen.cpp rename to source/movegen.cpp index 8af16f3..fb47454 100644 --- a/movegen.cpp +++ b/source/movegen.cpp @@ -63,9 +63,6 @@ Bitboard maskKingAttacks(int square) { Bitboard maskBishopAttacks(int square) { Bitboard attacks; - // ranks and files - int r, f; - // target rank and files int tr = square / 8; int tf = square % 8; @@ -73,25 +70,54 @@ Bitboard maskBishopAttacks(int square) { // mask relevant occupancy bits // 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)); } // 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)); } //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)); } //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)); } 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() { for (int square = 0; square < 64; square++) { pawnAttacks[White][square] = maskPawnAttacks(White, square); diff --git a/movegen.h b/source/movegen.h similarity index 84% rename from movegen.h rename to source/movegen.h index c2f8566..260f280 100644 --- a/movegen.h +++ b/source/movegen.h @@ -19,4 +19,7 @@ Bitboard maskKingAttacks(int square); // generate bishop attacks Bitboard maskBishopAttacks(int square); +// generate rook attacks +Bitboard maskRookAttacks(int square); + void initLeaperAttacks(); \ No newline at end of file diff --git a/types.h b/source/types.h similarity index 100% rename from types.h rename to source/types.h