diff options
Diffstat (limited to 'src/meeple.c')
-rw-r--r-- | src/meeple.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/meeple.c b/src/meeple.c new file mode 100644 index 0000000..b9df686 --- /dev/null +++ b/src/meeple.c @@ -0,0 +1,36 @@ +#include "meeple.h" + +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; +} |