summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2022-01-21 17:20:17 -0500
committerRobby Zambito <contact@robbyzambito.me>2022-01-21 17:20:17 -0500
commitf1a4b5757f0d20739270b22726ebf8442b13cb50 (patch)
tree93e170ddebc79cf5a41777fc040797bc6dfa5d85 /include
parent3a85be307b6240525f032b9fad5114bdf172bdc1 (diff)
Fleshed out Scheme primitives
* Moved board specific functions from othello.h to new othello_board.h * Removed unused function pointer for player moves * Added prototypes in headers for SCM functions, including scm_get_current_player, * Made get_winner accept a board and current player. This is useful for predictions to see if some move would make the other player a winner. * get_winner also writes the players scores to provided pointers.
Diffstat (limited to 'include')
-rw-r--r--include/othello.h26
-rw-r--r--include/othello_board.h43
-rw-r--r--include/othello_move.h8
3 files changed, 59 insertions, 18 deletions
diff --git a/include/othello.h b/include/othello.h
index 40a36c4..e46c13e 100644
--- a/include/othello.h
+++ b/include/othello.h
@@ -20,6 +20,7 @@
#pragma once
+#include <libguile.h>
#include <stdbool.h>
#include <stdio.h>
@@ -34,30 +35,19 @@ struct move {
int col;
};
-// Function pointers for each players move function
-extern struct move (*player_one_get_move)(void);
-extern struct move (*player_two_get_move)(void);
-
-// Set a board to a new game state.
-void initialize_board(void);
-
-// Copy the specified board. It must be freed by the caller.
-enum player_color **copy_board(enum player_color **board);
-
-// Free the specified board.
-void free_board(enum player_color **board);
// Plays a game to completion, starting with board.
enum player_color game_loop(char *player_one_strategy,
char *player_two_strategy);
-// Prints the current state of the board, including coordinates in the margins.
-void print_board(enum player_color **board);
-
// Returns the color of the player whose turn it is.
enum player_color get_current_player(void);
+SCM scm_get_current_player(void);
-// Returns the current board.
-enum player_color **get_board(void);
+enum player_color scm_player_to_c_player(SCM player);
-enum player_color get_winner(void);
+enum player_color get_winner(enum player_color **board,
+ enum player_color current_player,
+ int *white_score,
+ int *black_score);
+SCM scm_get_winner(SCM board, SCM current_player);
diff --git a/include/othello_board.h b/include/othello_board.h
new file mode 100644
index 0000000..8852ad0
--- /dev/null
+++ b/include/othello_board.h
@@ -0,0 +1,43 @@
+/* This file is a part of othello-ai-guile-c
+ *
+ * Copyright (C) 2021 Robby Zambito
+ *
+ * othello-ai-guile-c is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * othello-ai-guile-c is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#define _GNU_SOURCE
+
+#pragma once
+
+#include "othello.h"
+
+// Set a board to a new game state.
+void initialize_board(void);
+
+// Copy the specified board. It must be freed by the caller.
+enum player_color **copy_board(enum player_color **board);
+
+// Free the specified board.
+void free_board(enum player_color **board);
+
+// Prints the current state of the board, including coordinates in the margins.
+void print_board(enum player_color **board);
+
+// Returns the current board.
+enum player_color **get_board(void);
+SCM scm_get_board(void);
+
+SCM scm_board_from_c_board(enum player_color **board);
+
+enum player_color **scm_board_to_c_board(SCM board);
diff --git a/include/othello_move.h b/include/othello_move.h
index 281cb9b..2e2974b 100644
--- a/include/othello_move.h
+++ b/include/othello_move.h
@@ -30,6 +30,9 @@ struct move get_scm_move(char *strategy_path);
bool is_valid_move(enum player_color **board,
const enum player_color current_player,
const struct move move);
+SCM scm_is_valid_move(SCM board, SCM current_player, SCM move);
+
+SCM scm_valid_moves(SCM scm_board, SCM player);
// True if current_player has any valid moves.
// Otherwise false.
@@ -39,3 +42,8 @@ bool has_valid_moves(enum player_color **board,
/* Returns true if the move was valid */
bool apply_move(enum player_color **board, enum player_color current_player,
struct move move);
+// Does not actually modify the current board state. Returns a new board with
+// the move applied. If the move was not valid, an empty list (nil) is returned.
+SCM scm_apply_move(SCM move, SCM board, SCM current_player);
+
+struct move scm_move_to_c_move(SCM scm_move);