“Dots”: like the Go game, but on a grid sheet, and a neural network opponent

Hello! I’m making a digital version of “Dots” — it’s a paper game that’s popular in the CIS and Poland. When I was in school, I played quite a few games of it. I’m writing it in Godot, and the main feature is the opponent — a neural network that I trained from scratch.

I’ll warn you right away: “Dots” is not the same as Dots and Boxes. Although the names are similar, this is a completely different game. The closest relative of “Dots” is Go. “Dots” is played by two people on a grid sheet. Players take turns placing dots of their own color at the intersections of the cells and try to surround the opponent’s dots. Anything that ends up inside a closed chain of your dots, spaced one cell apart (diagonals also count), is considered surrounded. You can learn the rules in two minutes, but learning to play well is not that easy. Each player weaves their own network of dots, and the game turns into a race of traps that the opponents set for each other.

Why can’t a strong opponent be programmed

I’ve long wanted to have a strong AI opponent for “Dots”. At first, it seemed that it would be possible to program an algorithm similar to the one used in chess: iterating through moves plus evaluating the position. It turned out that it wasn’t possible, and the reason was the scale. The chessboard has 64 squares, and in an average position there are about 35 possible moves. To calculate a chain of 4 moves, you need to iterate through approximately 1.5 million options — a feasible task for a computer. The classic “Dots” board is 39×32, i.e., 1,248 cells, and a move can be almost any empty cell. The same 4 moves already yield about 2 trillion options — a million times more. Moreover, a chess position is easy to evaluate based on a simple criterion: who has the stronger pieces left. “Dots” has no such criterion.

How the neural network learned

Since it’s impossible to program the evaluation of a position, let’s try to train a neural network. I took the approach of AlphaZero — a program that was taught to play Go — as a basis. The idea is this: the neural network plays thousands of games against itself and then learns from this data. A new generation of the network enters the “arena” — it plays a series of games against the previous one. If the newcomer wins more often than it loses, it takes the place of the previous one and generates games for the next generation. Currently, the 20th generation is in the game, and while I’m writing this post, an arena is going on against the 21st. I’m training the network on PyTorch using my home graphics card, an RTX 5070 Ti — one generation takes approximately 15 hours.

How it works in Godot

The game itself is written in Godot 4.7 + C#/.NET 10. The rules and game logic are pure C# without external dependencies. The neural network is trained in Python and run in C#. To do this, it is exported to ONNX — a universal format for neural networks. In the game, the model runs on the player’s GPU: DirectML on Windows, CoreML on macOS, CUDA on Linux. A special bonus: the network is convolutional — it doesn’t look at the entire field; it moves a small window across it, like a blur filter over an image in a shader. Therefore, the size of the field doesn’t matter to it: the same model plays both on a 9×9 field and on a classic 39×32 field — the size is chosen before the match. If you have questions about training the network or about integrating ONNX into Godot, ask in the thread, and I’ll share the details.

What’s ready now

The game against the AI is ready, there’s a two‑player mode on one computer, saving and viewing games, two difficulty levels, and the option to choose the board size and starting arrangement. On a 15×15 board, the “Harder” level consistently beats me. On the classic 39×32 board, the network responds in less than a second, but it’s still doesn’t play well: the training hasn’t reached this size yet — I’m gradually expanding the board sizes.

Right now, I’m preparing the game for release on Steam (only Windows for now): Just Dots on Steam. If you like the game, add it to your wishlist. This will be very helpful to me: the more people have it on their wishlist, the higher the game will rank in the Steam ratings, and the more people will see it. I’m planning to release the game in December, but if you’re interested in battling the AI, I can give you access to the beta version — message me privately.

5 Likes

What a nice clean UI. Maybe too clean. And too off-center. Did you try putting score and buttons into a top or bottom row?

Is there anything that stops you from making this multi-player just to stand out from the crowd? A agar.io like friendslop game for people with turtle-neck pullovers :smiley:
If it get’s crowded, just zoom out every few moves like Mini Metro does (and MM shows on your steam page). Took me ages to notice that zoom…

I see quite a few dots and boxes games on Google Play, no harm in looking what those with success do do.
Actually, I’m feeling inspired branching my current Voronoi graph prototype into a Dots and Polygons game :smiley:

1 Like

Hello! Thanks for the ideas!

I see quite a few dots and boxes games on Google Play, no harm in looking what those with success do.

It seems to me that you’re viewing this game as a variation of Dots and Boxes, but it’s a different game with completely different rules. Its closest relative is Go. The rules are simply, but the gameplay that grows out of them is surprisingly deep.

If you’re curious, I’d be happy to send you beta access — just DM me. Maybe you’ll discover a game you’ll really enjoy :slight_smile:

This looks really cool :fire:
The UI is so clean well done!
Keep it up

1 Like

There appear to be strategic similarities to Hex. You might want to look at approaches that have been profitable in Hex programs, for example, the use of Monte Carlo tree search. I mention this because your neural network work would give you a head start on a MCTS guided by a neural network.

I suspect virtual connections might also be a useful Hex concept.

Disclaimer: I have never played Dots, but I spent too much time working on Hex back in the early 1990’s :smiley:

More information at www.hexwiki.net/index.php/Computer_Hex

1 Like