Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mnito/round-robin
Round-robin schedule generation library for PHP
https://github.com/mnito/round-robin
generator home-away php7 round-robin schedule scheduler tournament
Last synced: 5 days ago
JSON representation
Round-robin schedule generation library for PHP
- Host: GitHub
- URL: https://github.com/mnito/round-robin
- Owner: mnito
- License: mit
- Created: 2016-09-07T19:02:33.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2021-09-12T14:24:59.000Z (about 3 years ago)
- Last Synced: 2024-10-15T01:21:39.998Z (about 1 month ago)
- Topics: generator, home-away, php7, round-robin, schedule, scheduler, tournament
- Language: PHP
- Size: 56.6 KB
- Stars: 61
- Watchers: 7
- Forks: 14
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# round-robin
[![Build Status](https://app.travis-ci.com/mnito/round-robin.svg)](https://app.travis-ci.com/mnito/round-robin)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:
```php
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$scheduleBuilder = new ScheduleBuilder($teams);
$schedule = $scheduleBuilder->build();
```or
```php
$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:
```php
$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
```php
$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:
```php
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$scheduleBuilder = new ScheduleBuilder($teams);
$scheduleBuilder->doNotShuffle();
$schedule = $scheduleBuilder->build();
```or
```php
$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:
```php
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$scheduleBuilder = new ScheduleBuilder($teams);
$scheduleBuilder->shuffle(89);
$schedule = $scheduleBuilder->build();
```
or```php
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$schedule = schedule($teams, null, true, 89);
```### Looping Through A Schedule
#### Looping Through the Full Schedule
Setup:
```php
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$schedule = schedule($teams, null, true, 89);
```or
```php
$scheduleBuilder = new ScheduleBuilder();
$scheduleBuilder->setTeams($teams);
$scheduleBuilder->setRounds(10);
$scheduleBuilder->doNotShuffle();
$schedule = $scheduleBuilder->build();
```Loop through:
```php
$matchups){ ?>
Round =$round?>
- =$matchup[0] ?? '*BYE*'?> vs. =$matchup[1] ?? '*BYE*'?>
```
#### Looping Through Team Schedules
```php
shuffle(18);
$schedule = $scheduleBuilder->build();
?>
=$team?>
- =(($contest['home'] ? '' : '@').($contest['team'] ?? '*BYE*'))?>
```
## License
MIT License
## Author
Michael P. Nitowski <[[email protected]](mailto:[email protected])>