My Tic-Tac-Toe game - Should be unbeatable

My Tic-Tac-Toe game - Should be unbeatable
0.0 0

#1

Please check my Tic-Tac-Toe game.

Try to win :slight_smile:

AI is implemented without using MiniMax, so it is possible there are some edge cases I didn’t think of.

Any feedback appreciated.


#2

I confirm, can only do tie. :slight_smile:


#3

Nice job! I couldn’t beat it either.


#4

So, looking at your code on Github, yours is more of a hardcoded strategy?

// if AI moves first, take corner

// if AI moves second, take center, if center taken, take corner…

Did you choose this because it’s a known ‘optimum’ unbeatable strategy that’s documented somewhere, or did you work out this ‘unbeatable’?

Very curious as to why you went in this direction. About to start the project myself and trying to decide if I want to learn minimax.


#5

Unbeatable without minimax as far as I can see. This is very cool.


#6

I got this strategy from Wikipedia.

I tried minimax, but I just couldn’t translate the algorithm to JavaScript so I did a little research and found the mentioned Wikipedia article and went with hardcoding the strategy.


#7

Got it. Nice work.

I found a good article explaining minimax - I’m going to try and implement it. Then I’ll go your way if I find it impossible: http://neverstopbuilding.com/minimax


#8


#9

I win the second time, before my turn, sorry:


#10

Thank you @mikeale03 and @xavierartot for your feedback.

I’m currently working on my fCC Back-End projects, but someday I’ll come back to update the frontend projects and will fix the bugs you pointed out :wink: