2017 © Pedro Peláez
 

library round-robin

Round-robin schedule generation implementation in PHP

image

mnito/round-robin

Round-robin schedule generation implementation in PHP

  • Monday, September 4, 2017
  • by mnito
  • Repository
  • 4 Watchers
  • 12 Stars
  • 111 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 2 Open issues
  • 5 Versions
  • 44 % Grown

The README.md

round-robin

Build Status, (*1)

Round-robin schedule generation reference implementation for PHP 7 licensed under the MIT license, (*2)

Features

  • Efficient schedule generation enabled by an efficient round-robin rotation function
  • Ability to generate an arbitrary number of rounds
  • Support for any number of teams by adding a bye for odd-numbered team counts
  • Simple, concise implementation for easy analysis of the algorithm
  • Unit tested
  • Documented
  • Modern PHP 7 code
  • Object-oriented and procedural APIs

Basic Usage

Generating Common Schedules

Generate a random schedule where each player meets every other player once:

$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$scheduleBuilder = new ScheduleBuilder($teams);
$schedule = $scheduleBuilder->build();

or, (*3)

$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$schedule = schedule($teams);

Generate a random home-away schedule where each player meets every other player twice, once at home and once away, using the $rounds integer parameter:

$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, (*4)

$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$rounds = (($count = count($teams)) % 2 === 0 ? $count - 1 : $count) * 2;
$schedule = schedule($teams, $rounds);

Generate a schedule without randomly shuffling the teams using the $shuffle boolean parameter:

$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$scheduleBuilder = new ScheduleBuilder($teams);
$scheduleBuilder->doNotShuffle();
$schedule = $scheduleBuilder->build();

or, (*5)

$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$schedule = schedule($teams, null, false);

Use your own seed with the $seed integer parameter for predetermined shuffling:

$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$scheduleBuilder = new ScheduleBuilder($teams);
$scheduleBuilder->shuffle(89);
$schedule = $scheduleBuilder->build();

or, (*6)

$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$schedule = schedule($teams, null, true, 89);

Looping Through A Schedule

Looping Through the Full Schedule

Setup:, (*7)

$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$schedule = schedule($teams, null, true, 89);

or, (*8)

$scheduleBuilder = new ScheduleBuilder();
$scheduleBuilder->setTeams($teams);
$scheduleBuilder->setRounds(10);
$scheduleBuilder->doNotShuffle();
$schedule = $scheduleBuilder->build();

Loop through:, (*9)

<?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 } ?>

Looping Through Team Schedules

shuffle(18);
$schedule = $scheduleBuilder->build();
?>



    <h3><?=$team?></h3>
    <ol>
    <?php foreach($schedule($team) as $contest) { ?>
        <li><?=(($contest['home'] ? '' : '@').($contest['team'] ?? '*BYE*'))?></li>
    <?php } ?>
    </ol>

License

MIT License, (*10)

Author

Michael P. Nitowski mike@nitow.ski" title="See online mike@nitow.ski">mike@nitow.ski, (*11)

The Versions

04/09 2017

dev-master

9999999-dev https://github.com/mnito/round-robin

Round-robin schedule generation implementation in PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

schedule generation round round-robin robin

04/09 2017

v1.2.0

1.2.0.0 https://github.com/mnito/round-robin

Round-robin schedule generation implementation in PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

schedule generation round round-robin robin

27/09 2016

v1.1.0

1.1.0.0 https://github.com/mnito/round-robin

Round-robin schedule generation implementation in PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

schedule generation round round-robin robin

09/09 2016

v1.0.1

1.0.1.0 https://github.com/mnito/round-robin

Round-robin schedule generation implementation in PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

schedule generation round round-robin robin

09/09 2016

v1.0.0

1.0.0.0 https://github.com/mnito/round-robin

Round-robin schedule generation implementation in PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

schedule generation round round-robin robin