Message Boards Message Boards

Back

Challenge: Tic-tac-toe

Threads [ Previous | Next ]
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)