alcalyn/awale 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

alcalyn/awale

Composer 安装命令:

composer require alcalyn/awale

包简介

Awale game PHP implementation

README 文档

README

This library provides a PHP implementation of the Awale (or Oware) game.

Installation

Download

Using Composer:

{
    "require": {
        "alcalyn/awale": "1.0.x"
    }
}

Update your composer.

composer update

Not using Composer ? Install it directly.

Usage

Creating an instance

Create an instance of Awale, which is an instance of an Awale game state, with seeds.

use Alcalyn\Awale\Awale;

$awale = new Awale();

// Players start with 4 seeds in each container.
$awale->setSeedsPerContainer(4);

// The first player starts.
$awale->setCurrentPlayer(Awale::PLAYER_0);

// Needs to explicitly init the grid (containers seeds number, and attics).
$awale->initGrid();

Or to do it shorter:

use Alcalyn\Awale\Awale;

$awale = new Awale::createWithSeedsPerContainer(4);

The grid

The Awale grid represents the containers and attics.

// Retrieve the grid array from the Awale instance
$grid = $awale->getGrid();

print_r($grid);

/* Outputs:
Array
(
    [0] => Array                // Player 0, or player top.
        (
            [seeds] => Array
                (
                    [0] => 4    // Player 0 seeds, he has 4 seeds in each containers.
                    [1] => 4    // The first container is the top left container.
                    [2] => 4
                    [3] => 4
                    [4] => 4
                    [5] => 4    // The top right container.
                )

            [attic] => 0        // Player 0 has no seeds in his attic.
        )

    [1] => Array                // Player 1, or player bottom.
        (
            [seeds] => Array
                (
                    [0] => 4    // The bottom left container.
                    [1] => 4
                    [2] => 4
                    [3] => 4
                    [4] => 4
                    [5] => 4    // The bottom right container.
                )

            [attic] => 0        // No seeds in player 1 attic.
        )

)
*/

Or to get a graphical representation:

echo $awale;

/* Outputs:

Awale game instance.
     4  4  4  4  4  4
  0                    0
     4  4  4  4  4  4
seeds per container: 4
current player: PLAYER_0
last move: null

*/

Play moves

Once you have an instance of a game, you can play move.

// Top player plays his third container (from left)
$awale->play(Awale::PLAYER_0, 2);

// Bottom player plays his first container (from left)
$awale->play(Awale::PLAYER_1, 0);

The play method throws an Alcalyn\Awale\Exception\AwaleException on invalid move.

Game usefull checks

// Last played move
// An array with keys 'players' and 'move', example: {player:1, move:5}, Player 1 played his 5th container
$awale->getLastMove();

// Player's turn to play
$awale->getCurrentPlayer(); // Awale::PLAYER_0 or Awale::PLAYER_1

// Get amount of seeds needed to exceed, depending on seedsPerContainer
$awale->getSeedsNeededToWin(); // 24 if seedsPerContainer = 4

// Check is game is over (a player has more than 24 seeds, or game is looping, or player cannot feeds his opponent)
$awale->isGameOver(); // true or false

// Get winner when game is finished
$awale->getWinner(); // Awale::PLAYER_0 or Awale::PLAYER_1 or Awale::DRAW or null

// Get seeds number in a player attic
$awale->getScore(Awale::PLAYER_1);

// Whether a loop is detected (a same state of the game will appear again and again)
$awale->isGameLooping();

There is some other methods in the Awale class.

Run unit tests

First, update your composer to get phpunit, then run:

vendor/bin/phpunit -c .

License

This library is under the MIT License.

alcalyn/awale 适用场景与选型建议

alcalyn/awale 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 555 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 01 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「game」 「awale」 「oware」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 alcalyn/awale 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 alcalyn/awale 我们能提供哪些服务?
定制开发 / 二次开发

基于 alcalyn/awale 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-16