diff options
| author | 2026-11-08 02:11:35 +0000 | |
|---|---|---|
| committer | 2026-11-08 02:11:35 +0000 | |
| commit | 08fcd58893b5ea754ebddbf63b2745dde34d4830 (patch) | |
| tree | 6e121100ec1aceccd2a6032c90bf11d1dd16ef8f /src/board.c | |
| download | lab-01-master.tar.gz | |
Diffstat (limited to 'src/board.c')
| -rw-r--r-- | src/board.c | 36 |
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 | |||
| 4 | void | ||
| 5 | board_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 | |||
| 12 | void | ||
| 13 | board_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 | |||
| 22 | bool | ||
| 23 | board_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 | |||
| 32 | void | ||
| 33 | board_free (struct board *board) | ||
| 34 | { | ||
| 35 | bitarray_free (&board->bitarray); | ||
| 36 | } | ||
