akondas / chess.php
chess.php 是一个用于棋步生成/验证、棋子放置/移动,以及将军/被将军/长将的 PHP 棋牌库
v1.0.5
2019-01-28 22:14 UTC
Requires
- php: ^7.2
- ext-json: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.14
- johnkary/phpunit-speedtrap: ^3.0
- phpbench/phpbench: ^0.15.0
- phpstan/phpstan: ^0.11.1
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-08-29 05:06:30 UTC
README
chess.php 是一个用于棋步生成/验证、棋子放置/移动,以及将军/被将军/长将的 PHP 棋牌库——基本上是一切,除了人工智能。
注意:这是从 php 转移 chess.js 的版本,forked from ryanhs/chess.php
安装
使用 composer 通过 composer require akondas/chess.php
或者在您的 composer.json 中添加
"require": {
"ryanhs/chess.php": "^1.0"
}
示例代码
下面的代码随机进行一局完整的棋局 ...
<?php require 'vendor/autoload.php'; use \Ryanhs\Chess\Chess; $chess = new Chess(); while (!$chess->gameOver()) { $moves = $chess->moves(); $move = $moves[mt_rand(0, count($moves) - 1)]; $chess->move($move); } echo $chess->ascii() . PHP_EOL;
+------------------------+
8 | . . . . . . . . |
7 | . . . . r . . . |
6 | . . . . . . . . |
5 | . . . . . . . . |
4 | k . . . . . . . |
3 | . . . . . . K . |
2 | . . . n . . . . |
1 | . . . . . . . . |
+------------------------+
a b c d e f g h
性能
在这个主题上还有很多工作要做。
akondas/php-grandmaster 是开始实验的好地方 ;)