diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-04-10 22:32:36 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-04-10 22:32:36 +0300 |
commit | cecf821c9526ba2e93288f4f0ff354b2cb98c452 (patch) | |
tree | 7bf2275ee933d8a1cfbc8b5f6188af5c64df6001 /src/board.c | |
parent | 5f583e476f3f711a581f417319670ee401a716c4 (diff) | |
download | carcassonne-engine-c-cecf821c9526ba2e93288f4f0ff354b2cb98c452.tar.gz |
feat: highlight player-controlled areas
Diffstat (limited to 'src/board.c')
-rw-r--r-- | src/board.c | 35 |
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; +} |