diff options
Diffstat (limited to 'src/bitboard.c')
| -rw-r--r-- | src/bitboard.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/bitboard.c b/src/bitboard.c index 1c3ed28..71e66a5 100644 --- a/src/bitboard.c +++ b/src/bitboard.c @@ -73,6 +73,22 @@ char get_piece_char_from_sqr(position_t position, size_t square) { return ' '; } +int find_piece_on_square(position_t* p, int square) { + if ((p->bitboards[WHITE_KING] >> square) & 1) return WHITE_KING; + if ((p->bitboards[WHITE_QUEEN] >> square) & 1) return WHITE_QUEEN; + if ((p->bitboards[WHITE_ROOK] >> square) & 1) return WHITE_ROOK; + if ((p->bitboards[WHITE_BISHOP] >> square) & 1) return WHITE_BISHOP; + if ((p->bitboards[WHITE_KNIGHT] >> square) & 1) return WHITE_KNIGHT; + if ((p->bitboards[WHITE_PAWN] >> square) & 1) return WHITE_PAWN; + if ((p->bitboards[BLACK_KING] >> square) & 1) return BLACK_KING; + if ((p->bitboards[BLACK_QUEEN] >> square) & 1) return BLACK_QUEEN; + if ((p->bitboards[BLACK_ROOK] >> square) & 1) return BLACK_ROOK; + if ((p->bitboards[BLACK_BISHOP] >> square) & 1) return BLACK_BISHOP; + if ((p->bitboards[BLACK_KNIGHT] >> square) & 1) return BLACK_KNIGHT; + if ((p->bitboards[BLACK_PAWN] >> square) & 1) return BLACK_PAWN; + assert(0 && "Failed to find the piece on the square"); +} + void print_position(position_t position) { for (int i = 8; i > 0; i--) { printf("+---+---+---+---+---+---+---+---+\n"); |
