aboutsummaryrefslogtreecommitdiff
path: root/src/board.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/board.c')
-rw-r--r--src/board.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/board.c b/src/board.c
new file mode 100644
index 0000000..fe798f7
--- /dev/null
+++ b/src/board.c
@@ -0,0 +1,36 @@
1#include "board.h"
2#include "utils.h"
3
4void
5board_init (struct board *board, uint32_t rows, uint32_t cols)
6{
7 bitarray_init (&board->bitarray, rows*cols);
8 board->rows = rows;
9 board->cols = cols;
10}
11
12void
13board_set (struct board *board, int32_t row, int32_t col, bool value)
14{
15 ASSERT (board);
16
17 row = MOD (row, (int32_t) board->rows);
18 col = MOD (col, (int32_t) board->cols);
19 bitarray_set (&board->bitarray, row*board->cols + col, value);
20}
21
22bool
23board_get (struct board *board, int32_t row, int32_t col)
24{
25 ASSERT (board);
26
27 row = MOD (row, (int32_t) board->rows);
28 col = MOD (col, (int32_t) board->cols);
29 return bitarray_get (&board->bitarray, row*board->cols + col);
30}
31
32void
33board_free (struct board *board)
34{
35 bitarray_free (&board->bitarray);
36}