summaryrefslogtreecommitdiff
path: root/src/search/moves.c
blob: c0cdb4efbb66ba53fa9689d2fdd12a74a13196c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "../search.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++;
}