PHPackages                             air-petr/tic-tac-toe-ai - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. air-petr/tic-tac-toe-ai

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

air-petr/tic-tac-toe-ai
=======================

PHP AI for Tic-Tac-Toe playing.

v1.0.3(4y ago)05MITPHPPHP &gt;=7.4

Since Oct 10Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Air-Petr/tic-tac-toe-ai)[ Packagist](https://packagist.org/packages/air-petr/tic-tac-toe-ai)[ RSS](/packages/air-petr-tic-tac-toe-ai/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (2)Versions (8)Used By (0)

Tic-Tac-Toe AI
==============

[](#tic-tac-toe-ai)

PHP AI for a tic-tac-toe game.

Installation
------------

[](#installation)

```
composer require air-petr/tic-tac-toe-ai
```

How To Use
----------

[](#how-to-use)

`Player` and `Board` are main classes of this package. In general, you create a board, give it to an AI player and receive it back with a new mark. `placeMark` is a main function of `Player` instance.

```
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______"
```

There are three difficulties of AI players: easy, normal and hard.

- Easy player does random moves.
- Hard player is based on a minimax algorithm. He is unbeatable.
- Normal player is between hard and easy player. He doesn't give you an easy victory, but can be caught by fork. Just like an average human Tic-tac-toe player.

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

`Board` instance can be created from various data sources. Use `X` and `O` symbols for initialization:

```
$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` instance also can be converted to various representations:

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

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

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

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

Demo
----

[](#demo)

You can play with code in `demo` folder. Here's how you can run interactive game:

```
php demo/interactive_game.php
```

Testing
-------

[](#testing)

There are some unit tests in `test` folder. Run tests by:

```
composer test
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~25 days

Recently: every ~31 days

Total

6

Last Release

1549d ago

Major Versions

v0.2.0 → v1.0.02021-11-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/dc29160cfd4432204e4df0fbab4bfcc6e7b1ba471255e64146b93a604c7c8e72?d=identicon)[air-petr](/maintainers/air-petr)

---

Top Contributors

[![Air-Petr](https://avatars.githubusercontent.com/u/15061863?v=4)](https://github.com/Air-Petr "Air-Petr (53 commits)")

---

Tags

aigamealgorithms

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/air-petr-tic-tac-toe-ai/health.svg)

```
[![Health](https://phpackages.com/badges/air-petr-tic-tac-toe-ai/health.svg)](https://phpackages.com/packages/air-petr-tic-tac-toe-ai)
```

###  Alternatives

[rubix/ml

A high-level machine learning and deep learning library for the PHP language.

2.2k1.4M28](/packages/rubix-ml)[codewithkyrian/transformers

State-of-the-art Machine Learning for PHP. Run Transformers in PHP

749231.8k5](/packages/codewithkyrian-transformers)[maestroerror/laragent

Power of AI Agents in your Laravel project

630106.4k](/packages/maestroerror-laragent)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

310107.9k1](/packages/cognesy-instructor-php)[davmixcool/php-sentiment-analyzer

PHP Sentiment Analyzer is a lexicon and rule-based sentiment analysis tool that is used to understand sentiments in a sentence using VADER (Valence Aware Dictionary and sentiment Reasoner).

138151.7k1](/packages/davmixcool-php-sentiment-analyzer)[symfony/ai-platform

PHP library for interacting with AI platform provider.

51927.7k136](/packages/symfony-ai-platform)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
