承接 p-chess/chess-bundle 相关项目开发

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

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

p-chess/chess-bundle

Composer 安装命令:

composer require p-chess/chess-bundle

包简介

Provide integration with p-chess/chess library

关键字:

README 文档

README

Installation

Run composer require p-chess/chess-bundle

Configuration

Create a service that extends PChess\ChessBundle\HtmlOutput and implement the required methods. You probably want to inject Symfony's router service here and use it to return the required URLs. Note that each route can be provided with an identifier for your game.

Create a configuration file, and use content like the following:

# config/packages/chess.yaml
chess:
    output_service: App\YourOutputService

This is an example of how routes can be defined (using an "id" parameter as an identifier):

# config/routes.yaml
move_start:
    path: /{id}/move/{from}
    methods: GET
    controller: ... # your controller action

move_cancel:
    path: /{id}
    methods: GET
    controller: ... # your controller action

move_promotion:
    path: /{id}/promote/{from}/{to}
    methods: GET
    controller: ... # your controller action

move_end:
    path: /{id}/move/{from}/{to}/{promotion}
    methods: GET
    controller: ... # your controller action
    defaults:
        promotion: ~

Usage

You can inject a service implementing \PChess\ChessBundle\ChessProviderInterface in your controller, then implement different actions, using the provided \PChess\Chess\Chess object.

In your template, you can use the Twig function chess_render(chess) to render the board. If you need to pass an identifier, use chess_render(chess, identifier) instead.

The main service you can use is \PChess\ChessBundle\SessionChessProvider. This service allows you to keep chess games in session, providing the following methods:

  • getChess($identifier, $fen) to get main \PChess\Chess\Chess instance (as provided by interface)
  • restart($identifier) to restart the game
  • save($identifier) to save the game in session
  • reverse($identifier) to switch sides
  • getAllowedMoves($chess, $from) to get a list of currently allowed moves (optionally limited to $from square)

Using $identifier is not mandatory.

Styling

You can use the provided _board.scss file to style the board:

@import '~@p-chess/chess-bundle/scss/board';

Don't forget to update your frontend files, using npm or yarn.

The final result should be something like this:

Persisting a Chess object

You can easily save a Chess object into Doctrine (or other kinds of mapping libraries), using two fields/properties: fen, and history. The first one is a simple string. The second one can be a simple_array (for Doctrine), where you should put the result of Mover::getHistoryStrings() method. When retrieving an object, you should use fen and the result of Mover::getHistoryEntries() to build back your Chess object.

p-chess/chess-bundle 适用场景与选型建议

p-chess/chess-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 36 次下载、GitHub Stars 达 5, 最近一次更新时间为 2021 年 04 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 p-chess/chess-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-05