Skip to content

Commit efe9cc3

Browse files
committed
format
1 parent d9274fa commit efe9cc3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2468
-2404
lines changed

Bit-Genie/src/Square.h

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,58 +34,60 @@ enum Square : uint8_t
3434

3535
enum class Direction : int8_t
3636
{
37-
north = 8, south = -8,
38-
east = 1, west = -1,
37+
north = 8,
38+
south = -8,
39+
east = 1,
40+
west = -1,
3941
};
4042

41-
template<typename E>
42-
inline Square to_sq(E const& e)
43+
template <typename E>
44+
inline Square to_sq(E const &e)
4345
{
44-
return static_cast<Square>(e);
46+
return static_cast<Square>(e);
4547
}
4648

47-
template<>
48-
inline Square to_sq<std::string_view>(std::string_view const& sq)
49+
template <>
50+
inline Square to_sq<std::string_view>(std::string_view const &sq)
4951
{
50-
return static_cast<Square>((sq[0] - 97) + ((sq[1] - 49) * 8));
52+
return static_cast<Square>((sq[0] - 97) + ((sq[1] - 49) * 8));
5153
}
5254

5355
inline Direction operator+(Direction l, Direction r)
5456
{
55-
return static_cast<Direction>(to_int(l) + to_int(r));
57+
return static_cast<Direction>(to_int(l) + to_int(r));
5658
}
5759

5860
inline Square operator-(Square l, Direction r)
5961
{
60-
return static_cast<Square>(to_int(l) - to_int(r));
62+
return static_cast<Square>(to_int(l) - to_int(r));
6163
}
6264

6365
inline Square flip_square(const Square sq)
6466
{
65-
return to_sq(sq ^ 56);
67+
return to_sq(sq ^ 56);
6668
}
6769

68-
inline Square operator++(Square& sq, int)
70+
inline Square operator++(Square &sq, int)
6971
{
70-
Square temp = sq;
71-
sq = to_sq(sq + 1);
72-
return temp;
72+
Square temp = sq;
73+
sq = to_sq(sq + 1);
74+
return temp;
7375
}
7476

7577
inline Square operator+(Square sq, Direction dir)
7678
{
77-
return to_sq(sq + to_int(dir));
79+
return to_sq(sq + to_int(dir));
7880
}
7981

80-
inline Square& operator+=(Square& sq, int inc)
82+
inline Square &operator+=(Square &sq, int inc)
8183
{
82-
sq = to_sq(sq + inc);
83-
return sq;
84+
sq = to_sq(sq + inc);
85+
return sq;
8486
}
8587

8688
inline bool is_ok(const Square sq)
8789
{
88-
return sq >= Square::A1 && sq <= Square::H8;
90+
return sq >= Square::A1 && sq <= Square::H8;
8991
}
9092
bool is_valid_sq(std::string_view);
91-
std::ostream& operator<<(std::ostream&, const Square);
93+
std::ostream &operator<<(std::ostream &, const Square);

Bit-Genie/src/attacks.h

Lines changed: 105 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -23,122 +23,112 @@ namespace Attacks
2323
{
2424
// Initializes magic bitboard arrays. Should be called before
2525
// using Attacks::bishop / Attacks::rook
26-
inline void init()
27-
{
28-
initmagicmoves();
29-
}
30-
31-
// Return a bitboard of the knight attacks for a
32-
// knight situated on the given square
33-
inline uint64_t knight(Square sq)
34-
{
35-
return BitMask::knight_attacks[sq];
36-
}
37-
38-
// Return a bitboard of the king attacks for a
39-
// king situated on the given square
40-
inline uint64_t king(Square sq)
41-
{
42-
return BitMask::king_attacks[sq];
43-
}
44-
45-
// Return a bitboard of the bishop attacks for a
46-
// bishop situated on the given square
47-
// Diagonal and anti-diagonal attacks with respect to the current occupancy
48-
inline uint64_t bishop(Square sq, uint64_t occ)
49-
{
50-
return Bmagic(sq, occ);
51-
}
52-
53-
// Return a bitboard of the rook attacks for a
54-
// rook situated on the given square
55-
// Vertical (file) and horizontal(rank) attacks with respect to the current occupancy
56-
inline uint64_t rook(Square sq, uint64_t occ)
57-
{
58-
return Rmagic(sq, occ);
59-
}
60-
61-
// Return a bitboard of the queen attacks for a
62-
// queen situated on the given square
63-
64-
// Diagonal and anti-diagonal attacks with respect to the current occupancy
65-
// Vertical (file) and horizontal(rank) attacks with respect to the current occupancy
66-
inline uint64_t queen(Square sq, uint64_t occ)
67-
{
68-
return Qmagic(sq, occ);
69-
}
70-
71-
// Check whether the given square is directly attacked by any of the given color's
72-
//pieces in the position.
73-
inline bool square_attacked(Position const& position, Square sq, Color enemy, uint64_t occupancy)
74-
{
75-
assert(is_ok(sq));
76-
uint64_t pawns = position.pieces.get_piece_bb<Pawn>(enemy);
77-
uint64_t knights = position.pieces.get_piece_bb<Knight>(enemy);
78-
uint64_t bishops = position.pieces.get_piece_bb<Bishop>(enemy);
79-
uint64_t rooks = position.pieces.get_piece_bb<Rook>(enemy);
80-
uint64_t queens = position.pieces.get_piece_bb<Queen>(enemy);
81-
uint64_t kings = position.pieces.get_piece_bb<King>(enemy);
82-
83-
bishops |= queens;
84-
rooks |= queens;
85-
86-
87-
return (BitMask::pawn_attacks[!enemy][sq] & pawns)
88-
|| (bishop(sq, occupancy) & bishops)
89-
|| (rook(sq, occupancy) & rooks)
90-
|| (knight(sq) & knights)
91-
|| (king(sq) & kings);
92-
}
26+
inline void init()
27+
{
28+
initmagicmoves();
29+
}
30+
31+
// Return a bitboard of the knight attacks for a
32+
// knight situated on the given square
33+
inline uint64_t knight(Square sq)
34+
{
35+
return BitMask::knight_attacks[sq];
36+
}
37+
38+
// Return a bitboard of the king attacks for a
39+
// king situated on the given square
40+
inline uint64_t king(Square sq)
41+
{
42+
return BitMask::king_attacks[sq];
43+
}
44+
45+
// Return a bitboard of the bishop attacks for a
46+
// bishop situated on the given square
47+
// Diagonal and anti-diagonal attacks with respect to the current occupancy
48+
inline uint64_t bishop(Square sq, uint64_t occ)
49+
{
50+
return Bmagic(sq, occ);
51+
}
52+
53+
// Return a bitboard of the rook attacks for a
54+
// rook situated on the given square
55+
// Vertical (file) and horizontal(rank) attacks with respect to the current occupancy
56+
inline uint64_t rook(Square sq, uint64_t occ)
57+
{
58+
return Rmagic(sq, occ);
59+
}
60+
61+
// Return a bitboard of the queen attacks for a
62+
// queen situated on the given square
63+
64+
// Diagonal and anti-diagonal attacks with respect to the current occupancy
65+
// Vertical (file) and horizontal(rank) attacks with respect to the current occupancy
66+
inline uint64_t queen(Square sq, uint64_t occ)
67+
{
68+
return Qmagic(sq, occ);
69+
}
70+
71+
// Check whether the given square is directly attacked by any of the given color's
72+
//pieces in the position.
73+
inline bool square_attacked(Position const &position, Square sq, Color enemy, uint64_t occupancy)
74+
{
75+
assert(is_ok(sq));
76+
uint64_t pawns = position.pieces.get_piece_bb<Pawn>(enemy);
77+
uint64_t knights = position.pieces.get_piece_bb<Knight>(enemy);
78+
uint64_t bishops = position.pieces.get_piece_bb<Bishop>(enemy);
79+
uint64_t rooks = position.pieces.get_piece_bb<Rook>(enemy);
80+
uint64_t queens = position.pieces.get_piece_bb<Queen>(enemy);
81+
uint64_t kings = position.pieces.get_piece_bb<King>(enemy);
82+
83+
bishops |= queens;
84+
rooks |= queens;
85+
86+
return (BitMask::pawn_attacks[!enemy][sq] & pawns) || (bishop(sq, occupancy) & bishops) || (rook(sq, occupancy) & rooks) || (knight(sq) & knights) || (king(sq) & kings);
87+
}
9388

9489
// Return a bitboard of all the attackers to the given square, both black and white pieces
95-
// are included.
96-
inline uint64_t attackers_to_sq(Position const& position, Square sq)
97-
{
98-
uint64_t occ = position.total_occupancy();
99-
uint64_t pawn_mask = (BitMask::pawn_attacks[White][sq] & position.pieces.bitboards[Pawn] & position.pieces.colors[Black]);
100-
pawn_mask |= (BitMask::pawn_attacks[Black][sq] & position.pieces.bitboards[Pawn] & position.pieces.colors[White]);
101-
102-
uint64_t bishops = position.pieces.bitboards[Bishop] | position.pieces.bitboards[Queen];
103-
uint64_t rooks = position.pieces.bitboards[Rook] | position.pieces.bitboards[Queen];
104-
105-
106-
return (pawn_mask)
107-
| (knight(sq) & position.pieces.bitboards[Knight])
108-
| (king(sq) & position.pieces.bitboards[King])
109-
| (bishop(sq, occ) & bishops)
110-
| (rook(sq, occ) & rooks);
111-
}
112-
113-
inline bool square_attacked(Position const& position, Square sq, Color enemy)
114-
{
115-
return square_attacked(position, sq, enemy, position.total_occupancy());
116-
}
117-
118-
// Check for the piece and generate (no pawns)
119-
inline uint64_t generate(PieceType piece, Square sq, uint64_t occ)
120-
{
121-
switch (piece)
122-
{
123-
case Knight:
124-
return knight(sq);
125-
126-
case Bishop:
127-
return bishop(sq, occ);
128-
129-
case Rook:
130-
return rook(sq, occ);
131-
132-
case Queen:
133-
return queen(sq, occ);
134-
135-
case King:
136-
return king(sq);
137-
138-
default:
139-
throw std::invalid_argument("Invalid argument in generate");
140-
return 0;
141-
}
142-
}
90+
// are included.
91+
inline uint64_t attackers_to_sq(Position const &position, Square sq)
92+
{
93+
uint64_t occ = position.total_occupancy();
94+
uint64_t pawn_mask = (BitMask::pawn_attacks[White][sq] & position.pieces.bitboards[Pawn] & position.pieces.colors[Black]);
95+
pawn_mask |= (BitMask::pawn_attacks[Black][sq] & position.pieces.bitboards[Pawn] & position.pieces.colors[White]);
96+
97+
uint64_t bishops = position.pieces.bitboards[Bishop] | position.pieces.bitboards[Queen];
98+
uint64_t rooks = position.pieces.bitboards[Rook] | position.pieces.bitboards[Queen];
99+
100+
return (pawn_mask) | (knight(sq) & position.pieces.bitboards[Knight]) | (king(sq) & position.pieces.bitboards[King]) | (bishop(sq, occ) & bishops) | (rook(sq, occ) & rooks);
101+
}
102+
103+
inline bool square_attacked(Position const &position, Square sq, Color enemy)
104+
{
105+
return square_attacked(position, sq, enemy, position.total_occupancy());
106+
}
107+
108+
// Check for the piece and generate (no pawns)
109+
inline uint64_t generate(PieceType piece, Square sq, uint64_t occ)
110+
{
111+
switch (piece)
112+
{
113+
case Knight:
114+
return knight(sq);
115+
116+
case Bishop:
117+
return bishop(sq, occ);
118+
119+
case Rook:
120+
return rook(sq, occ);
121+
122+
case Queen:
123+
return queen(sq, occ);
124+
125+
case King:
126+
return king(sq);
127+
128+
default:
129+
throw std::invalid_argument("Invalid argument in generate");
130+
return 0;
131+
}
132+
}
143133

144134
}

0 commit comments

Comments
 (0)