
Tic Tac Toe in React and Tailwind with unbeatable AI opponent
Design comparison
Solution retrospective
I'm proud that the app works properly and that it's impossible to win it in the CPU mode. The whole project was very hard, especially the gaming logic. First, I had a silly idea to map the next moves as strings and retrieve them from a Map object, but it turned out to have more than 40000 combinations of moves, which was too many. Eventually, I had to find minmax algorythm online and implement it inside my app (I still don't fully get how it works, to be honest, I was too tired to figure it out).
What challenges did you encounter, and how did you overcome them?I was struggling a lot with the state updates and double moves made by AI. I spent more than 3 hours trying to figure out the reason. Turned out, I put too many dependencies in useEffect and it updated too many times, which cause asynchronous methods to run multiple times. Eventually, I had to carefully distribute everything into separate functions and call them only when necessary, which is also very challenging as React run asynchonously.
What specific areas of your project would you like help with?I don't need help, to be honest. Just check it out and enjoy!
Community feedback
- @vgropsanPosted about 1 month ago
When you play against CPU and when you finish the first round with O. The second round you start with X.
I think it shouldn't be like that ..
Marked as helpful1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord