From a7f2a09bce2d94c236469843d0815803edbf3574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Sat, 28 Mar 2015 12:19:59 -0300 Subject: add setters and getters for the board squares using Coord --- lib/board.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'lib') 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; +} -- cgit v1.2.3