philicevic / berger
A tool to create round robin tournament matchups using the Berger tables
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/philicevic/berger
Requires
- php: >=8.2
Requires (Dev)
- phpunit/phpunit: ^11
README
This package allows you to generate round robin tournament matchups based on the Berger tables.
Usage
use Philicevic\Berger\Services\RoundRobin;
// this creates 6 rounds where teams play each other twice
$teams = ['A', 'B', 'C', 'D'];
$matchesAgainstEachOther = 2;
$rounds = RoundRobin::makeFromTeams($teams, $matchesAgainstEachOther);
// or use it step by step
$teams = ['A', 'B', 'C', 'D'];
$rr = RoundRobin::create();
$rr->setTeams($teams);
$rounds = $rr->make();
$rounds will be an array of Round objects.
Round
foreach ($rounds as $round) {
// get array of fixtures
$round->fixtures;
// get number of round
$round->number;
// add fixture to round
$round->addFixture($fixture);
// remove fixture from round by index
$round->removeFixture($index);
// format round as array
$round->toArray();
}
// $round->toArray() will return something like this
[
[
[
'home' => 'A',
'away' => 'C',
'round' => 1,
],
[
'home' => 'B',
'away' => 'D',
'round' => 1,
],
],
[
[
'home' => 'C',
'away' => 'B',
'round' => 2,
],
[
'home' => 'D',
'away' => 'A',
'round' => 2,
],
],
[
[
'home' => 'A',
'away' => 'B',
'round' => 3,
],
[
'home' => 'C',
'away' => 'D',
'round' => 3,
],
],
]
Fixture
Every fixture has two properties.
$fixture->home
$fixture->away
Both contain just the name of the team.
You could also access the teams via the getTeams method.
// returns ["Team A", "Team B"]
$fixture->getTeams()
If you want to swap the places of the teams for a fixture you can also do that.
$fixture->swapTeams()