Coder Social home page Coder Social logo

tic-tac-toe-ai's Introduction

Tic-Tac-Toe-AI

I was recently challenged with the task of writing a game of tic tac toe with an unbeatable AI. This version works on both iPhone and iPad devices. If you want to get schooled give it a shot :D

Tic tac toe is a two-player zero-sum game. By this, I mean the gain of one player is balanced perfectly by the loss of the other player and vice versa. These kinds of problems can be solved with the minimax theorem which is closely related to linear programming duality, or with Nash equilibrium.

Minimax Algorithm

The minimax algorithm often used in decision theory and game theory uses the fact that the two players are working towards opposite goals to make predictions. So we evaluate a point system for each player:

  • if you win +10
  • if you lose -10
  • if nobody wins 0

Tic tac toe has 9 squares so the possible combinations are 9! which means it is possible to process all outcomes in a reasonable amount of time. Given this fact, from any point in the game we can make a tree of all possible combinations and assign a score at each node based on the assumption that each player will want the maximum score from that nodes children. This can be done with a recursive method for assigning the score at each node. There is a method in Game.m file that accomplishes this task.

tic-tac-toe-ai's People

Contributors

awadalaa avatar

Watchers

James Cloos avatar Sebastien Royer 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.