aboutsummaryrefslogtreecommitdiff
path: root/src/board.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/board.c')
-rw-r--r--src/board.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/board.c b/src/board.c
index 0e66f16..95b8738 100644
--- a/src/board.c
+++ b/src/board.c
@@ -111,3 +111,38 @@ int evaluate_structure(int index, BoardUnit* board) {
return value;
}
+
+void refresh_meeple_map(BoardUnit* board, int* meeple_map) {
+ for (int i = 0; i < MAX_STRUCTURES * PLAYERS; i++) meeple_map[i] = 0;
+
+ for (int i = 0; i < BOARD_UNITS; i++) {
+ if (board[i].meeple) {
+ meeple_map[board[i].structure_group * PLAYERS + (board[i].meeple - 1)]++;
+ }
+ }
+}
+
+int is_allowed_meeple(int meeple, int index, BoardUnit* board, int* meeple_map) {
+ if (board[index].meeple
+ || board[index].feature == 'F'
+ || board[index].feature == ANY
+ || board[index].feature == SEPARATOR
+ ) return 0;
+
+ int dominator = get_structure_dominator(board[index].structure_group, meeple_map);
+ return dominator == meeple || dominator == 0;
+}
+
+int get_structure_dominator(int structure_group, int* meeple_map) {
+ int dominator = 0;
+ int dominator_meeples = 0;
+
+ for (int player = 0; player < PLAYERS; player++) {
+ int meeples = meeple_map[structure_group * PLAYERS + player];
+ if (meeples > dominator_meeples) {
+ dominator_meeples = meeples;
+ dominator = player + 1;
+ }
+ }
+ return dominator;
+}