aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-03-29 14:11:42 +0300
committereug-vs <eugene@eug-vs.xyz>2022-03-29 14:11:42 +0300
commit1ce760e73a10da34ef1360f64202d4d03492f859 (patch)
tree602fbc54d257895dcfeb559700cd5623f53ec37e
parentb77e0ab18c4531c45394951bccc8d5d5b8181ee2 (diff)
downloadcarcassonne-engine-c-1ce760e73a10da34ef1360f64202d4d03492f859.tar.gz
feat: allow read/write board to file
-rw-r--r--src/board.h7
-rw-r--r--src/main.c24
2 files changed, 21 insertions, 10 deletions
diff --git a/src/board.h b/src/board.h
index ad46098..a2e6793 100644
--- a/src/board.h
+++ b/src/board.h
@@ -1,9 +1,8 @@
-#define BOARD_WIDTH 5
+#define BOARD_WIDTH 7
#define BOARD_ROW_BYTES ((BOARD_WIDTH * 2) + 1)
#define BOARD_BYTES BOARD_ROW_BYTES * BOARD_ROW_BYTES
char EMPTY = ' ';
-char FORBIDDEN = ' ';
int neighbor_increments[] = {
- BOARD_ROW_BYTES,
@@ -17,6 +16,10 @@ void initialize_board(char* board);
void print_board(char* board);
+void write_board(char* board, char* filename);
+
+void read_board(char* board, char* filename);
+
// Moves
int is_allowed_placement(char* tile, int index, char* board);
diff --git a/src/main.c b/src/main.c
index 65567b8..d74335c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -101,25 +101,33 @@ int evaluate_structure(int index, char* board, char* structures) {
return value;
}
+void write_board(char* board, char* filename) {
+ FILE* file = fopen(filename, "w");
+ fprintf(file, "%s\n", board);
+ fclose(file);
+}
+
+void read_board(char* board, char* filename) {
+ FILE* file = fopen(filename, "r");
+ fgets(board, BOARD_BYTES, file);
+ fclose(file);
+}
+
int main() {
char board[BOARD_BYTES];
char structures[BOARD_BYTES];
initialize_board(board);
- initialize_board(structures);
+ place_tile("RFRCR", translate_coordinate(24), board);
+ write_board(board, "board.txt");
- place_tile("RFRFR", translate_coordinate(0), board);
- place_tile("RCCRR", translate_coordinate(1), board);
- place_tile("CFFCC", translate_coordinate(2), board);
- place_tile("RRFRF", translate_coordinate(3), board);
+ initialize_board(structures);
create_structure_mask(board, structures);
-
print_board(board);
printf("\n\n");
print_board(structures);
- evaluate_structure(translate_coordinate(0), board, structures);
-
+ evaluate_structure(translate_coordinate(24), board, structures);
return 0;
}