Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

TicTacToe with AI using React

P
alexanderβ€’ 1,300

@alex931d

Desktop design screenshot for the Tic Tac Toe game coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
3intermediate
View challenge

Design comparison


SolutionDesign

Solution retrospective


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

hello just finished the tictactoe challenge open for feedback :)

Community feedback

@loki1205

Posted

Hi, this is a great project, I tried playing with computer and the computer knows where exactly to block the move. How does it know that? What logiv are you using for computer?

1

P
alexanderβ€’ 1,300

@alex931d

Posted

@loki1205 Hello, I'm using something called the minimax algorithm. It compares a lot of moves in a tree structure and finds the best outcome based on some rules!

In this small game, I programmed my CPU player to prioritize blocking over winning. The CPU gains 2 points for blocking instead of 1 for winning. Therefore, it will always try to block the opponent. Furthermore the CPU player knows the maximum score is infinity and minimum is -infinity and will always try to reach the best score!

1

Please log in to post a comment

Log in with GitHub
Discord logo

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