mano/chessknight 问题修复 & 功能扩展

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

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

mano/chessknight

Composer 安装命令:

composer require mano/chessknight

包简介

Knight's Shortest Path on an Infinite Chessboard

README 文档

README

A logic game as a programming exercise. Find the shortest path of a chess knight on chessboard.

There are multiple strategies to this problem - only one is implemented so far(Breadth-first search). A tree of all possible moves is built gradually and the result is evaluated at each depth level.

Other suggested strategies to improve performance:

  • divide the board into smaller parts first
  • only try offsets that aim to the final square initially
  • try several depth level at once (can be also slower - can be nicely combined with previous point)

Installation

Clone the repository.

If you want to run tests, run Composer.

php composer install

Tests

Not covered all so far - only integration tested thoroughly.

php vendor/bin/phpunit tests

Usage

// create a board o size 8x8
$board = new Board(8);

$finder = new ShortestPathFinder(
    new Knight(), // set a piece that is used
    $board,
    new SquareArrayInterpreter(), // set how you want to get the result as
);

// the strategy to find the path
$finder->setStrategy(new TreeStrategy());

// result will depend on the interpreter, in this case it will return all the visited squares
$result = $finder->findShortestPath(
    $board->getSquareByChessNotation('A1'),
    $board->getSquareByChessNotation('B3')
);

TODO

  • Debug interpreter shows time and memory consumption.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-04-25