robertasproniu / tic-tac-toe-agent
A Tic Tac Toe Game
1.0.1
2017-01-06 08:14 UTC
Requires
- php: >=5.5.9
Requires (Dev)
- phpunit/phpunit: ^4.8 || ^5.0
This package is not auto-updated.
Last update: 2025-04-12 22:52:58 UTC
README
A PHP Tic Tac Toe Game package with AI included
for installing just type:
Installing
You can install the library via Composer, or by downloading it directly on GitHub.
Composer
Set up a Composer project, then run the following command:
php composer.phar require robertasproniu/tic-tac-toe-agent
Basic usage
To create a game instance, use:
<?php require_once __DIR__ . '/vendor/autoload.php'; // Composer // OR require_once __DIR__ . '/src/TicTacToe.php'; // ZIP download use \TicTacToeAgent\TicTacToe; use \TicTacToeAgent\Board; $game = new TicTacToe(new Board()); // Create a new game
Now, you have created a new game with a empty board.
You can see the board by using the getBoard()
method:
print_r( $game->getBoard() );
Also you can set players symbols by accessing setPlayers()
method:
$game->setPlayers(['X', 'O']);
For getting recommended move for a player you need to pass board and player symbol
by using makeMove(array $board, $player )
method:
$move = $game->makeMove(array_fill(0, 9, null), 'X'); // board can be multidimensional array too print_r($move); // [2,0,'X'] if available position else [];