Message Boards Message Boards

Back

Challenge: Tic-tac-toe

Toggle
Challenge: Tic-tac-toe
Answer
5/24/25 8:15 AM
Hi all,

Just to learn more about smartbuilder functionality and programming, I am trying to build a tic-tac-toe game which 'in theory' the computer would never loose. I'm already pretty happy with the base I have so far of how the pieces move and the limited code is uses to get everything working, but am now starting with the computer 'intellegence' to see traps and make the best move. Besides that I think there is still some room for optimising the code, like a way to check the item's index in a list.

All input from everybody is welcome. As said before, it is just a learning project, so everybody who wants to join, help, share, read along or use it in a project is welcome to. Ideas on possibilities how to do this, code blocks or ways to optimise code are are appreciated and needed for this project to evolve further, and of course help us learn stuff.

Thanks in advance and looking forward to everybody's reply emoticon
0 (0 Votes)

RE: Challenge: Tic-tac-toe
Answer
5/30/25 9:16 PM as a reply to Marcel Ooms.
Hi Marcel,
This is really neat! Thanks for creating this, and sharing your file.

I have a couple of efficiencies that I can show you regarding tag lists, which will make your actions smaller (but more dense/complex). Here's a video showing those - https://app.screencast.com/OiRYXDf7ZHuXj

Overall, you're correct, I think the hardest part is getting the computer to think of the best next move. However, I believe that if everyone is playing tic-tac-toe optimally, the game is not actually any fun. The first player always wins or ties, or the second player can always force a draw. So your ComputerPlayer will always force a tie if it's being smart. So your current approach of randomly selecting a tile, I would argue, is more fun, because the HumanPlayer can actually win. You may want to consider some alternate form of slightly dumbed-down-AI for the ComputerPlayer where it tries to block a three-in-a-rown, but if the HumanPlayer is smart, they will still win. I think this is a common "problem" for video games - making the AI challenging, but not too difficult.

Here are the rules on how to never lose at tic-tac-toe - https://www.youtube.com/watch?v=6ZForbaku9c&ab_channel=PinkPencil (one small mistake in one of the diagrams, but what they're saying is accurate).
0 (0 Votes)

RE: Challenge: Tic-tac-toe
Answer
12/23/25 11:58 AM as a reply to Navdeep Dhillon.
Hi Smartbuilder Community,

It took some time, but I finally had time to make an update on the game again. It is a big change, mainly on switching to lists and making a start on finding the best move for the computer. Here are some of my findings and remarks
- I found a way to make a list quickly using the split text block
- Everything is now made with the 'procedure' object as Navdeep advised and showed in this tutorial. This gives a cleaner overview and is perfect for small games.
- We use lists now instead of the inputtext. Mainly because it is easier to check the lenght of the lists.
- I had trouble with the 'is thing in list' block, so I used the 'is everything in list'. But still not sure what I did wrong. Maybe because a list can not be a 'thing'?
- I also had trouble transfering the only number on a list to another. That's why I used the 'pick random' on lists of 1 item long. I don't understand why I couldn't use the 'copy list' function or just connect the two variables directly to eachother.
- Is it possible to have the possible lists (vertical, horizontal & diagonal) in a map which could iterate the checking procedure? Just to make it more tidy instead of adding all possibilities (checking best move, checking best defence, checking if game finished etc) manually?

I still have a few things I want to improve. But all tips, tricks and ideas on improving or optimizing are welcome ofcoure. I would love to hear everybody's ideas on how to program this game emoticon
0 (0 Votes)

RE: Challenge: Tic-tac-toe
Answer
6/8/26 12:59 PM as a reply to Marcel Ooms.
Hi Smartbuilder community,

I had some time again to continue this project. You can see the project here: https://mooms.nl/projects/tictactoe/
- improved the computers best move (although still not super clean code, it does work pretty well and is hard to beat)
- added the design
- added the players' name(s) function and ability to choose the difficulty level
- added a multi player 

I'm curious what you guys think of it. Although not the most interesting project, it was a very good challenge to teach myself some smartbuilder coding and ideas about game making. If you have any ideas or comments, I'm very happy to hear them emoticon. Or if you want to check out the project file, just leave a reply.

Cheers

Marcel
0 (0 Votes)

RE: Challenge: Tic-tac-toe
Answer
6/9/26 6:40 PM as a reply to Marcel Ooms.
Very cool, Marcel! It works well and looks really good!

How did you create different difficulty levels for the computer? Calculate a random placement and the ideal placement, and then adjust the probability that it picks one or the other?
Here are some thoughts from someone with fresh eyes:
  1. I would include a way to go back to the main menu to change your name / difficulty / swap to multiplayer. Most people probably aren't viewing this to play the game, but rather to test out the capabilities.
  2. I would add some sounds (and a mute button). Choosing the right sounds can be an art - you want fun, but not annoying or obtrusive. You might have to look on paid sites to get sounds with the right feel - I haven't had much luck with free quality sounds.
  3. In the multiplayer version, I would make it VERY clear whose turn it is. Maybe change the background color, or show something large on the page to indicate if it is the O player or the X player.
Thanks so much for sharing!
0 (0 Votes)

RE: Challenge: Tic-tac-toe
Answer
6/11/26 8:11 AM as a reply to Navdeep Dhillon.
Hi Navdeep,

Yes, the difficulty level is exactly as you say. Hard is the best computer move, easy is just random placement and medium all possible options + twice the best move and then randomly pick, so it starts bad but becomes better during the game. So it becomes more likely the computer will see when there are 2 in a row.

Good suggestions! I will add the first and second in the next version. The third one is in the top left corner, but maybe it is too hidden. I will see if I can make it more visible. Maybe grey out the stones of the other person.

Thanks for these suggestions. This gives new inspiration for another improvement round emoticon
0 (0 Votes)