summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2022-01-25 22:07:12 -0500
committerRobby Zambito <contact@robbyzambito.me>2022-01-25 22:07:12 -0500
commit2206201ed53f3d3c51a2687772fdb8c908bb11e2 (patch)
tree7ffab422327d9d86ccba8fff9d212cdf33ef16d5
parent8522d9cbe81dd982bab1bdebec89b5b4e1c66ec3 (diff)
Added move constructor and extract row and colHEADmaster
-rw-r--r--README.md12
-rw-r--r--include/othello_move.h4
-rw-r--r--src/move.c15
3 files changed, 31 insertions, 0 deletions
diff --git a/README.md b/README.md
index 14effa8..1a4ee8c 100644
--- a/README.md
+++ b/README.md
@@ -21,6 +21,18 @@ Function: (other-player)
this operation is likely to be common, it is provided as a primitive for
convenience.
+Function: (move row col)
+
+ Constructs a new move object with the provided row and col.
+
+Function: (move->row m)
+
+ Selects the row from move `m`.
+
+Function: (move->col m)
+
+ Selects the col from move `m`.
+
Function: (valid-move? move #:optional board player)
Returns #t or #f based on if the provided move is valid or not on a board by a player.
diff --git a/include/othello_move.h b/include/othello_move.h
index 6b58bbe..50fe899 100644
--- a/include/othello_move.h
+++ b/include/othello_move.h
@@ -53,3 +53,7 @@ SCM scm_apply_move(SCM move, SCM board, SCM current_player);
SCM scm_get_num_flipped_by_move(SCM move, SCM board, SCM current_player);
struct move scm_move_to_c_move(SCM scm_move);
+
+SCM scm_new_move(SCM row, SCM col);
+SCM scm_move_to_row(SCM move);
+SCM scm_move_to_col(SCM move);
diff --git a/src/move.c b/src/move.c
index 9f8df44..9151c8d 100644
--- a/src/move.c
+++ b/src/move.c
@@ -402,6 +402,18 @@ SCM scm_valid_moves(SCM scm_board, SCM player) {
return result;
}
+SCM scm_new_move(SCM row, SCM col) {
+ return scm_cons(row, col);
+}
+
+SCM scm_move_to_row(SCM move) {
+ return scm_car(move);
+}
+
+SCM scm_move_to_col(SCM move) {
+ return scm_cdr(move);
+}
+
struct move get_scm_move(char *strategy_path) {
// Initialize move to an invalid move.
struct move move = {-1, -1};
@@ -411,6 +423,9 @@ struct move get_scm_move(char *strategy_path) {
scm_c_define_gsubr("get-board", 0, 0, 0, scm_get_board);
scm_c_define_gsubr("current-player", 0, 0, 0, scm_get_current_player);
scm_c_define_gsubr("other-player", 0, 0, 0, scm_get_other_player);
+ scm_c_define_gsubr("move", 2, 0, 0, scm_new_move);
+ scm_c_define_gsubr("move->row", 1, 0, 0, scm_move_to_row);
+ scm_c_define_gsubr("move->col", 1, 0, 0, scm_move_to_col);
scm_c_define_gsubr("valid-move?", 1, 2, 0, scm_is_valid_move);
scm_c_define_gsubr("valid-moves", 0, 2, 0, scm_valid_moves);
scm_c_define_gsubr("apply-move", 1, 2, 0, scm_apply_move);