git clone
this repository locally- run
composer install
- run
php scripts/run.php
. The program will start, good luck with beating the Ai ;)
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.
The AI will never lose. At best you can Draw
. The Ai will apply the strategy mentioned on Wikipedia.
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.