diff options
| author | Aargh Rai <aargh.rai+git@gmail.com> | 2026-07-16 23:03:28 +0530 |
|---|---|---|
| committer | Aargh Rai <aargh.rai+git@gmail.com> | 2026-07-18 14:04:14 +0530 |
| commit | c34b4c1b036058b2906556850cc4ded6ececcf89 (patch) | |
| tree | 0da79a6578ed85123abbc02141f5d1d989bb3aa3 /src/bitboard.c | |
| parent | f1c6f59ae02a9d9db50171a69032dc2409a0e6c6 (diff) | |
fixed pawn gen, onto the next perf
Diffstat (limited to 'src/bitboard.c')
| -rw-r--r-- | src/bitboard.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/bitboard.c b/src/bitboard.c index 9df3855..1c3ed28 100644 --- a/src/bitboard.c +++ b/src/bitboard.c @@ -47,6 +47,52 @@ bool check_valid_position(position_t position) { return true; } +char get_piece_char(size_t piece_type) { + assert(piece_type < PIECE_TYPE_COUNT); + if (WHITE_KING == piece_type) return 'K'; + if (WHITE_QUEEN == piece_type) return 'Q'; + if (WHITE_ROOK == piece_type) return 'R'; + if (WHITE_BISHOP == piece_type) return 'B'; + if (WHITE_KNIGHT == piece_type) return 'N'; + if (WHITE_PAWN == piece_type) return 'P'; + if (BLACK_KING == piece_type) return 'k'; + if (BLACK_QUEEN == piece_type) return 'q'; + if (BLACK_ROOK == piece_type) return 'r'; + if (BLACK_BISHOP == piece_type) return 'b'; + if (BLACK_KNIGHT == piece_type) return 'n'; + if (BLACK_PAWN == piece_type) return 'p'; +} + +char get_piece_char_from_sqr(position_t position, size_t square) { + assert(square < 64); + for (int i = 0; i < PIECE_TYPE_COUNT; i++) { + if ((position.bitboards[i] >> square) & (bitboard_t)1) { + return get_piece_char(i); + } + } + return ' '; +} + +void print_position(position_t position) { + for (int i = 8; i > 0; i--) { + printf("+---+---+---+---+---+---+---+---+\n"); + printf( + "| %c | %c | %c | %c | %c | %c | %c | %c | %d\n", + get_piece_char_from_sqr(position, 8 * i - 8), + get_piece_char_from_sqr(position, 8 * i - 7), + get_piece_char_from_sqr(position, 8 * i - 6), + get_piece_char_from_sqr(position, 8 * i - 5), + get_piece_char_from_sqr(position, 8 * i - 4), + get_piece_char_from_sqr(position, 8 * i - 3), + get_piece_char_from_sqr(position, 8 * i - 2), + get_piece_char_from_sqr(position, 8 * i - 1), + i + ); + } + printf("+---+---+---+---+---+---+---+---+\n"); + printf(" a b c d e f g h\n"); +} + void print_bitboard(bitboard_t bitboard) { printf("Bitboard(%" PRIu64 ")\n", bitboard); for (int i = 7; i >= 0; i--) { |
