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)