Code Monkey home page Code Monkey logo

tictactoe's Introduction

Unbeatable TicTacToe

To play:

Open index.html in a browser.

AI

The AI uses a recursive minimax algorithm to calculate the optimal move.

  1. For a given state, it generates a list of all possible moves.
  2. For each possible move, it then generates a new list of all the opponent's possible moves, and so on.
  3. At the bottom of the possibility tree, when the simulated game is finished, weights are assigned based on the outcome: * 10 points if the computer won * -10 points if the opponent won * 0 points for a tie * In addition, points are decremented based on how many levels deep in the recursion it is, essentially telling the computer that quicker wins are more valuable.
  4. As the recursive calls resolve, each level of the branch (therefore each possible move) is assigned a weight based on whose turn it was: * The maximum of all possible scores of that branch if it was the computer's turn * The minimum of all possible scores of that branch if it was the opponent's turn
  5. Finally, at the top level of the recursion, the computer chooses the move that had the highest possible score.

tictactoe's People

Contributors

ksullivan2 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.