summaryrefslogtreecommitdiff
path: root/src/bitboard.c
diff options
context:
space:
mode:
authorAargh Rai <aargh.rai+git@gmail.com>2026-02-24 22:49:43 +0530
committerAargh Rai <aargh.rai+git@gmail.com>2026-02-24 22:49:43 +0530
commit63fa6656749d1cdb6a54a001950048a9660f0d73 (patch)
tree39c7e0586c2ad761d65f56bdfd6c96f6bbfdccb9 /src/bitboard.c
parent9cd36deffadc4f5ab83f08c2999407b31354027e (diff)
pawn forward movement works?
Diffstat (limited to 'src/bitboard.c')
-rw-r--r--src/bitboard.c64
1 files changed, 55 insertions, 9 deletions
diff --git a/src/bitboard.c b/src/bitboard.c
index 05b370b..ce994c5 100644
--- a/src/bitboard.c
+++ b/src/bitboard.c
@@ -1,25 +1,71 @@
#include "bitboard.h"
+#include <stdio.h>
+#include <inttypes.h>
+#include <assert.h>
-position starting_position() {
- return (position) {
+position_t position_starting() {
+ return (position_t) {
.bitboards = {
+ 16ULL,
+ 8ULL,
+ 129ULL,
+ 36ULL,
+ 66ULL,
+ 65280ULL,
1152921504606846976ULL,
576460752303423488ULL,
9295429630892703744ULL,
- 4755801206503243776ULL,
2594073385365405696ULL,
+ 4755801206503243776ULL,
71776119061217280ULL,
- 16ULL,
- 8ULL,
- 129ULL,
- 66ULL,
- 36ULL,
- 65280ULL
},
.castling =
(1 << WHITE_SHORT_CASTLE) |
(1 << WHITE_LONG_CASTLE) |
(1 << BLACK_SHORT_CASTLE) |
(1 << BLACK_LONG_CASTLE),
+ .turn = WHITE_TURN,
};
}
+
+void assert_valid_position(position_t position) {
+ assert(position.castling <=
+ (
+ (1 << WHITE_SHORT_CASTLE) |
+ (1 << WHITE_LONG_CASTLE) |
+ (1 << BLACK_SHORT_CASTLE) |
+ (1 << BLACK_LONG_CASTLE)
+ )
+ );
+ assert(position.turn == WHITE_TURN || position.turn == BLACK_TURN);
+}
+
+bitboard_t whites(position_t position) {
+ return
+ position.bitboards[WHITE_KING] |
+ position.bitboards[WHITE_QUEEN] |
+ position.bitboards[WHITE_ROOK] |
+ position.bitboards[WHITE_BISHOP] |
+ position.bitboards[WHITE_KNIGHT] |
+ position.bitboards[WHITE_PAWN];
+}
+
+bitboard_t blacks(position_t position) {
+ return
+ position.bitboards[BLACK_KING] |
+ position.bitboards[BLACK_QUEEN] |
+ position.bitboards[BLACK_ROOK] |
+ position.bitboards[BLACK_BISHOP] |
+ position.bitboards[BLACK_KNIGHT] |
+ position.bitboards[BLACK_PAWN];
+}
+
+void print_bitboard(bitboard_t bitboard) {
+ printf("Bitboard(%" PRIu64 ")\n", bitboard);
+ for (int i = 7; i >= 0; i--) {
+ for (int j = 0; j < 8; j++) {
+ printf("%" PRIu64 "", (bitboard >> (8 * i + j)) & 1);
+ }
+ printf("\n");
+ }
+}