aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-03-29 03:21:13 +0300
committereug-vs <eugene@eug-vs.xyz>2022-03-29 03:21:13 +0300
commit2c803562d153b53a2c1f983af5e8ee68422cbfdb (patch)
treef43abf3aa3c3cab3423e095121c8bc8077e83bc2
parent7315e36cd66b9f2626dbb3d89f7e0ea8b9fcafd0 (diff)
downloadcarcassonne-engine-c-2c803562d153b53a2c1f983af5e8ee68422cbfdb.tar.gz
feat: add structure traversal
-rw-r--r--src/board.h5
-rw-r--r--src/main.c28
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);
diff --git a/src/main.c b/src/main.c
index a872cab..f80e4f7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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;
}