PHP code example of air-petr / tic-tac-toe-ai

1. Go to this page and download the library: Download air-petr/tic-tac-toe-ai library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

air-petr / tic-tac-toe-ai example snippets


use AirPetr\TicTacToeAi\Player;
use AirPetr\TicTacToeAi\Board;

$board = new Board();
$player = new Player();

echo $board->toString(); // "_________"

$boardWithMove = $player->placeMark('X', $board);

echo $boardWithMove->toString(); // "__X______"

$easyPlayer = Player::easy();
$normalPlayer = Player::normal();
$hardPlayer = Player::hard();

$board1 = Board::createByString('__X___O__');
echo $board1->toString(); // "__X___O__"

$board2 = Board::createByPlainArray(['_', '_', 'X', '_', '_', '_', 'O', '_', '_']);
echo $board2->toString(); // "__X___O__"

$board3 = Board::createByArrayTable([
    ['_', '_', 'X'],
    ['_', '_', '_'],
    ['O', '_', '_']
]);
echo $board3->toString(); // "__X___O__"

$board = Board::createByString('__X___O__');

$board->toString();
// "__X___O__"

$board->toPlainArray();
// ['_', '_', 'X', '_', '_', '_', 'O', '_', '_']

$board->toArrayTable();
// [['_', '_', 'X'], ['_', '_', '_'], ['O', '_', '_']]
bash
php demo/interactive_game.php