Tournament Generator

DoubleElimination extends Tournament implements Preset

Double elimination generator

Tags
author

Tomáš Vojík vojik@wboy.cz

since
0.1

Interfaces, Classes and Traits

Preset
Interface for tournament presets

Table of Contents

$container  : HierarchyContainer
$expectedCategoryWait  : int
$games  : GameContainer
$id  : string|int
$name  : string
$teams  : TeamContainer
$allowSkip  : bool
$expectedGameWait  : int
$expectedPlay  : int
$expectedRoundWait  : int
__construct()  : mixed
__toString()  : string
addCategory()  : $this
Add one or more category to object
addGameContainer()  : WithGames
Add a child container for games
addRound()  : $this
Adds round to the category
addTeam()  : WithTeams
Add one or more teams into the object.
addTeamContainer()  : WithTeams
Add a child container for games
allowSkip()  : $this
Allows round skipping
category()  : Category
Creates a new category and adds it to the object
disallowSkip()  : $this
Disallow round skipping
export()  : ExporterInterface
Prepares a general hierarchy exporter for this hierarchy class
filterTeams()  : array<string|int, mixed>
Filter teams using the specified filters
generate()  : $this
Generate all the games
genGamesSimulate()  : array<string|int, Game>|int
Simulate all games as they would be played in reality - with dummy teams
genGamesSimulateReal()  : int|array<string|int, Game>
Simulate all games as they would be played in reality - with real teams
getCategories()  : array<string|int, Category>
Get all categories
getCategoryWait()  : int
Get the wait time between categories
getContainer()  : HierarchyContainer
Get the hierarchy container
getGameContainer()  : GameContainer
Get the container for games
getGames()  : array<string|int, Game>
Get all tournament games
getGameWait()  : int
Get wait time between games
getGroups()  : array<string|int, Group>
Get all groups in this object
getId()  : string|int
Gets the unique identifier of the object
getName()  : string
Gets the name of the object
getPlay()  : int
Get play time for one game
getRounds()  : array<string|int, Round>
Get all rounds in this category
getRoundWait()  : int
Get wait time between rounds
getSkip()  : bool
Getter for round skipping
getTeamContainer()  : TeamContainer
Get the container for games
getTeams()  : array<string|int, Team>
Get all teams in the object
getTournamentTime()  : int
Get the whole tournament time
insertIntoContainer()  : $this
Insert into hierarchical container
printBracket()  : string
queryCategories()  : ContainerQuery
Get categories container query
queryGroups()  : ContainerQuery
Get groups container query
queryRounds()  : ContainerQuery
Get rounds container query
round()  : Round
Creates a new round and adds it to the category
setCategoryWait()  : $this
Set the wait time between categories
setGameAutoincrementId()  : WithGames
Sets a new autoincrement value (start) for the generated games
setGameWait()  : $this
Set wait time between games
setId()  : self
Sets the unique identifier of the object
setName()  : self
Sets the name of the object
setPlay()  : $this
Set play time for one game
setResults()  : Game|null
Set the game's results
setRoundWait()  : $this
Set wait time between rounds
setSkip()  : $this
Set round skipping
sortTeams()  : array<string|int, Team>
Sort the teams by their score/points
splitTeams()  : $this
Split teams into its Groups
team()  : Team
Create a new team and add it into the object
calcByes()  : float|int
Calculate how many teams should skip the first round
generateLosingSide()  : void
Generate the "losing side" - same as Single elimination
generateWinSide()  : void
Generate the winning side (Single elimination with progressions into the losing side)

Properties

$expectedCategoryWait

protected int $expectedCategoryWait = 0

$id

protected string|int $id

$name

protected string $name = ''

$expectedGameWait

private int $expectedGameWait = 0

$expectedRoundWait

private int $expectedRoundWait = 0

Methods

__construct()

public __construct([string $name = '' ]) : mixed
Parameters
$name : string = ''
Return values
mixed —

__toString()

public __toString() : string
Return values
string —

Name of the object

addCategory()

Add one or more category to object

public addCategory(Category ...$categories) : $this
Parameters
$categories : Category

Category objects

Return values
$this —

addRound()

Adds round to the category

public addRound(Round ...$rounds) : $this
Parameters
$rounds : Round

One or more round objects

Return values
$this —

allowSkip()

Allows round skipping

public allowSkip() : $this
Return values
$this —

category()

Creates a new category and adds it to the object

public category([string $name = '' ][, string|int|null $id = null ]) : Category
Parameters
$name : string = ''

New category name

$id : string|int|null = null

Id of the new category - if omitted -> it is generated automatically as unique string

Return values
Category —

New category

disallowSkip()

Disallow round skipping

public disallowSkip() : $this
Return values
$this —

filterTeams()

Filter teams using the specified filters

public filterTeams(array<string|int, mixed> &$teams, array<string|int, TeamFilter>|array<string|int, array<string|int, TeamFilter>> $filters) : array<string|int, mixed>
Parameters
$teams : array<string|int, mixed>

Teams to filter through

$filters : array<string|int, TeamFilter>|array<string|int, array<string|int, TeamFilter>>

Filters to use

Tags
throws
Exception
Return values
array<string|int, mixed> —

generate()

Generate all the games

public generate() : $this
Tags
throws
Exception
Return values
$this —

genGamesSimulate()

Simulate all games as they would be played in reality - with dummy teams

public genGamesSimulate([bool $returnTime = false ]) : array<string|int, Game>|int
Parameters
$returnTime : bool = false

If true - return the expected play time

Tags
throws
Exception
Return values
array<string|int, Game>|int —

Generated games, or expected play time

genGamesSimulateReal()

Simulate all games as they would be played in reality - with real teams

public genGamesSimulateReal([bool $returnTime = false ]) : int|array<string|int, Game>
Parameters
$returnTime : bool = false

If true - return the expected play time

Tags
throws
Exception
Return values
int|array<string|int, Game> —

Generated games, or expected play time

getCategoryWait()

Get the wait time between categories

public getCategoryWait() : int
Return values
int —

getGames()

Get all tournament games

public getGames() : array<string|int, Game>
Return values
array<string|int, Game> —

getGameWait()

Get wait time between games

public getGameWait() : int
Return values
int —

getGroups()

Get all groups in this object

public getGroups() : array<string|int, Group>
Return values
array<string|int, Group> —

getId()

Gets the unique identifier of the object

public getId() : string|int
Return values
string|int —

Unique identifier of the object

getName()

Gets the name of the object

public getName() : string
Return values
string —

Name of the object

getPlay()

Get play time for one game

public getPlay() : int
Return values
int —

getRounds()

Get all rounds in this category

public getRounds() : array<string|int, Round>
Return values
array<string|int, Round> —

getRoundWait()

Get wait time between rounds

public getRoundWait() : int
Return values
int —

getSkip()

Getter for round skipping

public getSkip() : bool
Return values
bool —

getTeams()

Get all teams in the object

public getTeams([bool $ordered = false ][, string|null $ordering = Constants::POINTS ][, array<string|int, TeamFilter>|array<string|int, array<string|int, TeamFilter>> $filters = [] ]) : array<string|int, Team>
Parameters
$ordered : bool = false

If true - order the teams by their score/points

$ordering : string|null = Constants::POINTS

What to order the teams by - Constants::POINTS, Constants::SCORE

$filters : array<string|int, TeamFilter>|array<string|int, array<string|int, TeamFilter>> = []

Filters to filter the returned teams (ex. if you only want to get the first 3 teams)

Tags
throws
Exception
Return values
array<string|int, Team> —

getTournamentTime()

Get the whole tournament time

public getTournamentTime() : int
Return values
int —

insertIntoContainer()

Insert into hierarchical container

public insertIntoContainer(Base $object) : $this
Parameters
$object : Base
Tags
post

Object is added to hierarchy

post

If the object has teams -> add other team container to hierarchy

post

If the object has games -> add other game container to hierarchy

throws
Exception
Return values
$this —

round()

Creates a new round and adds it to the category

public round([string $name = '' ][, string|int|null $id = null ]) : Round
Parameters
$name : string = ''

Round name

$id : string|int|null = null

Round id - if omitted -> it is generated automatically as unique string

Return values
Round —

The newly created round

setCategoryWait()

Set the wait time between categories

public setCategoryWait(int $wait) : $this
Parameters
$wait : int
Return values
$this —

setGameAutoincrementId()

Sets a new autoincrement value (start) for the generated games

public setGameAutoincrementId(int $id) : WithGames
Parameters
$id : int

Id - probably from the database

Tags
warning

Do this on the top-level hierarchy element (Tournament class) or else, it might be reset later

post

Propagates the value to all child hierarchy objects

see
GameContainer::setAutoIncrement()
since
0.5
Return values
WithGames —

setGameWait()

Set wait time between games

public setGameWait(int $wait) : $this
Parameters
$wait : int
Return values
$this —

setId()

Sets the unique identifier of the object

public setId(string|int $id) : self
Parameters
$id : string|int

Unique identifier of the object

Tags
throws
InvalidArgumentException

if the provided argument is not of type 'string' or 'int'

Return values
self —

setName()

Sets the name of the object

public setName(string $name) : self
Parameters
$name : string

Name of the object

Return values
self —

setPlay()

Set play time for one game

public setPlay(int $play) : $this
Parameters
$play : int
Return values
$this —

setResults()

Set the game's results

public setResults(array<string|int, int> $results) : Game|null

Results is an array of [teamId => teamScore] key-value pairs. This method will look for a game with given teams and try to set the first not played.

Parameters
$results : array<string|int, int>

array of [teamId => teamScore] key-value pairs

Tags
throws
Exception
Return values
Game|null —

setRoundWait()

Set wait time between rounds

public setRoundWait(int $wait) : $this
Parameters
$wait : int
Return values
$this —

setSkip()

Set round skipping

public setSkip(bool $skip) : $this
Parameters
$skip : bool
Return values
$this —

sortTeams()

Sort the teams by their score/points

public sortTeams([string|null $ordering = Constants::POINTS ][, array<string|int, TeamFilter>|array<string|int, array<string|int, TeamFilter>> $filters = [] ]) : array<string|int, Team>
Parameters
$ordering : string|null = Constants::POINTS

What to order the teams by - Constants::POINTS, Constants::SCORE

$filters : array<string|int, TeamFilter>|array<string|int, array<string|int, TeamFilter>> = []

Filters to filter the returned teams (ex. if you only want to get the first 3 teams)

Tags
throws
Exception
Return values
array<string|int, Team> —

splitTeams()

Split teams into its Groups

public splitTeams(Round ...$wheres) : $this
Parameters
$wheres : Round
Tags
throws
Exception
noinspection

CallableParameterUseCaseInTypeContextInspection

Return values
$this —

team()

Create a new team and add it into the object

public team([string $name = '' ][, string|int|null $id = null ]) : Team
Parameters
$name : string = ''

Name of the new team

$id : string|int|null = null

Id of the new team - if omitted -> it is generated automatically as unique string

Return values
Team —

Newly created team

calcByes()

Calculate how many teams should skip the first round

private calcByes(int $countTeams, int &$nextPow) : float|int
Parameters
$countTeams : int

Total teams

$nextPow : int

Next power of 2

Return values
float|int —

generateLosingSide()

Generate the "losing side" - same as Single elimination

private generateLosingSide(int $roundNum, Round $round, array<string|int, Group> &$allGroups[, array<string|int, Group> $previousLosingGroups = [] ][, array<string|int, mixed> $previousGroups = [] ][, array<string|int, mixed> &$losingGroups = [] ]) : void
Parameters
$roundNum : int

Round number

$round : Round

Round object

$allGroups : array<string|int, Group>

Array of all groups

$previousLosingGroups : array<string|int, Group> = []
$previousGroups : array<string|int, mixed> = []
$losingGroups : array<string|int, mixed> = []
Return values
void —

Last losing group

generateWinSide()

Generate the winning side (Single elimination with progressions into the losing side)

private generateWinSide(int $roundNum, int $byes, int $countTeams, Round $round, array<string|int, Group> &$allGroups, array<string|int, Group> &$groups[, Group|null &$lastWinningGroup = null ][, array<string|int, Group> $previousGroups = [] ]) : void
Parameters
$roundNum : int

Round number

$byes : int

Initial byes

$countTeams : int

Total teams

$round : Round

Round object

$allGroups : array<string|int, Group>

All groups

$groups : array<string|int, Group>

Output groups

$lastWinningGroup : Group|null = null

Last group

$previousGroups : array<string|int, Group> = []

Losing side groups

Return values
void —

Search results