summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
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