From 58fdd68496e369558dcba53361563dadae7e37a6 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Mon, 11 Apr 2022 19:18:53 +0300 Subject: feat: return meeples home on structure completion --- src/structure.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/structure.c') 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; -- cgit v1.2.3