aboutsummaryrefslogtreecommitdiff
path: root/src/board.c
blob: fe798f73b4aaf502fd33229038ef7bf4e35ca58b (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
#include "board.h"
#include "utils.h"

void
board_init (struct board *board, uint32_t rows, uint32_t cols)
{
  bitarray_init (&board->bitarray, rows*cols);
  board->rows = rows;
  board->cols = cols;
}

void
board_set (struct board *board, int32_t row, int32_t col, bool value)
{
  ASSERT (board);

  row = MOD (row, (int32_t) board->rows);
  col = MOD (col, (int32_t) board->cols);
  bitarray_set (&board->bitarray, row*board->cols + col, value);
}

bool
board_get (struct board *board, int32_t row, int32_t col)
{
  ASSERT (board);

  row = MOD (row, (int32_t) board->rows);
  col = MOD (col, (int32_t) board->cols);
  return bitarray_get (&board->bitarray, row*board->cols + col);
}

void
board_free (struct board *board)
{
  bitarray_free (&board->bitarray);
}