Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 10 months ago

Tic Tac Toe in React and Tailwind with unbeatable AI opponent

react, tailwind-css, vite
Ilya Andreev•950
@NeoScripter
A solution to the Tic Tac Toe game challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?

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!

Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on Ilya Andreev's solution.

Join 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

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner
  • Use cases

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License