summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaúl Benencia <rul@kalgan.cc>2015-03-31 15:33:24 -0300
committerRaúl Benencia <rul@kalgan.cc>2015-03-31 15:33:24 -0300
commit9ad93043d107926b48196b9c9ba9588ded5f4b64 (patch)
tree6d344646bb390c3d7212fcb4ac7f26bfc555c2a8
parentc81bc656c6226883b7e3cae5269532123c7dea76 (diff)
board make move
-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