You are browsing as a guest. Sign up (or log in) to start making projects!

Gomoku Balanced

  • 11 Devlogs
  • 49 Total hours

Simular to tic-tac-toe, but with a large board and it goes up to 5 instead of 3. Includes offline multiplayer and a bot to play against. Balanced so that black doesn't win 100% of the time.

Ship #1 Pending review

I made Gomoku in Pygame. Gomoku is an East Asian board game that's kinda similar to Tic-Tac-Toe, except the board is 15x15 or 19x19 and the players are aiming for 5 in a row instead of 3.

By far the hardest part of making this was making the bot that plays against you. It essentially scans every spot on the board for a specific pattern, and places a stone when it detects the pattern, which allows it to make and respond to threats.

In order to balance the game, the board starts in a randomized position. This is done because when black starts and places a stone in the middle of the board, there is a 100% chance theoretically and 67% chance practically that black will win, which is kinda unfair.

The program also includes a somewhat functional title screen and a volume toggle that stores the status on a persistent config file.

This is my first actually serious Python project, and my first time making any sort of GUI in a non-browser based programming language (like not scratch and not javascript). It was really satisfying to make, even if I did get annoyed a lot while making it.

  • 11 devlogs
  • 49h
Try project → See source code →
Open comments for this post

3h 16m 29s logged

Devlog #11: Probably final devlog before ship

The project is now released on Itch.io! There’s files for Linux, MacOS, and Windows since compatibility is important. I personally daily drive Linux, but I know that most people use Mac or Windows.

If I get 5 likes on this post I might release this for iOS and Android (depends on if it costs money to release idk)

Yes, it did take me 3 hours to package the files and put them on GitHub and Itch.io. Yes, I also used AI a lot for it, but in my defense this is my first time doing anything like this.

There were also a couple of issues with the assets locations, and I also had to use AI but overall I think AI only takes up maybe 2-3% of this project.

0
0
9
Open comments for this post

4h 20m 17s logged

Devlog #10:

The bot is finally fixed. Now it (almost) never misses tactics, and it plays about 10 times faster thanks to better scanning.

So essentially what I did was for every empty spot on the board, it scans for a specified pattern. If a pattern is found, it returns the coordinates, which are then placed. If somehow there are no patterns, the bot either tries to get 2 in a row or plays randomly.

the screenshot is me losing to my own creation. probably because i lowkey have a skill issue

0
0
3
Open comments for this post

3h 38m 28s logged

Devlog #9

I added a volume toggle to the main menu. IDK if I mentioned this, but I added background music to the game. It gets annoying listening to the same 3 songs for so long, so I made a 2 buttons with Inkscape and coded it so that they toggle between each other depending on if the background music is turned on or turned off.

I decided to switch from Visual Studio Code to PyCharm, and was then assaulted by like 50 warnings about how everything I did went against some kind of Python convention or another. It took me like an hour, but I managed to get all the errors sorted out.

The bot is still broken, IDK why :(

0
0
4
Open comments for this post

3h 45m 5s logged

Devlog #8

Some relatively small changes like README improvements and adding the ability for the game to handle draws. Believe it or not, it’s actually possible to get a draw by filling up the entire board, but it isn’t easy (see image below).

I also removed the bot’s AI because it was really unoptimized and inefficient, and I am now in the process of rebuilding the bot’s AI from scratch.

0
0
6
Open comments for this post

5h 12m 26s logged

Devlog #7

The bot can now create threats and and will try to win. It’s still kinda dumb imo, but I’m a relatively skilled player so yeah.

I was thinking of maybe using an engine someone else had built to power the bot but I couldn’t find anything.

The bot still misses tactics from me like 50% of the time and idk how to make it better.

0
0
3
Open comments for this post

6h 21m 25s logged

Devlog #6

I added intelligence to the bot. It’s not that smart yet, but it now actively can try to thwart your plans by blocking you when you have 3 or 4 in a row, and will also try to get 5 in a row.

I did this by searching for 3 and 4 in a row using a modified version of the function that scans for the game conclusion (5 in a row).

To help evaluate the position, I created a separate copy of the board, then simulated placing stones on every spot and seeing if there’s a 4 or 5 in a row now.

For a while, if there was already a 3 or 4 in a row on the board, the engine would just think that the first available spot was a good spot, which is not good. I solved this by getting the function to return the position where the 4 or 5 in a row is located.

The bot has yet to beat me in a game where I took it seriously, but hopefully that changes soon.

0
0
2
Open comments for this post

1h 26m 37s logged

Devlog #5

I made singlepayer vs bot (finally). Only problem, the bot players with the skill of a blind and deaf 2 year old, which is too say, completely randomly.

I will proceed to stall the creation of an somewhat competent engine for this for like 3 weeks.

0
0
2
Open comments for this post

2h 46m 25s logged

Devlog #4: Optimizations and StartPositions

As the title implies, I optimized the code and tried to fix what is called “spaghetti code”. I guess I was somewhat successful but I won’t know until I start trying to implement singleplayer with the bot.

One thing about this project that I haven’t implemented yet is the actual swap2 balancing. Except that actually implementing swap2 turns out to be very hard, so I decided to use my own balancing method instead, by just picking a random starting position with 3 stones on the board. Is this the best? No. But does it work better than the pro method? Probably idk.

0
0
1
Open comments for this post

9h 44m 57s logged

#Devlog #3

I added a main menu to the game. It doesn’t look good or anything, and I had to make the buttons in GIMP because I was too lazy to draw the buttons on Pygame.

From the main menu, you can quit the game, play offline multiplayer, and there’s also buttons for settings and singleplayer, which don’t do anything except stop you from clicking any buttons.

After someone wins in offline multiplayer, a line gets drawn (like in tic-tac-toe), and you exit back to the main menu. For a long time, it was broken and after you exited, you weren’t able to start another game, but that was because of a bug with resetting the board.

0
0
2
Open comments for this post

4h 25m 42s logged

Devlog #2

So you can now actually play the game. It only took me 8 hours.

What I added

Placing stones

The most basic gameplay mechanic of Gomuku and Go. When you click on a place you can place a stone (in Gomuku and Go it’s where the lines intersect), a stone appears according which player’s turn it currently is.

Winning

When you get 5 in a row, you win. The game window closes instantly, which isn’t really good, but I couldn’t find a way to display a gameover message (at least not yet)

Struggles

Misalignment

For a long time, the rendering script was somehow broken and stones would display in the incorrect location. I solved it by manually moving the stones 45 pixels up and left.

Gameover detection

This took me so long. For the longest time, it seemed like the code was just not running. Then I asked AI because I literally did not know what to do, then the program just crashed on start. Then I asked AI again and it works now. Apparently it was because I used break and return prematurely, which lead to most of the squares not being detected.

0
0
7
Open comments for this post

4h 20m 9s logged

#Devlog #1
My family is from China, and so as I grew up I played a lot of Asian board games. One of those was Gomuku, or Wuziqi. So I decided to make it in Python, with a bit of a twist.

Most of the gomuku websites on the internet, and even my family, when we played it, use the Pro ruleset. In this ruleset, the player that starts first (black) has literally a 100% chance of winning in a perfect game, and a 67% chance of winning in actual competitive play. This is of course, unfair, so the highest level tournaments instead use the swap2 ruleset (hence the swap2 in the project name), which balances things out. TBH I don’t really understand it much but I’ll figure it out.

So this session, I just made a game board in Pygame. This should not have taken me 3 hours, but I don’t have any experience in Pygame beforehand, and also I tried to code the code for placing the stones before the code to actually rendering the game. I had to delete the code since it was very confusing when writing the code to draw the board.

0
0
2

Delete project?

Are you sure you want to permanently delete this project? This action cannot be undone.

All devlogs, followers, and associated data will be removed.

Followers

Loading…