From 1ce760e73a10da34ef1360f64202d4d03492f859 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Tue, 29 Mar 2022 14:11:42 +0300 Subject: feat: allow read/write board to file --- src/board.h | 7 +++++-- src/main.c | 24 ++++++++++++++++-------- 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; } -- cgit v1.2.3