I want to try a new form of code golf here. Similar to bonuses, not all parts of the challenge have to be completed, but each answer has to implement a subset of certain size (and there is a core that every answer has to implement). So besides the golfing this challenge also involves choosing a set of features that go well together.
The Rules
Kingdom Builder is a board game, played on a (pointy-top) hex grid. The board is made up of four (randomised) quadrants, each of which has 10x10 hex cells (so a full board will be 20x20). For the purposes of this challenge, each hex cell contains either water (W
), mountain (M
) a town (T
), a castle (C
) or is empty (.
). So a quadrant could look like
. . W . . . . . . .
. M W W . . . . . .
. M . . W . . . T .
M M . W . . . . . .
. . M . W W . . . .
. . . . . W W W W W
. T . . . . . . . .
. . W . . C . . . .
. . W W . . . . M .
. . . . . . . M M .
The second row will always be offset to the right from the first row. Players 1
to 4
can place up to 40 settlements each on empty cells (following some rules which we will ignore for this challenge). A possible board at the end of the game is the following:
3 3 W . . . 4 . 4 . . 2 W . 4 . . 4 . 4
3 M W W . 1 1 . . 4 2 W . 3 C 4 4 . . 4
3 M 2 2 W 1 1 1 T 3 2 W 4 3 . 1 4 . 4 .
M M . W 2 2 . . . 2 2 W 3 . 1 1 1 . . .
. 4 M . W W 2 2 2 2 W W 3 . 1 4 . T . .
. . . . . W W W W W . 3 C 1 . . 2 2 2 2
. T 1 1 1 1 . . 2 . . 4 . . . 2 2 M M M
4 . W 4 . C 4 4 . . . . . . 2 M M M M M
. 4 W W . . . 4 M . . W . W . 2 2 2 M M
. . . . . . . M M . . W W . . . . 2 M .
. . . 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 . 1
M 3 3 . . . . . . . . 4 . T 2 . 2 4 1 .
M M . C . 4 . 4 . . . . . 1 2 4 2 1 1 .
M . . 1 . 4 . . . . M M 1 2 . . 2 1 . .
. . . W 1 1 4 1 1 . . . 1 2 . . 2 W W W
. . 1 1 W 1 T . 1 1 1 1 T . . 2 W . 4 .
. 1 1 W . 3 3 . . . . . . . . 2 W 4 C 3
C 1 3 3 3 . 3 . 4 . 4 . 4 . . 2 W 1 1 M
4 3 3 4 . M 4 3 . . . . . . . 2 W . . .
. . . 4 . M M 3 . . 4 4 . 4 . 2 W W . .
We'll label the quadrants like
1 2
3 4
Your task will be to score such a board. There is one core score which is always used, and 8 optional scores, 3 of which are chosen for each game.† In the following, I'll describe all 9 scores and use the above setup as an example for how many points each player would get.
† There are 10 scores in the actual game, but I'll leave out two because no one wants to golf them.
The core score. A player gets 3 points for each C
astle they have a settlement next to. Example scores: 18, 0, 15, 12.
The optional scores.
A player gets 1 point for each horizontal row on which they have at least one settlement.
Example scores: 14, 20, 12, 16.
For each player, find the horizontal row on which they most of their settlements (pick any in case of a tie). A player gets 2 points for each settlement on that row.
Example scores: 14 (row 16), 8 (row 4, 5 or 6), 28 (row 11), 10 (row 1).
A player gets 1 point for each settlement that is build next to
W
ater.Example scores: 13, 21, 10, 5.
A player gets 1 point for each settlement next to a
M
ountain.Example scores: 4, 12, 8, 4.
Count the settlements of each player in each quadrant. Per quadrant, the players with the largest number of settlements get 12 points each, the players with the second-largest number of settlements get 6 points each.
Example scores: 18 (6 + 0 + 6 + 6), 36 (12 + 12 + 0 + 12), 12 (0 + 0 + 12 + 0), 18 (12 + 6 + 0 + 0).
For each player determine the quadrant in which they have the least number of settlements. A player gets 3 points for each settlement in that quadrant.
Example scores: 18 (Quadrant 2), 0 (Quadrant 3), 15 (Quadrant 1 or 2), 27 (Quadrant 3).
A player gets 1 point for each connected group of settlements.
Example scores: 7, 5, 6, 29.
A player gets 1 point for every 2 settlements in the player's largest group of connected settlements.
Example scores: 4, 10, 8, 2.
The Challenge
As in the game you will choose 3 of the optional scores, and score a given board based on the core score and those three scores. Your code should produce a list of 4 scores. There is one restriction on the choice though: I have grouped the scores into 3 groups, and you are to implement one of each group:
- Implement one of 1 and 2.
- Implement one of 3, 4, 5 and 6.
- Implement one of 7 and 8.
You may write a program or function, taking input via STDIN, command-line argument, prompt or function parameter. You may return the result or print it to STDOUT.
You may choose any convenient 1D or 2D list/string format for the input. You may not use a graph with full adjacency information. Here is some good reading on hex grids if you need inspiration.
Your output may also be in any convenient, unambiguous list or string format.
This is code golf, so the shortest answer (in bytes) wins.
Further Assumptions
You may assume that ...
- ... each player has at least 1 settlement and there are no more than 40 settlements of each player.
- ... each quadrant contains either one town and two castles, or two towns and one castle.
- ... towns and castles are far enough apart, such that no settlement can be adjacent to two of them.
Test Cases
Still using the above board, here are the individual scores for all possible choices of scoring mechanisms:
Chosen Scores Total Player Scores
1 3 7 52 46 43 62
1 3 8 49 51 45 35
1 4 7 43 37 41 61
1 4 8 40 42 43 34
1 5 7 57 61 45 75
1 5 8 54 66 47 48
1 6 7 57 25 48 84
1 6 8 54 30 50 57
2 3 7 52 34 59 56
2 3 8 49 39 61 29
2 4 7 43 25 57 55
2 4 8 40 30 59 28
2 5 7 57 49 61 69
2 5 8 54 54 63 42
2 6 7 57 13 64 78
2 6 8 54 18 66 51