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

Tic Tac Toe AI Challenge: React, TypeScript, and Minimax Algorithm

react, typescript, sass/scss
P
Curtis•930
@webguy83
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 am most proud of the successful integration of the Minimax algorithm to create a challenging AI opponent in the Tic Tac Toe game. This accomplishment highlights my ability to apply complex algorithms in a real-world application, ensuring that the computer opponent is both challenging and fair. It was a significant achievement to see the algorithm not only function correctly but also provide a gaming experience that truly tests the player’s strategic thinking. The seamless user interface that adapts across various devices and screen sizes is another aspect I take pride in, as it demonstrates my commitment to user-centric design.

For future projects, I would aim to implement a more modular and scalable architecture from the start. While the current implementation works well for a relatively simple game like Tic Tac Toe, a more modular approach would facilitate easier updates and feature additions. I would also explore more advanced state management solutions, such as using Redux or Context API in combination with custom hooks, to handle the application's state more efficiently and avoid some of the complexities encountered with local state management.

What challenges did you encounter, and how did you overcome them?

A significant challenge I faced was managing state persistence across sessions to ensure that the game state, including the board configuration and scores, was saved accurately in local storage and restored correctly upon refreshing the page. This required a robust mechanism to handle state updates and side effects effectively. Initially, I encountered issues where state values were not persisting as expected, leading to inconsistencies in the game’s state after a page reload.

To overcome this, I developed and refined custom hooks specifically designed to manage interactions with local storage. These hooks were instrumental in encapsulating the logic for reading from and writing to local storage, ensuring that the state was consistently synchronized with the stored data. I implemented mechanisms to detect changes in the game state and update the local storage accordingly, which helped maintain the integrity of the game state across sessions.

By centralizing the state management logic within these custom hooks, I was able to simplify the overall state handling and reduce the complexity of the codebase. This not only resolved the persistence issues but also improved the maintainability and scalability of the application. The solution allowed for a seamless user experience where the game state was reliably preserved, providing a consistent gaming experience even after a browser refresh or reopening the game.

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 Curtis'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
Frontend Mentor logo

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

Frontend Mentor

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

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

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit 1st-party linked stylesheets, and styles within <style> tags.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.