avantar/bracket-generator

Simple Bracket Generator

0.1.1 2020-12-31 11:55 UTC

This package is auto-updated.

Last update: 2024-04-29 04:40:31 UTC


README

Simple Bracket Generator

codecov Maintainability

Requirements:

  1. PHP 7.4+

How to use:

  1. Create new instance of the Bracket Generator:
$generator = new \BracketGenerator\Generator();
  1. Use the generate method to get array with bracket games. You need to pass the number of tournament participants:
$generator->generate(8);
  1. You should get an array of games:
[
    [
        'id' => 1,
        'round' => 1,
        'game_in_round' => 1,
        'next_game_id' => 5
    ],
    [
        'id' => 2,
        'round' => 1,
        'game_in_round' => 2,
        'next_game_id' => 5
    ],
    [
        'id' => 3,
        'round' => 1,
        'game_in_round' => 3,
        'next_game_id' => 6
    ],
    [
        'id' => 4,
        'round' => 1,
        'game_in_round' => 4,
        'next_game_id' => 6
    ],
    [
        'id' => 5,
        'round' => 2,
        'game_in_round' => 1,
        'next_game_id' => 7
    ],
    [
        'id' => 6,
        'round' => 2,
        'game_in_round' => 2,
        'next_game_id' => 7
    ],
    [
        'id' => 7,
        'round' => 3,
        'game_in_round' => 1,
        'next_game_id' => null
    ],
];

For now, the library is able to generate only a single elimination bracket. Feel free to contribute. Thanks!