summaryrefslogtreecommitdiff
path: root/src/engine/moves/vec.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/moves/vec.c')
-rw-r--r--src/engine/moves/vec.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/engine/moves/vec.c b/src/engine/moves/vec.c
new file mode 100644
index 0000000..6192706
--- /dev/null
+++ b/src/engine/moves/vec.c
@@ -0,0 +1,51 @@
+#include "../moves.h"
+#include <assert.h>
+#include <stdlib.h>
+
+void position_make_move(position_t* position, move_t* move) {
+
+}
+
+moves_t moves_init() {
+ return moves_init_wcapacity(16);
+}
+
+moves_t moves_init_wcapacity(u32 capacity) {
+ move_t* moves = malloc(capacity * sizeof(*moves));
+ return (moves_t) {
+ .moves = moves,
+ .capacity = capacity,
+ .length = 0,
+ };
+}
+
+moves_t moves_empty() {
+ 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) {
+ assert(moves->moves != 0);
+ assert(from != to);
+
+ 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++;
+}