summaryrefslogtreecommitdiff
path: root/src/bitboard.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bitboard.c')
-rw-r--r--src/bitboard.c46
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--) {