phelix / tournaments
锦标赛管理器
v1.0.2
2020-12-18 12:23 UTC
Requires (Dev)
- phpunit/phpunit: 6.*
This package is auto-updated.
Last update: 2024-09-21 14:12:19 UTC
README
这是一个用于锦标赛管理的PHP软件包
包含的服务
- 排名
- 单败淘汰赛
- 双败淘汰赛
- 循环赛
- 括号分组(循环赛、单败淘汰赛和双败淘汰赛组)
- 锦标赛生成器(即将推出...)
安装
composer require phelix/tournaments
如何测试
该软件包包含示例测试用例。您可以使用以下命令运行测试:
vendor/bin/phpunit test
文档
1. 循环赛中排名
这是所有玩家在给定的循环赛阶段的比赛,即每个玩家都必须与其他所有对手比赛
<?php use Phelix\Tournaments\Leaderboard\RoundRobin; // Sample Results Data. Your data is to be passed to this method in this structure: $results = [ [ "name" => "1.1", // name of the match "scores" => [ ["player_id" => "Taru", "score" => 0], // remember to use uid in player id and not the name as in this sample ["player_id" => "Dan", "score" => 0], ] ], [ "name" => "1.2", "scores" => [ ["player_id" => "Sykes", "score" => 2], ["player_id" => "Phelix", "score" => 0], ] ], [ "name" => "1.3", "scores" => [ ["player_id" => "Taru", "score" => 2], ["player_id" => "Phelix", "score" => 2], ] ], [ "name" => "1.4", "scores" => [ ["player_id" => "Dan", "score" => 2], ["player_id" => "Sykes", "score" => 0], ] ], [ "name" => "1.5", "scores" => [ ["player_id" => "Taru", "score" => 4], ["player_id" => "Sykes", "score" => 5], ] ], [ "name" => "1.6", "scores" => [ ["player_id" => "Phelix", "score" => 0], ["player_id" => "Dan", "score" => 4], ] ] ]; $ranks = RoundRobin::generateStageLeaderboard($results); // process the ranks as per your system needs. print_r($ranks);
1. 单败淘汰赛
这是玩家处于一个单阶段单败淘汰赛中,即你输了,你就会被立即淘汰
<?php use Phelix\Tournaments\Leaderboard\SingleElimination; // Expected data structure with sample $results = [ [ "round" => 1, "matches" => [ [ "name" => "1.1", "scores" => [ ["player_id" => "JP Omondi", "score" => 1], ["player_id" => "Timothy Amahaya", "score" => 0], ] ], [ "name" => "1.2", "scores" => [ ["player_id" => "Taru", "score" => 2], ["player_id" => "Phelix Juma", "score" => 0], ] ], [ "name" => "1.3", "scores" => [ ["player_id" => "Sykes", "score" => 3], ["player_id" => "Joanna", "score" => 4], ] ], [ "name" => "1.4", "scores" => [ ["player_id" => "Calvin", "score" => 2], ["player_id" => "Daniel", "score" => 5], ] ], [ "name" => "1.5", "scores" => [ ["player_id" => "Michael", "score" => 2], ["player_id" => "Dan", "score" => 0], ] ], [ "name" => "1.6", "scores" => [ ["player_id" => "Sindani", "score" => 3], ["player_id" => "Jordan", "score" => 2], ] ] ] ], [ "round" => 2, "matches" => [ [ "name" => "2.1", "scores" => [ ["player_id" => "JP Omondi", "score" => 2], ["player_id" => "Joanna", "score" => 0], ] ], [ "name" => "2.2", "scores" => [ ["player_id" => "Michael", "score" => 0], ["player_id" => "Daniel", "score" => 2], ] ], [ "name" => "2.3", "scores" => [ ["player_id" => "Sindani", "score" => 3], ["player_id" => "Taru", "score" => 0], ] ] ] ] ]; $ranks = SingleElimination::generateStageLeaderboard($results); // process the ranks as per your system needs print_r($ranks);
3. 双败淘汰赛
在需要单阶段锦标赛排名且玩家处于双败淘汰赛的情况下使用
<?php use Phelix\Tournaments\Leaderboard\DoubleElimination; // Sample data showing the expected data structure $results = [ [ "bracket" => "WB", "rounds" => [ [ "round" => 1, "matches" => [ [ "name" => "1.1", "scores" => [ ["player_id" => "Dan", "score" => 2], ["player_id" => "Taru", "score" => 0], ] ], [ "name" => "1.2", "scores" => [ ["player_id" => "Michael", "score" => 1], ["player_id" => "JP", "score" => 0], ] ], [ "name" => "1.3", "scores" => [ ["player_id" => "Phelix", "score" => 0], ["player_id" => "Sykes", "score" => 2], ] ], [ "name" => "1.4", "scores" => [ ["player_id" => "Calvin", "score" => 1], ["player_id" => "Jordan", "score" => 4], ] ] ] ], [ "round" => 2, "matches" => [ [ "name" => "2.1", "scores" => [ ["player_id" => "Jordan", "score" => 2], ["player_id" => "Sykes", "score" => 1], ] ], [ "name" => "2.2", "scores" => [ ["player_id" => "Michael", "score" => 0], ["player_id" => "Dan", "score" => 5], ] ] ] ], [ "round" => 3, "matches" => [ [ "name" => "3.1", "scores" => [ ["player_id" => "Dan", "score" => 1], ["player_id" => "Jordan", "score" => 0], ] ] ] ], [ "round" => 4, "matches" => [ [ "name" => "4.1", "scores" => [ ["player_id" => "Dan", "score" => 2], ["player_id" => "Phelix", "score" => 4], ] ] ] ] ] ], [ "bracket" => "LB", "rounds" => [ [ "round" => 1, "matches" => [ [ "name" => "1.1L", "scores" => [ ["player_id" => "Phelix", "score" => 1], ["player_id" => "Taru", "score" => 0], ] ], [ "name" => "1.2L", "scores" => [ ["player_id" => "JP", "score" => 2], ["player_id" => "Calvin", "score" => 0], ] ] ] ], [ "round" => 2, "matches" => [ [ "name" => "2.1L", "scores" => [ ["player_id" => "Sykes", "score" => 2], ["player_id" => "Phelix", "score" => 3], ] ], [ "name" => "2.2L", "scores" => [ ["player_id" => "Michael", "score" => 2], ["player_id" => "JP", "score" => 0], ] ] ] ], [ "round" => 3, "matches" => [ [ "name" => "3.1L", "scores" => [ ["player_id" => "Phelix", "score" => 2], ["player_id" => "Michael", "score" => 0], ] ] ] ], [ "round" => 4, "matches" => [ [ "name" => "4.1L", "scores" => [ ["player_id" => "Jordan", "score" => 2], ["player_id" => "Phelix", "score" => 3], ] ] ] ] ] ] ]; $ranks = DoubleElimination::generateStageLeaderboard($results); // Process the ranks as per your system needs print_r($ranks);
4. 池
如果在一个阶段内,玩家被放入不同的组/池(例如,A池、B池等),则使用此功能
池可以实现循环赛、单败淘汰赛或双败淘汰赛的括号
因此,池内部的数据结构类似于其括号类型的数据结构,因此上面显示的每种锦标赛类型的数据结构就足够了
<?php use Phelix\Tournaments\Leaderboard\DuelPool; /** * This is sample data showing the data structure * This sample is for Round Robin Groups * As can be seen, the data structure for the "rounds" section resembles that one for round robin bracket shown above * You must modify this section depending on the group type eg for SE, you use the SE structure shown in the SE section above */ $results = [ [ "group" => 1, "type" => "RR", "rounds" => [ [ "name" => "1.1", "scores" => [ ["player_id" => "Timothy", "score" => 0], ["player_id" => "Michael", "score" => 0], ] ], [ "name" => "1.2", "scores" => [ ["player_id" => "Timothy", "score" => 2], ["player_id" => "Jude", "score" => 0], ] ], [ "name" => "1.3", "scores" => [ ["player_id" => "Michael", "score" => 2], ["player_id" => "Jude", "score" => 3], ] ] ] ], [ "group" => 2, "type" => "RR", "rounds" => [ [ "name" => "1.1", "scores" => [ ["player_id" => "Dan", "score" => 1], ["player_id" => "Sindani", "score" => 1], ] ], [ "name" => "1.2", "scores" => [ ["player_id" => "Dan", "score" => 3], ["player_id" => "JP", "score" => 0], ] ], [ "name" => "1.3", "scores" => [ ["player_id" => "Sindani", "score" => 4], ["player_id" => "JP", "score" => 3], ] ] ] ] ]; $ranks = DuelPool::generateStageLeaderboard($results); // Process the ranks print_r($ranks);
5. 多阶段对决锦标赛
使用此功能为整个锦标赛生成总排名
这可以在玩家从一级进展到下一级时使用
每个阶段可以实施循环赛、单败淘汰赛、双败淘汰赛或括号分组。由于每个阶段都是独立的,因此每个阶段可以有不同的括号类型。
<?php use Phelix\Tournaments\Leaderboard\DuelTournament; // Sample data showing the expected data structure. // This sample is for stage 1 implementing single elimination after which the three winners // progress to stage 2 that implements round robin $results = [ [ "stage" => 1, "type" => "SE", "rounds" => [ [ "round" => 1, "matches" => [ [ "name" => "1.1", "scores" => [ ["player_id" => "Dan", "score" => 2], ["player_id" => "Kevin", "score" => 0], ] ], [ "name" => "1.2", "scores" => [ ["player_id" => "Taru", "score" => 0], ["player_id" => "JP", "score" => 2], ] ], [ "name" => "1.3", "scores" => [ ["player_id" => "Sykes", "score" => 1], ["player_id" => "Michael", "score" => 2], ] ], [ "name" => "1.4", "scores" => [ ["player_id" => "Calvin", "score" => 2], ["player_id" => "Timothy", "score" => 3], ] ], [ "name" => "1.5", "scores" => [ ["player_id" => "Jordan", "score" => 5], ["player_id" => "Aldo", "score" => 3], ] ], [ "name" => "1.6", "scores" => [ ["player_id" => "Jude", "score" => 1], ["player_id" => "Phelix", "score" => 0], ] ] ] ], [ "round" => 2, "matches" => [ [ "name" => "2.1", "scores" => [ ["player_id" => "Timothy", "score" => 2], ["player_id" => "JP", "score" => 1], ] ], [ "name" => "2.2", "scores" => [ ["player_id" => "Michael", "score" => 2], ["player_id" => "Dan", "score" => 0], ] ], [ "name" => "2.3", "scores" => [ ["player_id" => "Jordan", "score" => 0], ["player_id" => "Jude", "score" => 3], ] ] ] ] ] ], [ "stage" => 2, "type" => "RR", "rounds" => [ [ "name" => "1.1", "scores" => [ ["player_id" => "Timothy", "score" => 0], ["player_id" => "Michael", "score" => 0], ] ], [ "name" => "1.2", "scores" => [ ["player_id" => "Timothy", "score" => 2], ["player_id" => "Jude", "score" => 0], ] ], [ "name" => "1.3", "scores" => [ ["player_id" => "Michael", "score" => 2], ["player_id" => "Jude", "score" => 3], ] ] ] ] ]; $ranks = DuelTournament::generateStageLeaderboard($results); // Process the ranks as per your system needs print_r($ranks);
6. 大逃杀
使用此功能在大逃杀比赛中生成排名
<?php use Phelix\Tournaments\Leaderboard\BattleRoyale; // Sample data showing the expected data structure $results = [ ["player_id" => "Mike", "position" => 1, "kills" => 20], ["player_id" => "Allan", "position" => 2, "kills" => 12], ["player_id" => "Daniel", "position" => 3, "kills" => 15], ["player_id" => "Sidney", "position" => 4, "kills" => 6], ["player_id" => "JP", "position" => 5, "kills" => 3], ]; $ranks = BattleRoyale::generateStageLeaderboard($results); // Process the ranks as per your system needs print_r($ranks);
7. 大逃杀(池)
使用此功能在大逃杀比赛中生成排名,其中玩家被分到不同的池中
这可以在玩家从一级进展到下一级时使用
每个阶段可以实施循环赛、单败淘汰赛、双败淘汰赛或括号分组。由于每个阶段都是独立的,因此每个阶段可以有不同的括号类型。
<?php use Phelix\Tournaments\Leaderboard\BattleRoyalePool; // Sample data showing the expected data structure $results = [ [ "group" => 1, "matches" => [ ["player_id" => "Mike", "position" => 1, "kills" => 20], ["player_id" => "Allan", "position" => 2, "kills" => 12], ["player_id" => "Daniel", "position" => 3, "kills" => 15], ["player_id" => "Sidney", "position" => 4, "kills" => 6], ["player_id" => "JP", "position" => 5, "kills" => 4], ] ], [ "group" => 2, "matches" => [ ["player_id" => "Taru", "position" => 1, "kills" => 200], ["player_id" => "Jordan", "position" => 2, "kills" => 120], ["player_id" => "JP", "position" => 3, "kills" => 150], ["player_id" => "Timothy", "position" => 4, "kills" => 60], ["player_id" => "Calvin", "position" => 5, "kills" => 20], ] ] ]; $ranks = BattleRoyalePool::generateStageLeaderboard($results); // Process the ranks as per your system needs print_r($ranks);
8. 大逃杀锦标赛
使用此功能在大逃杀锦标赛中生成排名
这可以在玩家从一级进展到下一级时使用
每个阶段可以实施大逃杀或大逃杀池。由于每个阶段都是独立的,因此每个阶段可以有不同的括号类型。
<?php use Phelix\Tournaments\Leaderboard\BattleRoyaleTournament; // Sample data showing the expected data structure $results = [ [ "stage" => 1, "type" => "PBR", // battle royale pool "rounds" => [ [ "group" => 1, "matches" => [ ["player_id" => "Mike", "position" => 1, "kills" => 20], ["player_id" => "Allan", "position" => 2, "kills" => 12], ["player_id" => "Daniel", "position" => 3, "kills" => 15], ["player_id" => "Sidney", "position" => 4, "kills" => 6], ["player_id" => "JP", "position" => 5, "kills" => 3], ] ], [ "group" => 2, "matches" => [ ["player_id" => "Taru", "position" => 1, "kills" => 200], ["player_id" => "Jordan", "position" => 2, "kills" => 120], ["player_id" => "Phelix", "position" => 3, "kills" => 150], ["player_id" => "Timothy", "position" => 4, "kills" => 60], ["player_id" => "Calvin", "position" => 5, "kills" => 30], ] ] ] ], [ "stage" => 2, "type" => "BR", // battle royale "rounds" => [ ["player_id" => "Mike", "position" => 1, "kills" => 345], ["player_id" => "Allan", "position" => 2, "kills" => 235], ["player_id" => "Taru", "position" => 3, "kills" => 79], ["player_id" => "Jordan", "position" => 4, "kills" => 35] ] ] ]; $ranks = BattleRoyaleTournament::generateStageLeaderboard($results); // Process the ranks as per your system needs print_r($ranks);
变更日志
- v1.0.0 首次发布
- v1.0.1 在循环赛中添加了包含抽签点的修复
- v1.0.2 添加了大逃杀比赛
致谢
- 来自 Kuza Lab Ltd 的 Phelix Juma(jumaphelix@kuzalab.com)