Skip to content

jnardiello/Tic-Tac-Toe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Tic Tac Toe

Requirements

  • PHP 5x installed on your machine. You can quickly grab a php vagrant machine here.
  • Install composer

Install

  • git clone this repository locally
  • run composer install

Run

  • run php scripts/run.php. The program will start, good luck with beating the Ai ;)

Creating a new game

To create a new game simply

$tictactoe = new TicTacToe();
$winner = $tictactoe
    ->addAi('Al', 'O')
    ->addHuman('Jacopo', 'X')
    ->play();

where the order in which you are adding ais or humans will affect the order of turns. The winner name and message will be returned.

Notes

The AI will never lose. At best you can Draw. The Ai will apply the strategy mentioned on Wikipedia.

Dev notes

To run the tests vendor\bin\phpunit

The Ai implements a series of rules, which are listed by priority. The most interesting rules are Fork and BlockOpponentFork as the Ai will run a real simulation to understand if it is possible to generate a fork or if the opponent is going to fork anytime soon - and calculate how to stop it.

About

The Tic Tac Toe

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages