summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAargh Rai <aargh.rai+git@gmail.com>2026-05-26 14:22:55 +0530
committerAargh Rai <aargh.rai+git@gmail.com>2026-05-26 14:22:55 +0530
commitad32fc54b2869c0bbedcabea6274b0e3732ec893 (patch)
treee4229b03c3f5ee4beea73db3d6614136ff3165e7
parent7e021a821b49306eaa8b0688e4b91d2db25d4878 (diff)
bishop & queen
-rw-r--r--src/main.c11
-rw-r--r--src/search.c1
-rw-r--r--src/search.h13
-rw-r--r--src/search/bishop_moves.c47
-rw-r--r--src/search/queen_moves.c21
-rw-r--r--src/search/rook_moves.c47
6 files changed, 99 insertions, 41 deletions
diff --git a/src/main.c b/src/main.c
index b5d57eb..a929a54 100644
--- a/src/main.c
+++ b/src/main.c
@@ -7,9 +7,9 @@ int main() {
position_t position = position_starting();
position.bitboards[WHITE_KING] = 16ULL;
-position.bitboards[WHITE_QUEEN] = 8ULL;
+position.bitboards[WHITE_QUEEN] = 268435456ULL;
position.bitboards[WHITE_ROOK] = 16777344ULL;
-position.bitboards[WHITE_BISHOP] = 36ULL;
+position.bitboards[WHITE_BISHOP] = 67108896ULL;
position.bitboards[WHITE_KNIGHT] = 66ULL;
position.bitboards[WHITE_PAWN] = 65280ULL;
position.bitboards[BLACK_KING] = 1152921504606846976ULL;
@@ -19,11 +19,16 @@ position.bitboards[BLACK_BISHOP] = 2594073385365405696ULL;
position.bitboards[BLACK_KNIGHT] = 4611687117939015680ULL;
position.bitboards[BLACK_PAWN] = 71776119061217280ULL;
- get_rook_moves(&moves, position);
+ get_queen_moves(&moves, position);
+
+ bitboard_t b = 0;
for (int i = 0; i < moves.length; i++) {
+ b |= (bitboard_t)1 << moves.moves[i].to;
printf("%d %d | ", (moves.moves[i].from), (moves.moves[i].to));
}
+
+ print_bitboard(b);
return 0;
}
diff --git a/src/search.c b/src/search.c
index 03b5eb5..e389087 100644
--- a/src/search.c
+++ b/src/search.c
@@ -4,3 +4,4 @@
#include "search/pawn_moves.c"
#include "search/rook_moves.c"
#include "search/bishop_moves.c"
+#include "search/queen_moves.c"
diff --git a/src/search.h b/src/search.h
index 14f876f..5648e99 100644
--- a/src/search.h
+++ b/src/search.h
@@ -29,4 +29,17 @@ void get_rook_moves(moves_t* moves, position_t position);
void get_bishop_moves(moves_t* moves, position_t position);
void get_queen_moves(moves_t* moves, position_t position);
+void __forloop_rook_moves_gen(
+ moves_t* moves,
+ bitboard_t friendly_type,
+ bitboard_t friendly_pieces,
+ bitboard_t enemy_pieces
+);
+void __forloop_bishop_moves_gen(
+ moves_t* moves,
+ bitboard_t friendly_type,
+ bitboard_t friendly_pieces,
+ bitboard_t enemy_pieces
+);
+
#endif // !SEARCH_H
diff --git a/src/search/bishop_moves.c b/src/search/bishop_moves.c
index 10b46e5..29fe3a6 100644
--- a/src/search/bishop_moves.c
+++ b/src/search/bishop_moves.c
@@ -1,24 +1,14 @@
#include "search.h"
-void get_bishop_moves(moves_t* moves, position_t position) {
- assert_valid_position(position);
-
- bitboard_t friendly_rooks;
- bitboard_t friendly_pieces;
- bitboard_t enemy_pieces;
- if (position.turn == WHITE_TURN) {
- friendly_pieces = whites(position);
- enemy_pieces = blacks(position);
- friendly_rooks = position.bitboards[WHITE_ROOK];
- } else {
- friendly_pieces = blacks(position);
- enemy_pieces = whites(position);
- friendly_rooks = position.bitboards[BLACK_ROOK];
- }
-
- while (friendly_rooks) {
- int from = __builtin_ctzll(friendly_rooks);
- friendly_rooks &= friendly_rooks - 1;
+void __forloop_bishop_moves_gen(
+ moves_t* moves,
+ bitboard_t friendly_type,
+ bitboard_t friendly_pieces,
+ bitboard_t enemy_pieces
+) {
+ while (friendly_type) {
+ int from = __builtin_ctzll(friendly_type);
+ friendly_type &= friendly_type - 1;
int og_rank = from / 8; // range: [0, 7]
int og_file = from % 8; // range: [0, 7]
@@ -61,3 +51,22 @@ void get_bishop_moves(moves_t* moves, position_t position) {
}
}
}
+
+void get_bishop_moves(moves_t* moves, position_t position) {
+ assert_valid_position(position);
+
+ bitboard_t friendly_bishops;
+ bitboard_t friendly_pieces;
+ bitboard_t enemy_pieces;
+ if (position.turn == WHITE_TURN) {
+ friendly_pieces = whites(position);
+ enemy_pieces = blacks(position);
+ friendly_bishops = position.bitboards[WHITE_BISHOP];
+ } else {
+ friendly_pieces = blacks(position);
+ enemy_pieces = whites(position);
+ friendly_bishops = position.bitboards[BLACK_BISHOP];
+ }
+
+ __forloop_bishop_moves_gen(moves, friendly_bishops, friendly_pieces, enemy_pieces);
+}
diff --git a/src/search/queen_moves.c b/src/search/queen_moves.c
new file mode 100644
index 0000000..f1e773a
--- /dev/null
+++ b/src/search/queen_moves.c
@@ -0,0 +1,21 @@
+#include "search.h"
+
+void get_queen_moves(moves_t* moves, position_t position) {
+ assert_valid_position(position);
+
+ bitboard_t friendly_queens;
+ bitboard_t friendly_pieces;
+ bitboard_t enemy_pieces;
+ if (position.turn == WHITE_TURN) {
+ friendly_pieces = whites(position);
+ enemy_pieces = blacks(position);
+ friendly_queens = position.bitboards[WHITE_QUEEN];
+ } else {
+ friendly_pieces = blacks(position);
+ enemy_pieces = whites(position);
+ friendly_queens = position.bitboards[BLACK_QUEEN];
+ }
+
+ __forloop_rook_moves_gen(moves, friendly_queens, friendly_pieces, enemy_pieces);
+ __forloop_bishop_moves_gen(moves, friendly_queens, friendly_pieces, enemy_pieces);
+}
diff --git a/src/search/rook_moves.c b/src/search/rook_moves.c
index 749210e..778c6a1 100644
--- a/src/search/rook_moves.c
+++ b/src/search/rook_moves.c
@@ -1,24 +1,14 @@
#include "search.h"
-void get_rook_moves(moves_t* moves, position_t position) {
- assert_valid_position(position);
-
- bitboard_t friendly_rooks;
- bitboard_t friendly_pieces;
- bitboard_t enemy_pieces;
- if (position.turn == WHITE_TURN) {
- friendly_pieces = whites(position);
- enemy_pieces = blacks(position);
- friendly_rooks = position.bitboards[WHITE_ROOK];
- } else {
- friendly_pieces = blacks(position);
- enemy_pieces = whites(position);
- friendly_rooks = position.bitboards[BLACK_ROOK];
- }
-
- while (friendly_rooks) {
- int from = __builtin_ctzll(friendly_rooks);
- friendly_rooks &= friendly_rooks - 1;
+void __forloop_rook_moves_gen(
+ moves_t* moves,
+ bitboard_t friendly_type,
+ bitboard_t friendly_pieces,
+ bitboard_t enemy_pieces
+) {
+ while (friendly_type) {
+ int from = __builtin_ctzll(friendly_type);
+ friendly_type &= friendly_type - 1;
int og_rank = from / 8; // range: [0, 7]
int og_file = from % 8; // range: [0, 7]
@@ -61,3 +51,22 @@ void get_rook_moves(moves_t* moves, position_t position) {
}
}
}
+
+void get_rook_moves(moves_t* moves, position_t position) {
+ assert_valid_position(position);
+
+ bitboard_t friendly_rooks;
+ bitboard_t friendly_pieces;
+ bitboard_t enemy_pieces;
+ if (position.turn == WHITE_TURN) {
+ friendly_pieces = whites(position);
+ enemy_pieces = blacks(position);
+ friendly_rooks = position.bitboards[WHITE_ROOK];
+ } else {
+ friendly_pieces = blacks(position);
+ enemy_pieces = whites(position);
+ friendly_rooks = position.bitboards[BLACK_ROOK];
+ }
+
+ __forloop_rook_moves_gen(moves, friendly_rooks, friendly_pieces, enemy_pieces);
+}