aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-04-11 19:18:53 +0300
committereug-vs <eugene@eug-vs.xyz>2022-04-17 14:57:28 +0300
commit58fdd68496e369558dcba53361563dadae7e37a6 (patch)
tree7a17f51a64658886b2ebb8f7723e1a6dcbe0bc4e
parent0333b7fa851e222c4a4d183ef9ae6d6dab7559cb (diff)
downloadcarcassonne-engine-c-58fdd68496e369558dcba53361563dadae7e37a6.tar.gz
feat: return meeples home on structure completionHEADmaster
-rw-r--r--src/main.c1
-rw-r--r--src/structure.c30
-rw-r--r--src/structure.h1
3 files changed, 32 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 3454c61..faad695 100644
--- a/src/main.c
+++ b/src/main.c
@@ -89,6 +89,7 @@ int main() {
else wprintw(messages_win, "Could not place tile %s (%c) at position %i\n", tile.edges, tile.center, position);
refresh_structure_groups(board);
+ complete_structures(board, available_meeples);
refresh_meeple_map(board, meeple_map);
/* meeple placement */
diff --git a/src/structure.c b/src/structure.c
index a3039e7..3a26d23 100644
--- a/src/structure.c
+++ b/src/structure.c
@@ -31,6 +31,36 @@ void refresh_structure_groups(BoardUnit* board) {
}
}
+void complete_structures(BoardUnit* board, int* available_meeples) {
+ int completed_structures[MAX_STRUCTURES];
+ for (int i = 0; i < MAX_STRUCTURES; i++) completed_structures[i] = 1;
+
+ /* zero-out incomplete structures */
+ for (int i = 0; i < BOARD_WIDTH * BOARD_WIDTH; i++) {
+ int index = translate_coordinate(i);
+ if (board[index].feature == EMPTY) {
+ for (int k = 0; k < 4; k++) {
+ int test_index = index + 2 * NEIGHBOR_INCREMENTS[k];
+ if (test_index < BOARD_UNITS) {
+ completed_structures[board[test_index].structure_group] = 0;
+ }
+ }
+ }
+ }
+
+ /* return meeples into player pools */
+ for (int structure_group = 0; structure_group < MAX_STRUCTURES; structure_group++) {
+ if (completed_structures[structure_group] == 1) {
+ for (int i = 0; i < BOARD_UNITS; i++) {
+ if (board[i].structure_group == structure_group && board[i].meeple) {
+ available_meeples[board[i].meeple - 1]++;
+ board[i].meeple = 0;
+ }
+ }
+ }
+ }
+}
+
int evaluate_structure(int index, BoardUnit* board) {
int value = 0;
diff --git a/src/structure.h b/src/structure.h
index 420c705..75566cc 100644
--- a/src/structure.h
+++ b/src/structure.h
@@ -6,3 +6,4 @@
void traverse_structure(int group, int index, BoardUnit* board);
void refresh_structure_groups(BoardUnit* board);
int evaluate_structure(int index, BoardUnit* board);
+void complete_structures(BoardUnit* board, int* available_meeples);