diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..71ae7f3 --- /dev/null +++ b/src/main.c @@ -0,0 +1,71 @@ +#include "board.h" + + +int check_allowed_tile(char* tile, int position, char* board) { + for (int i = 0; i < 4; i++) { + int index = (position * TILE_SIZE + i) + direction_increments[i]; + printf("Checking board index %i\n", index); + // TODO: board should have sentinel row/column + if (index >= 0 && index < BOARD_BYTES) { + char neighboring_edge = board[index]; + if (neighboring_edge > 0 && neighboring_edge != tile[i] && neighboring_edge != '_') { + printf("Failed on edge %i (%c). Neighboring edge is %c\n", i, tile[i], neighboring_edge); + return 0; + } + } + } + return 1; +} + +void place_tile(char* tile, int position, char* board) { + if (!check_allowed_tile(tile, position, board)) { + printf("Could not place the tile!"); + return; + } + for (int i = 0; i < TILE_SIZE; i++) { + board[position * TILE_SIZE + i] = tile[i]; + } +} + +void print_board(char* board) { + for (int row = 0; row < BOARD_WIDTH; row++) { + for (int tile = 0; tile < BOARD_WIDTH; tile++) { + printf("_%c_", board[TILE_SIZE * (row * BOARD_WIDTH + tile)]); + } + printf("\n"); + for (int tile = 0; tile < BOARD_WIDTH; tile++) { + printf( + "%c%c%c", + board[TILE_SIZE * (row * BOARD_WIDTH + tile) + 3], + board[TILE_SIZE * (row * BOARD_WIDTH + tile) + 4], + board[TILE_SIZE * (row * BOARD_WIDTH + tile) + 1] + ); + } + printf("\n"); + for (int tile = 0; tile < BOARD_WIDTH; tile++) { + printf("_%c_", board[TILE_SIZE * (row * BOARD_WIDTH + tile) + 2]); + } + printf("\n"); + } +} + +void initialize_board(char* board) { + for (int i = 0; i < BOARD_BYTES; i++) { + board[i] = '_'; + } +} + +int main() { + // Board + char board[BOARD_BYTES]; + initialize_board(board); + + place_tile("ABCDE", 7, board); + place_tile("FGHBJ", 8, board); + place_tile("FGHGJ", 9, board); + place_tile("FGAGJ", 1, board); + + print_board(board); + + return 0; +} |