diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-03-29 03:21:13 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-03-29 03:21:13 +0300 |
commit | 2c803562d153b53a2c1f983af5e8ee68422cbfdb (patch) | |
tree | f43abf3aa3c3cab3423e095121c8bc8077e83bc2 | |
parent | 7315e36cd66b9f2626dbb3d89f7e0ea8b9fcafd0 (diff) | |
download | carcassonne-engine-c-2c803562d153b53a2c1f983af5e8ee68422cbfdb.tar.gz |
feat: add structure traversal
-rw-r--r-- | src/board.h | 5 | ||||
-rw-r--r-- | src/main.c | 28 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/board.h b/src/board.h index f5d2da3..924c226 100644 --- a/src/board.h +++ b/src/board.h @@ -23,3 +23,8 @@ int is_allowed_placement(char* tile, int position, char* board); int is_center_position(int position); int place_tile(char* tile, int position, char* board); + +// Structures +void traverse_structure(char id, int byte, char* board, char* structures); + +void create_structure_mask(char* board, char* structures); @@ -49,16 +49,42 @@ int place_tile(char* tile, int position, char* board) { return 1; } +void traverse_structure(char id, int byte, char* board, char* structures) { + structures[byte] = id; + for (int i = 0; i < 4; i++) { + int new_byte = byte + neighbor_increments[i]; + if (board[new_byte] == board[byte] && structures[new_byte] == EMPTY) { + traverse_structure(id, new_byte, board, structures); + } + } +} + +void create_structure_mask(char* board, char* structures) { + char structure_id = '1'; + for (int i = 0; i < BOARD_BYTES; i++) { + if (structures[i] == EMPTY && board[i] != EMPTY && board[i] != 'F') { + traverse_structure(structure_id, i, board, structures); + structure_id += 1; + } + } +} + int main() { char board[BOARD_BYTES]; + char structures[BOARD_BYTES]; + initialize_board(board); + initialize_board(structures); place_tile("RFRFR", 6, board); place_tile("RCCRR", 8, board); place_tile("RRFRF", 18, board); - place_tile("CFFFC", 16, board); + place_tile("CFFCC", 16, board); + create_structure_mask(board, structures); print_board(board); + printf("\n\n"); + print_board(structures); return 0; } |