|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Xoco70\KendoTournaments\TreeGen; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
|
6
|
|
|
use Xoco70\KendoTournaments\Models\Championship; |
|
7
|
|
|
|
|
8
|
|
|
class PlayOffTreeGen extends TreeGen |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Calculate the Byes need to fill the Championship Tree. |
|
12
|
|
|
* @param Championship $championship |
|
13
|
|
|
* @return Collection |
|
14
|
|
|
*/ |
|
15
|
|
|
protected function getByeGroup(Championship $championship, $fighters) |
|
16
|
|
|
{ |
|
17
|
|
|
$fighterCount = $fighters->count(); |
|
18
|
|
|
$preliminaryGroupSize = $championship->settings->preliminaryGroupSize; |
|
19
|
|
|
$treeSize = $this->getTreeSize($fighterCount, $preliminaryGroupSize); |
|
20
|
|
|
$byeCount = $treeSize - $fighterCount; |
|
21
|
|
|
|
|
22
|
|
|
return $this->createNullsGroup($byeCount); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Create empty groups for direct Elimination Tree |
|
28
|
|
|
* @param $numFighters |
|
29
|
|
|
*/ |
|
30
|
|
|
public function pushEmptyGroupsToTree($numFighters) |
|
31
|
|
|
{ |
|
32
|
|
|
$numFightersEliminatory = $numFighters / $this->championship->getSettings()->preliminaryGroupSize * 2; |
|
33
|
|
|
// We calculate how much rounds we will have |
|
34
|
|
|
$numRounds = intval(log($numFightersEliminatory, 2)); |
|
35
|
|
|
$this->pushGroups($numRounds, $numFightersEliminatory); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Chunk Fighters into groups for fighting, and optionnaly shuffle |
|
40
|
|
|
* @param $round |
|
41
|
|
|
* @param $shuffle |
|
42
|
|
|
* @param $fightersByEntity |
|
43
|
|
|
* @return mixed |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function chunkAndShuffle($round, $shuffle, $fightersByEntity) |
|
|
|
|
|
|
46
|
|
|
{ |
|
47
|
|
|
if ($this->championship->hasPreliminary()) { |
|
48
|
|
|
$fightersGroup = $fightersByEntity->chunk($this->settings->preliminaryGroupSize); |
|
49
|
|
|
if ($shuffle) { |
|
50
|
|
|
$fightersGroup = $fightersGroup->shuffle(); |
|
51
|
|
|
} |
|
52
|
|
|
} else { // Round Robin |
|
53
|
|
|
$fightersGroup = $fightersByEntity->chunk($fightersByEntity->count()); |
|
54
|
|
|
} |
|
55
|
|
|
return $fightersGroup; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.