Skip to content

Commit a7e0004

Browse files
authored
King legal moves implementation (#75)
* removed castling rights to the empty fen position * implemented king legal moves
1 parent c0aa039 commit a7e0004

File tree

3 files changed

+500
-1
lines changed

3 files changed

+500
-1
lines changed

include/bitbishop/board.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Board {
6767
return {"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"};
6868
}
6969

70-
[[nodiscard]] static Board Empty() noexcept { return {"8/8/8/8/8/8/8/8 w KQkq - 0 1"}; }
70+
[[nodiscard]] static Board Empty() noexcept { return {"8/8/8/8/8/8/8/8 b - - 0 1"}; }
7171

7272
/**
7373
* @brief Retrieves the piece on a given square.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <bitbishop/board.hpp>
2+
#include <bitbishop/color.hpp>
3+
#include <bitbishop/lookups/king_attacks.hpp>
4+
#include <bitbishop/move.hpp>
5+
#include <utility>
6+
#include <vector>
7+
8+
void generate_legal_king_moves(std::vector<Move>& moves, const Board& board, Color us, Square king_sq,
9+
const Bitboard& enemy_attacks, const Bitboard& check_mask) {
10+
const Bitboard own = board.friendly(us);
11+
const Bitboard enemy = board.enemy(us);
12+
13+
Bitboard candidates = Lookups::KING_ATTACKS[king_sq.value()];
14+
15+
candidates &= ~own;
16+
candidates &= ~enemy_attacks;
17+
candidates &= check_mask;
18+
19+
for (Square to : candidates) {
20+
const bool is_capture = enemy.test(to);
21+
moves.emplace_back(king_sq, to, std::nullopt, is_capture, false, false);
22+
}
23+
}

0 commit comments

Comments
 (0)