diff options
author | Raúl Benencia <rul@kalgan.cc> | 2015-03-28 12:19:59 -0300 |
---|---|---|
committer | Raúl Benencia <rul@kalgan.cc> | 2015-03-28 12:19:59 -0300 |
commit | a7f2a09bce2d94c236469843d0815803edbf3574 (patch) | |
tree | 1421a28f40236d0152834777afdf868939fc20fb | |
parent | 68c1e827b0beb78d7327114c3e6c31802cf1f45e (diff) |
add setters and getters for the board squares using Coord
-rw-r--r-- | include/board.h | 3 | ||||
-rw-r--r-- | lib/board.c | 26 |
2 files changed, 29 insertions, 0 deletions
diff --git a/include/board.h b/include/board.h index 0cfdb70..5fd714a 100644 --- a/include/board.h +++ b/include/board.h @@ -6,4 +6,7 @@ Board board_init(); int board_delete(Board); +Square board_get_square(Board, Coord); +Board board_set_square(Board, Coord, Square); + #endif diff --git a/lib/board.c b/lib/board.c index 134cfa8..c4a4f2d 100644 --- a/lib/board.c +++ b/lib/board.c @@ -84,6 +84,16 @@ static Board _initial_setup(Board b) { return _setup_pieces(_setup_colors(b)); } +static short _from_col(char col) { + // col is a character between 'a' and 'h' + return col - 'a'; +} + +static short _from_row(char row) { + // row is an ASCII digit between '1' and '8' + return row - '1'; +} + Board board_init() { int i, j; @@ -112,3 +122,19 @@ int board_delete(Board b) { return 0; } + +Square board_get_square(Board b, Coord c) { + short x = _from_col(c.col); + short y = _from_row(c.row); + + return b[x][y]; +} + +Board board_set_square(Board b, Coord c, Square s) { + short x = _from_col(c.col); + short y = _from_row(c.row); + + b[x][y] = s; + + return b; +} |