承接 air-petr/tic-tac-toe-ai 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

air-petr/tic-tac-toe-ai

Composer 安装命令:

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

包简介

PHP AI for Tic-Tac-Toe playing.

README 文档

README

PHP AI for a tic-tac-toe game.

Installation

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

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

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

php demo/interactive_game.php

Testing

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

composer test

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-11-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固