Round-robin schedule generation library for PHP
Round-robin schedule generation reference implementation for PHP 7 licensed under the MIT license
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$scheduleBuilder = new ScheduleBuilder($teams);
$schedule = $scheduleBuilder->build();
or
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$schedule = schedule($teams);
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$rounds = (($count = count($teams)) % 2 === 0 ? $count - 1 : $count) * 2;
$scheduleBuilder = new ScheduleBuilder($teams, $rounds);
$schedule = $scheduleBuilder->build();
or
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$rounds = (($count = count($teams)) % 2 === 0 ? $count - 1 : $count) * 2;
$schedule = schedule($teams, $rounds);
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$scheduleBuilder = new ScheduleBuilder($teams);
$scheduleBuilder->doNotShuffle();
$schedule = $scheduleBuilder->build();
or
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$schedule = schedule($teams, null, false);
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$scheduleBuilder = new ScheduleBuilder($teams);
$scheduleBuilder->shuffle(89);
$schedule = $scheduleBuilder->build();
or
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$schedule = schedule($teams, null, true, 89);
Setup:
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$schedule = schedule($teams, null, true, 89);
or
$scheduleBuilder = new ScheduleBuilder();
$scheduleBuilder->setTeams($teams);
$scheduleBuilder->setRounds(10);
$scheduleBuilder->doNotShuffle();
$schedule = $scheduleBuilder->build();
Loop through:
<?php foreach($schedule as $round => $matchups){ ?>
<h3>Round <?=$round?></h3>
<ul>
<?php foreach($matchups as $matchup) { ?>
<li><?=$matchup[0] ?? '*BYE*'?> vs. <?=$matchup[1] ?? '*BYE*'?></li>
<?php } ?>
</ul>
<?php } ?>
<?php
$scheduleBuilder = new ScheduleBuilder($teams, 10);
$scheduleBuilder->shuffle(18);
$schedule = $scheduleBuilder->build();
?>
<?php foreach($teams as $team) { ?>
<h3><?=$team?></h3>
<ol>
<?php foreach($schedule($team) as $contest) { ?>
<li><?=(($contest['home'] ? '' : '@').($contest['team'] ?? '*BYE*'))?></li>
<?php } ?>
</ol>
<?php } ?>
MIT License
Michael P. Nitowski <[email protected]>