summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRaúl Benencia <rul@kalgan.cc>2015-03-28 12:19:59 -0300
committerRaúl Benencia <rul@kalgan.cc>2015-03-28 12:19:59 -0300
commita7f2a09bce2d94c236469843d0815803edbf3574 (patch)
tree1421a28f40236d0152834777afdf868939fc20fb /lib
parent68c1e827b0beb78d7327114c3e6c31802cf1f45e (diff)
add setters and getters for the board squares using Coord
Diffstat (limited to 'lib')
-rw-r--r--lib/board.c26
1 files changed, 26 insertions, 0 deletions
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;
+}
nihil fit ex nihilo