summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/board.h5
-rw-r--r--lib/board.c18
2 files changed, 23 insertions, 0 deletions
diff --git a/include/board.h b/include/board.h
index 5fd714a..de6234d 100644
--- a/include/board.h
+++ b/include/board.h
@@ -9,4 +9,9 @@ int board_delete(Board);
Square board_get_square(Board, Coord);
Board board_set_square(Board, Coord, Square);
+/*
+ * Receives and applies a Move on the Board
+ */
+Board board_make_move(Board b, Move m);
+
#endif
diff --git a/lib/board.c b/lib/board.c
index 774bfd5..a53c356 100644
--- a/lib/board.c
+++ b/lib/board.c
@@ -3,6 +3,7 @@
#include "board.h"
#include "coordinate.h"
+#include "move.h"
#include "piece.h"
static Board _setup_colors(Board b) {
@@ -148,3 +149,20 @@ Board board_set_square(Board b, Coord c, Square s) {
return b;
}
+
+Board board_make_move(Board b, Move m) {
+ /* Get piece from orig square coordinate */
+ Square s = board_get_square(b, move_get_orig(m));
+ Piece *p = s.piece;
+
+ /* Empty orig square */
+ s.piece = NULL;
+ board_set_square(b, move_get_orig(m), s);
+
+ /* Set piece on dest square */
+ s = board_get_square(b, move_get_dest(m));
+ s.piece = p;
+ board_set_square(b, move_get_dest(m), s);
+
+ return b;
+}
nihil fit ex nihilo