From edb7409e7f12bfa3d749f31b3706deade63b5ddc Mon Sep 17 00:00:00 2001 From: Ole Morud Date: Mon, 1 Apr 2024 01:33:47 +0200 Subject: [PATCH] asd --- src/board.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/map.h | 10 ++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/board.h diff --git a/src/board.h b/src/board.h new file mode 100644 index 0000000..756b31e --- /dev/null +++ b/src/board.h @@ -0,0 +1,56 @@ + +#pragma once + +#include +#include +#include +#include + +typedef uint64_t bitmap_t; +typedef uint_fast8_t index_t; +typedef int_fast8_t piece_t; + +enum tile_info { + EMPTY = 0b0000, + KING = 0b0001, + QUEEN = 0b0010, + ROOK = 0b0011, + BISHOP = 0b0100, + KNIGHT = 0b0101, + PAWN = 0b0110, + COLOR_BIT = 0b1000, + + PIECE_UNKNOWN=-1 +}; + +struct board { + static_assert(sizeof(bitmap_t) == 64/8, "bitmap_t must be 64 bits long"); + bitmap_t pieces[4]; // 4 bits correspond to 1 tile +}; + +static inline bitmap_t bit(index_t i) +{ + return 0b111UL << 3*i; +} + +static bool is_white(piece_t piece) +{ + return piece % 2 == 0; +} + +static bool is_black(piece_t piece) +{ + return piece % 2 == 1; +} + +static piece_t piece_at(struct board* board, index_t tile) +{ + for (size_t i = 0; i < sizeof board->pieces / board->pieces[0]; i++) { + if (bit(tile) & board->pieces[i]) { + return i; + } + } + return PIECE_UNKNOWN; +} + + diff --git a/src/map.h b/src/map.h index 1fff232..a91f5a5 100644 --- a/src/map.h +++ b/src/map.h @@ -1,5 +1,15 @@ +enum chess_piece { + EMPTY = 0, + KING = 1, + QUEEN = 2, + ROOK = 3, + BISHOP = 4, + KNIGHT = 5, + PAWN = 6, + PIECE_COUNT, +}; static bool board_equals(