heroyt / tournament-generator
一组用于在PHP中创建多种类型锦标赛赛制的类。
v0.5.5
2023-12-09 13:12 UTC
Requires
- php: >=8.0
Requires (Dev)
- infection/infection: ^0.26
- phpunit/phpunit: ^9.6
README
锦标赛生成器
一组用于生成和操作所有不同类型的锦标赛赛制或自定义赛制的类。
功能
- 创建任何数量类别、轮次、组和队伍的自定义锦标赛赛制
- 定义多种不同条件
- 轻松生成轮次交叉赛
- 使用预定义预设(单败淘汰、双败淘汰、2R2G)生成任何数量队伍的锦标赛
- 生成2到4支队伍在一场比赛中对战的赛制
- 填充你的赛制结果,并获得带有分数的队伍表格
安装
$ composer require heroyt/tournament-generator
基本用法
require 'vendor/autoload.php'; // Create a tournament $tournament = new TournamentGenerator\Tournament('Tournament name'); // Set tournament lengths - could be omitted $tournament ->setPlay(7) // SET GAME TIME TO 7 MINUTES ->setGameWait(2) // SET TIME BETWEEN GAMES TO 2 MINUTES ->setRoundWait(0); // SET TIME BETWEEN ROUNDS TO 0 MINUTES // Create a round and a final round $round = $tournament->round("First's round's name"); $final = $tournament->round("Final's round's name"); // Create 2 groups for the first round $group_1 = $round->group('Round 1') ->setInGame(2) // 2 TEAMS PLAYING AGAINST EACH OTHER ->setType(TournamentGenerator\Constants::ROUND_ROBIN); // ROBIN-ROBIN GROUP $group_2 = $round->group('Round 2') ->setInGame(2) // 2 TEAMS PLAYING AGAINST EACH OTHER ->setType(TournamentGenerator\Constants::ROUND_ROBIN); // ROBIN-ROBIN GROUP // Create a final group $final_group = $final->group('Finale') ->setInGame(2) // 2 TEAMS PLAYING AGAINST EACH OTHER ->setType(TournamentGenerator\Constants::ROUND_ROBIN); // ROBIN-ROBIN GROUP // CREATE 6 TEAMS for ($i=1; $i <= 6; $i++) { $tournament->team('Team '.$i); } // SET PROGRESSIONS FROM GROUP 1 AND 2 TO FINAL GROUP $group_1->progression($final_group, 0, 2); // PROGRESS 2 BEST WINNING TEAMS $group_2->progression($final_group, 0, 2); // PROGRESS 2 BEST WINNING TEAMS // Generate games in the first round $round->genGames(); // Simulate results (or you can fill it with your own real results) $round->simulate(); // Progress best teams from first round to final round $round->progress(); // Generate games in the final round $final->genGames(); // Simulate results (or you can fill it with your own real results) $final->simulate(); // GET ALL TEAMS $teams = $tournament->getTeams(true); // TRUE to get teams ordered by their results
使用模板创建锦标赛
require 'vendor/autoload.php'; // Create a tournament $tournament = new TournamentGenerator\Preset\SingleElimination('Tournament name'); // Set tournament lengths - could be omitted $tournament ->setPlay(7) // SET GAME TIME TO 7 MINUTES ->setGameWait(2) // SET TIME BETWEEN GAMES TO 2 MINUTES ->setRoundWait(0); // SET TIME BETWEEN ROUNDS TO 0 MINUTES // CREATE 6 TEAMS for ($i=1; $i <= 6; $i++) { $tournament->team('Team '.$i); } // GENERATE ALL GAMES $tournament->generate(); // Simulate games $tournament->genGamesSimulate(); // Simulate only games for example to only save bracket to DB $tournament->genGamesSimulateReal(); // Simulate games with results like a real tournament // GET ALL TEAMS $teams = $tournament->getTeams(true); // TRUE to get teams ordered by their results