moved imports from cpp files to headers + Makefile bugfix
This commit is contained in:
1 parent
67d6095aba
commit
f7d65e8af8
9 files changed
+97
-20
No files matched your search
@@ -20,14 +20,9 @@ Chess-Test$(EXE_EXT): $(OBJS)
|
||||
g++ -o $@ $^
|
||||
|
||||
# Rule to compile source files to object files
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(SRC_DIR)/types.h | $(OBJ_DIR)
|
||||
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 $(OBJ_DIR))
|
||||
$(OBJ_DIR):
|
||||
mkdir -p $@
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <iostream>
|
||||
#include "bitboards.h"
|
||||
|
||||
void Bitboard::PrintBoard() const {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include "types.h"
|
||||
|
||||
struct Bitboard {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#include "board.h"
|
||||
#include "types.h"
|
||||
#include "bitboards.h"
|
||||
#include <iostream>
|
||||
|
||||
void Board::Init() {
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "bitboards.h"
|
||||
#include <array>
|
||||
#include "bitboards.h"
|
||||
#include "types.h"
|
||||
|
||||
class Board {
|
||||
public:
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ int main() {
|
||||
board.Init();
|
||||
|
||||
initLeaperAttacks();
|
||||
maskRookAttacks(e4).PrintBoard();
|
||||
rookAttacksOnTheFly(e4, board.occupied).PrintBoard();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -118,6 +118,84 @@ Bitboard maskRookAttacks(int square) {
|
||||
return attacks;
|
||||
}
|
||||
|
||||
Bitboard bishopAttacksOnTheFly(int square, Bitboard block) {
|
||||
Bitboard attacks;
|
||||
|
||||
// target rank and files
|
||||
int tr = square / 8;
|
||||
int tf = square % 8;
|
||||
|
||||
Bitboard currentSquare;
|
||||
|
||||
// generate bishop attacks
|
||||
|
||||
// North West
|
||||
for (int r = tr + 1, f = tf - 1; r <= 7 && f >= 0; r++, f--) {
|
||||
currentSquare = (1ULL << (r * 8 + f));
|
||||
if ((currentSquare & block).GetBoard()) break;
|
||||
attacks |= currentSquare;
|
||||
}
|
||||
// North East
|
||||
for (int r = tr + 1, f = tf + 1; r <= 7 && f <= 7; r++, f++) {
|
||||
currentSquare = (1ULL << (r * 8 + f));
|
||||
if ((currentSquare & block).GetBoard()) break;
|
||||
attacks |= currentSquare;
|
||||
}
|
||||
//South West
|
||||
for (int r = tr - 1, f = tf - 1; r >= 0 && f >= 0; r--, f--) {
|
||||
currentSquare = (1ULL << (r * 8 + f));
|
||||
if ((currentSquare & block).GetBoard()) break;
|
||||
attacks |= currentSquare;
|
||||
}
|
||||
//South East
|
||||
for (int r = tr - 1, f = tf + 1; r >= 0 && f <= 7; r--, f++) {
|
||||
currentSquare = (1ULL << (r * 8 + f));
|
||||
if ((currentSquare & block).GetBoard()) break;
|
||||
attacks |= currentSquare;
|
||||
}
|
||||
|
||||
return attacks;
|
||||
}
|
||||
|
||||
Bitboard rookAttacksOnTheFly(int square, Bitboard block) {
|
||||
Bitboard attacks;
|
||||
|
||||
// target rank and files
|
||||
int tr = square / 8;
|
||||
int tf = square % 8;
|
||||
|
||||
Bitboard currentSquare;
|
||||
|
||||
// generate rook attacks
|
||||
|
||||
// North
|
||||
for (int r = tr + 1; r <= 7; r++) {
|
||||
currentSquare = (1ULL << (r * 8 + tf));
|
||||
if ((currentSquare & block).GetBoard()) break;
|
||||
attacks |= currentSquare;
|
||||
}
|
||||
//South
|
||||
for (int r = tr - 1; r >= 0; r--) {
|
||||
currentSquare = (1ULL << (r * 8 + tf));
|
||||
if ((currentSquare & block).GetBoard()) break;
|
||||
attacks |= currentSquare;
|
||||
}
|
||||
// East
|
||||
for (int f = tf + 1; f <= 7; f++) {
|
||||
currentSquare = (1ULL << (tr * 8 + f));
|
||||
if ((currentSquare & block).GetBoard()) break;
|
||||
attacks |= currentSquare;
|
||||
}
|
||||
//West
|
||||
for (int f = tf - 1; f >= 0; f--) {
|
||||
currentSquare = (1ULL << (tr * 8 + f));
|
||||
if ((currentSquare & block).GetBoard()) break;
|
||||
attacks |= currentSquare;
|
||||
}
|
||||
|
||||
return attacks;
|
||||
}
|
||||
|
||||
void initLeaperAttacks() {
|
||||
for (int square = 0; square < 64; square++) {
|
||||
pawnAttacks[White][square] = maskPawnAttacks(White, square);
|
||||
|
||||
+11
-6
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include <array>
|
||||
#include "bitboards.h"
|
||||
|
||||
// pawn attacks table [side][square]
|
||||
@@ -7,19 +6,25 @@ extern Bitboard pawnAttacks[2][64];
|
||||
extern Bitboard knightAttacks[64];
|
||||
extern Bitboard kingAttacks[64];
|
||||
|
||||
// generate pawn attacks
|
||||
// generate pawn masks
|
||||
Bitboard maskPawnAttacks(int square, int side);
|
||||
|
||||
// generate knight attacks
|
||||
// generate knight masks
|
||||
Bitboard maskKnightAttacks(int square);
|
||||
|
||||
// generate king attacks
|
||||
// generate king masks
|
||||
Bitboard maskKingAttacks(int square);
|
||||
|
||||
// generate bishop attacks
|
||||
// generate bishop masks
|
||||
Bitboard maskBishopAttacks(int square);
|
||||
|
||||
// generate rook attacks
|
||||
//generate bishop attacks
|
||||
Bitboard bishopAttacksOnTheFly(int square, Bitboard block);
|
||||
|
||||
// generate rook masks
|
||||
Bitboard maskRookAttacks(int square);
|
||||
|
||||
//generate rook attacks
|
||||
Bitboard rookAttacksOnTheFly(int square, Bitboard block);
|
||||
|
||||
void initLeaperAttacks();
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
|
||||
using U64 = uint64_t;
|
||||
|
||||
constexpr char StartingFen[] = "3b4/3P1N2/2b1P2K/n4r2/6Pk/3p2r1/2P1qQ2/6n1 w - - 0 1";
|
||||
constexpr char StartingFen[] = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
||||
|
||||
enum COLOR {
|
||||
White,
|
||||
|
||||
Reference in new issue
Block a user