I just wanted to put it out there, I think it would be a fantastic learning tool if there was an option for OGS to move the stones around for counting at the end of a game, the same as is done on a real Go board.

The purpose being to simulate the traditional counting method, as a cultural artifact, as a learning aid, and because it looks cool. I think it would be a great resource to see how counting actually works and make it easier for people to transition to in-person Go boards.

Accurately capturing the traditional method in an algorithm is tricky, since itâ€™s a matter of style. Personally I feel that Japanese-style counting would be most clear, but Iâ€™m not a programmer!

I donâ€™t think it is an â€śAIâ€ť, just an algorithm for going around the board picking up stones, putting them down, and making areas in each surrounded territory. I do not enjoy programming in my free time, but people in discord seemed to like the idea so I just wanted to put it out there.

AI or not, a proof of concept would be a good idea. (As someone who does enjoy programming, Iâ€™m still not really sure how would be a good way to implement this)

From my limited knowledge, I would say something like:

Pick up all the dead stones

Divide each distinct group that surrounds territory

Set it up as a constrained optimization problem to create separate zones that are as square/rectangular as possible

I am not sure how the movement of stones would work, that seems like the hard part to program. Maybe the first step is a problem to draw lines where the minimum territorial borders are, and then the next step is to move stones around.

The â€śAIâ€ť might simply solve an optimisation problem, as follows.

Step 0. Start with a go position after both players have passed. Remove the dead stones.

Step 1. Mark every intersection of the board with one of the following five labels:
White stone, Black stone, White territory, Black territory, or Dame.
If using Japanese rules, if there is a seki on the board, then all intersections involved in the seki must be marked as Dame as well, including the stones and eyes.

Step 2. A â€śsolutionâ€ť of the optimisation problems consists in changing the labels of any number of intersections, with the following rules:

A black stone or territory cannot become a white stone or territory, nor vice versa;

The number of black stones that become black territories plus the number of stones captured by white must be equal to the number of black territories that become black stones;

The number of white stones that become white territories plus the number of stones captured by black must be equal to the number of white territories that become white stones;

These rules guarantee that the score of the game is unaffected.

Then, the optimal solution is the solution that

maximises the â€śrectangularnessâ€ť of the territories, while at the same time

Minimising the number of changed labels is easy to formulate. Maximising the rectangularness is the harder part.

Idea 1
â€śMaximising the rectangularnessâ€ť might be reworded as â€śminimising the perimeterâ€ť. Now we just need to find a good definition for perimeter of a territory.

We can define â€śperimeterâ€ť as follows:

Every intersection contributes between 0 and 4 to the perimeter of a territory.

An intersection which does not belong to a territory contributes 0 to the perimeter of that territory.

An intersection which belongs to a territory contributes 1 for each adjacent intersection which does not belong to that territory.

An intersection which belongs to a territory also contributes 1 for each adjacent side of the board.

Idea 2
A territory is a rectangle if and only if it is convex. So we can add penalties for every concavity in a territory. A concavity is an intersection which is not in the territory, but is adjacent to at least two intersections which are in the same territory.

Not sure if this is worth noting, but thereâ€™s another â€śaxisâ€ť on which go players tend to maximize during the scoring phase: â€śround numbers/multiples of 10s/5sâ€ť thatâ€™s why you see stuff like: