I think my Tic Tac Toe game has an unbeatable AI?

The AI is based off of Wikipedia’s optimal strategy, and I think it’s unbeatable? At least, I haven’t been able to beat it yet. Feedback/comments/you telling me that you beat it is absolutely welcomed!

https://bethqiang.github.io/tic-tac-toe/

3 Likes

Rage Quits :rage:

Its completely unbeatable!

maybe you should add an optional easier version for people like me?

1 Like

Seems unbeatable to me.

One thing to consider: I think the convention is that X always goes first, so if I select the O token, the computer should get the first move.

corner, diagonal opposite corner, corner, win.

6 Likes

Sorry, but I beat it easily :slight_smile:

I somehow never knew this rule–but will definitely change my game to reflect that. Thanks! :slight_smile:

@jenovs @zelite @P1xt - noted. Will go back into the code and see what I can do. :slight_smile: Thanks!

1 Like

Great implementation, I had issues with the AI so finally I started with a multiplayer version. I hope if you don’t mind if I will look into your code to check how you’ve resolved the AI :slight_smile:

Not at all! I mostly brute-forced a strategy instead of using an actual algorithm, although I do hope to implement the Minimax algorithm at some point. :slight_smile:

I think that tic tac toe is a game where two reasonably skilled players should always come to a draw. It is possible to never lose at tic tac toe. As such, it is a great place to design your first AI, because you can enjoy real undeniable success.

1 Like

Oh wow, I used the strategy from Wikipedia on mine, too.
Great job on your game!
Unfortunately, though, both of our AIs are beatable (though yours is at this point much harder to beat than mine). I wonder if it is even possible to use Wiki’s strategy to create an unbeatable AI.

1 Like

I believe it is possible - I just forgot to include one of the points in Wikipedia’s strategy. :slight_smile: That’s the only flaw that people have exposed about it so far, so I’m inclined to think that if I patched that up, it would be unbeatable. I think. :grin:

I think you’re right.
I’ve worked on mine some more and it seems unbeatable: Codepen

1 Like

These examples of the tic-tac-toe game are all fantastic great job! I mindlessly played the OP’s version for like 15 min without realizing. :blush: There is still the corner’s issue, but the game is exellent. It is responsive and has a very nice design. I can’t wait untill i am able to try this challenge myself!

I won your game… you are not having all the options yet…

not even difficult lmao

I just beat yours on the 3rd try.

Started in top left corner. AI played center.
Rather than blocking, I played bottom center. The computer played top right corner.
I blocked with bottom left corner.
Computer blocked with left center.
And I win by playing lower right corner.

Playing pure defense, I always end in a tie with yours.

Was able to beat it following steps outlined in other comments.

But overall, this is super well done. Very clean design and interface. The only thing I’d change would be adding a slight delay before the computer’s move is displayed. (I find the immediacy of the computer play a bit disconcerting. I also noticed it actually plays a move in the split second between my winning move and displaying the “You win” message.)

I believe that I made a unbeatable TicTacToe ia using the Minimax algorithm. It took a great time to I undertand him but i believe that i got it. That only problem now I think that is that in moves of the AI in the first match and the second match take a long time.

i can beat your game , when i start first at 8th cell your game fill the 5th cell i fill the 1st cell your game fill the 3 rd cell i fill 7 th cell your game fill the 4th cell so i fill 9th cell , 789 i win , please check mine and give your suggestion and rate me on 10