summaryrefslogtreecommitdiff
path: root/src/search/moves.c
diff options
context:
space:
mode:
authorAargh Rai <aargh.rai+git@gmail.com>2026-02-20 17:04:46 +0530
committerAargh Rai <aargh.rai+git@gmail.com>2026-02-20 17:04:46 +0530
commit9cd36deffadc4f5ab83f08c2999407b31354027e (patch)
treee298606fb938ac6aea26c408c3cd29ddf4b17f9c /src/search/moves.c
parentfd57b964e50a4cb3385976a473bc287d682bcbdb (diff)
some moves dynamic array setup & starting position
Diffstat (limited to 'src/search/moves.c')
-rw-r--r--src/search/moves.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/search/moves.c b/src/search/moves.c
new file mode 100644
index 0000000..57797e7
--- /dev/null
+++ b/src/search/moves.c
@@ -0,0 +1,44 @@
+#include "../search.h"
+#include <stdlib.h>
+
+moves_t init_moves() {
+ return init_moves_wcapacity(16);
+}
+
+moves_t init_moves_wcapacity(u32 capacity) {
+ move_t* moves = malloc(capacity * sizeof(*moves));
+ return (moves_t) {
+ .moves = moves,
+ .capacity = capacity,
+ .length = 0,
+ };
+}
+
+moves_t empty_moves() {
+ return (moves_t) {
+ .moves = 0,
+ .capacity = 0,
+ .length = 0,
+ };
+}
+
+int min(int a, int b) {
+ if (a > b) return b;
+ return a;
+}
+
+void add_move(moves_t* moves, square_t from, square_t to) {
+ if (moves->moves == 0) return;
+ if (moves->length + 1 >= moves->capacity) {
+ moves->capacity += min(32, moves->capacity);
+ moves->moves = realloc(
+ moves->moves,
+ moves->capacity * sizeof(*moves->moves)
+ );
+ }
+ moves->moves[moves->length] = (move_t){
+ .from = from,
+ .to = to
+ };
+ moves->length++;
+}