aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-04-10 20:51:51 +0300
committereug-vs <eugene@eug-vs.xyz>2022-04-10 20:51:51 +0300
commit6c88febbe0cff8960bc6f2e0bcdfc89777a5f72b (patch)
tree3c6062bc33b4affcc9f9f765e621e71f4493eda7
parent8c3124e919d9f8e7118fb05f4341c12e54b68c72 (diff)
downloadcarcassonne-engine-c-6c88febbe0cff8960bc6f2e0bcdfc89777a5f72b.tar.gz
feat: support separator (+) feature
-rw-r--r--src/board.c12
-rw-r--r--src/board.h3
-rw-r--r--src/main.c4
3 files changed, 13 insertions, 6 deletions
diff --git a/src/board.c b/src/board.c
index 92420ed..cc16e06 100644
--- a/src/board.c
+++ b/src/board.c
@@ -58,11 +58,10 @@ void traverse_structure(int group, int index, BoardUnit* board) {
int new_unit = index + NEIGHBOR_INCREMENTS[i];
if (board[new_unit].feature == board[index].feature && board[new_unit].structure_group == 0) {
traverse_structure(group, new_unit, board);
- }
- else if (board[new_unit].feature == '*' && board[new_unit].structure_group != board[index].structure_group) {
+ } else if (board[new_unit].feature == ANY && board[new_unit].structure_group != board[index].structure_group) {
board[new_unit].feature = board[index].feature;
traverse_structure(group, new_unit, board);
- board[new_unit].feature = '*';
+ board[new_unit].feature = ANY;
}
}
}
@@ -72,7 +71,12 @@ void refresh_structure_groups(BoardUnit* board) {
int structure_group = 1;
for (int i = 0; i < BOARD_UNITS; i++) {
- if (board[i].structure_group == 0 && board[i].feature != EMPTY && board[i].feature != 'F') {
+ if (
+ board[i].structure_group == 0
+ && board[i].feature != EMPTY
+ && board[i].feature != SEPARATOR
+ && board[i].feature != 'F'
+ ) {
traverse_structure(structure_group, i, board);
structure_group += 1;
}
diff --git a/src/board.h b/src/board.h
index 4a8c4e8..4785871 100644
--- a/src/board.h
+++ b/src/board.h
@@ -5,6 +5,9 @@
/* constants */
const char EMPTY = ' ';
+const char ANY = '*';
+const char SEPARATOR = '+';
+
const int NEIGHBOR_INCREMENTS[] = { -BOARD_ROW_UNITS, 1, BOARD_ROW_UNITS, -1 };
/* structs */
diff --git a/src/main.c b/src/main.c
index a538675..ab5409e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -8,7 +8,7 @@ void draw_board(BoardUnit* board, WINDOW* win) {
for (int row = 0; row < BOARD_ROW_UNITS; row++) {
for (int i = 0; i < BOARD_ROW_UNITS; i++) {
int index = BOARD_ROW_UNITS * row + i;
- if (board[index].feature == EMPTY && is_center_index(index)) waddch(win, '*');
+ if (board[index].feature == EMPTY && is_center_index(index)) waddch(win, '.');
else waddch(win, board[index].feature | COLOR_PAIR(board[index].structure_group % 6));
}
}
@@ -47,7 +47,7 @@ int main() {
place_tile(tile, translate_coordinate(BOARD_WIDTH * BOARD_WIDTH / 2), board, 1);
Tile tileset[5] = {
- { "RRRR", 'R', 0 },
+ { "RRRR", '+', 0 },
{ "FCCC", 'C', 0 },
{ "FFFC", 'C', 0 },
{ "CCRR", '*', 0 },