Some help on coding a minimax

I, as a child I am, decided to draw a tic tac toe board on my hand :man_facepalming:

But! That made me think we should make Tic Tac Toe in Desmos!

And! I want to make a machine for the user to play against!

But! I have no idea how to make the AI (aka minimax)!

But! I have many people here to help me on CL forums.

Thanks!!! (I created this post as a Discussion because if I put it in Questions it would be off-topic)

1 Like

Cool idea.
There’s a really nice Desmos Graph to play Reversi:

https://www.desmos.com/art?lang=it#17;hmx24xhkc8
It uses the Alpha–beta pruning for minimax.
I didn’t study the code but it is really well done.

I suspect that for tic-tac-toe one may be able to simply
hardwire all the possibilities factoring out simmetries and rotations
and it is surely possible to greatly simplify the algorithm because
the game tree isn’t that deep so we can see how the game ends.

1 Like

While I was at summer camp I thought that we can just code where the user threatens to win, then make the AI always play there. If the user doesn’t threaten any win (the win variable is undefined or 0), the AI will try to create it’s own win.

Somewhat similar to what you said. I also saw that reversi game on the art expo!

This is what I have so far: Tic Tac Toe - Desmos | Desmos

Everything is done other than the AI logic

1 Like

UPDATE
Just tore apart and shredded my brain to make the AI be able to block a user’s win.

1 Like

It would be even cooler to develop a tic tac toe board that with each square is another tic tac toe and you have to when the indiviual tic tac toe to claim that square and where you play also determines which main box your opponent must play in next.

2 Likes

I’m pretty sure I’ve seen that as like a video game somewhere… cool idea.

1 Like

I think it was called Ultimate Tic-Tac-Toe? I also recall that when you play in a sub-grid, your opponent must go to the sub-grid that corresponds to the tile, so playing on the left side forces the other player to play on the left sub-grid.

Just thought of something: what if the sub-grid thingy was a tie?

1 Like

I typically count it as being scored for nobody, and it won’t be filled out. Sometimes, I empty the grid and put it back into play.

That’s pretty smart.

1 Like