diff options
| -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; +}  | 
