diff options
| author | Aargh Rai <aargh.rai+git@gmail.com> | 2026-02-25 23:46:07 +0530 |
|---|---|---|
| committer | Aargh Rai <aargh.rai+git@gmail.com> | 2026-02-25 23:46:07 +0530 |
| commit | 22c0d29724c2b054d8b9f9ed2373103d412f02b3 (patch) | |
| tree | 83be782ad10dc0568c825de7d82c20ff16db6af5 /src/search | |
| parent | b2f0457deaf8fd7c336e5370212df9202d6f3eeb (diff) | |
king DONE
Diffstat (limited to 'src/search')
| -rw-r--r-- | src/search/king_moves.c | 37 | ||||
| -rw-r--r-- | src/search/knight_moves.c | 2 | ||||
| -rw-r--r-- | src/search/pawn_moves.c | 2 |
3 files changed, 39 insertions, 2 deletions
diff --git a/src/search/king_moves.c b/src/search/king_moves.c new file mode 100644 index 0000000..631b7f0 --- /dev/null +++ b/src/search/king_moves.c @@ -0,0 +1,37 @@ +#include "../search.h" + +void get_king_moves(moves_t* moves, position_t position) { + assert_valid_position(position); + + bitboard_t friendly_king; + int king_square; + bitboard_t friendly_pieces; + if (position.turn == WHITE_TURN) { + friendly_pieces = whites(position); + friendly_king = position.bitboards[WHITE_KING]; + } else { + friendly_pieces = blacks(position); + friendly_king = position.bitboards[BLACK_KING]; + } + king_square = __builtin_ctzll(friendly_king); + + bitboard_t movement; + if (king_square >= 10) { + movement = 920078ULL << (king_square - 10); + } else { + movement = 920078ULL >> -(king_square - 10); + } + if (friendly_king & BITMASK_FILE_A) { + movement &= BITMASK_FILE_A | BITMASK_FILE_B; + } else if (friendly_king & BITMASK_FILE_H) { + movement &= BITMASK_FILE_G | BITMASK_FILE_H; + } + + movement &= ~friendly_pieces; + print_bitboard(movement); + while (movement) { + int to = __builtin_ctzll(movement); + movement &= movement - 1; + add_move(moves, king_square, to); + } +} diff --git a/src/search/knight_moves.c b/src/search/knight_moves.c index 55f8eec..34cf66a 100644 --- a/src/search/knight_moves.c +++ b/src/search/knight_moves.c @@ -75,6 +75,8 @@ bitboard_t knight_moves[64] = { }; void get_knight_moves(moves_t* moves, position_t position) { + assert_valid_position(position); + bitboard_t friendly_knights; bitboard_t friendly_pieces; if (position.turn == WHITE_TURN) { diff --git a/src/search/pawn_moves.c b/src/search/pawn_moves.c index 5d94571..fbf2bad 100644 --- a/src/search/pawn_moves.c +++ b/src/search/pawn_moves.c @@ -1,6 +1,4 @@ #include "../search.h" -#include <assert.h> -#include <inttypes.h> bitboard_t get_white_pawn_forwardmoves(moves_t* moves, position_t position) { bitboard_t enemy_bitboard = blacks(position); |
