Coder Social home page Coder Social logo

round-robin's Introduction

round-robin

Build Status

Round-robin schedule generation reference implementation for PHP 7 licensed under the MIT license

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

$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

$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

$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

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

Looping Through A Schedule

Looping Through the Full Schedule

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

Looping Through Team Schedules

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

License

MIT License

Author

Michael P. Nitowski <[email protected]>

round-robin's People

Contributors

mnito avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.