Introduction
Nine Mens's Morris (also called Mills) is a board game for two players which is played on the following board (image taken from the linked Wikipedia-page):
Each player has 9 men, colored black and white. The concrete rules are not important for this challenge, but check out the Wikipedia-page if you are interested.
The Challenge
Given a grid as input, which represents a certain boardstate, output the total mill count m
with 0<=m<=8
.
Three men of the same color form a mill when they are in a straight row of connected points. b2
to f2
is not a mill since the men are of different color. Also d2
to d5
would not form a mill since the three points have to be connected.
The board in the image above contains two mills for example. One from f2
to f6
and one from e3
to e5
.
Input
The board is represented as a 2D grid with 24 points which are connected as shown in the example image above. The example uses letters from a-g
for the columns and numbers from 1-7
for the rows, but you may choose any reasonable input format as long as it maps 24 unique coordinates to one of the following states:
- Empty
- Taken by black
- Taken by white
The concrete repersentation is up to you you are not restricted to "b" or "w" for the colors.
Besides this, your input may not contain any additional information.
Additional notes
- You don't have to map the points by any kind of values. If you want to take the input as a 2D array, that's fine as well. But keep in mind that not all points in there are used and that you have to consider the connections between them.
- The input might be empty, in which case you have to output zero (empty board -> no mills).
- Since each player has 9 men, the input will never contain more than 18 taken points.
- You may leave out emtpy points in the input and therefore only input points which are taken.
- The input may be ordered in any way. You can't rely on a specific order.
- You may assume that the input will always be valid. This means that there won't be more than 9 men of each color and that each point will be unique.
Rules
- Make clear which input format you use in your solution. Providing an example run of your program is hightly encouraged.
- Function or full program allowed.
- Default rules for input/output.
- Standard loopholes apply.
- This is code-golf, so lowest byte-count wins. Tiebreaker is earlier submission.
Test cases
The input format here is a list of tuples with the coordinates as in the example above as first element and the state of the point second element. A point taken by white is marked as "w" and a point taken by black as "b". All other points are left out and are empty.
[("a4","w"),("b2","b"),("b4","b"),("c4","b"),("d1","w"),("d2","w"),("e3","w"),("e4","w"),("e5","w"),("f2","b"),("f4","b"),("f6","b"),("g4","w")] -> 2 [("a1","b"),("a4","b"),("a7","b"),("b4","b"),("c4","b"),("d3","w"),("d2","w"),("d1","w")] -> 3 [] -> 0 [("b4", "b"),("a4",b"),("c4",w")] -> 0 [("b4", "b"),("a4",b"),("c4",b")] -> 1 [("a1", "b"),("a4", "b"),("a7", "b"),("b2", "b"),("b4", "b"),("b6", "b"),("c3", "b"),("c4", "b"),("c5", "b"),("e3", "w"),("e4", "w"),("e5", "w"),("f2", "w"),("f4", "w"),("f6", "w"),("g1", "w"),("g4", "w"),("g7", "w")] -> 8
Happy Coding!
d3
andd5
are not connected. Rules say:Three men of the same color form a mill when they are in a straight row of connected points.
. I added some examples in this section tho to make it clear, thanks for the comment! \$\endgroup\$