1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TournamentGenerator\Utilis; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* |
7
|
|
|
*/ |
8
|
|
|
class Simulator |
9
|
|
|
{ |
10
|
|
|
|
11
|
29 |
|
public static function simulateGroup(\TournamentGenerator\Group $group, array $filters = [], bool $reset = true) { |
12
|
29 |
|
foreach ($group->getGames() as $game) { |
13
|
27 |
|
$teams = $game->getTeams(); |
14
|
27 |
|
$results = []; |
15
|
27 |
|
foreach ($teams as $team) { |
16
|
27 |
|
$results[$team->getId()] = floor(rand(0, 500)); |
17
|
|
|
} |
18
|
27 |
|
$game->setResults($results); |
19
|
|
|
} |
20
|
29 |
|
$return = $group->sortTeams(null, $filters); |
21
|
29 |
|
if (!$reset) return $return; |
22
|
5 |
|
foreach ($group->getGames() as $game) { |
23
|
1 |
|
$game->resetResults(); |
24
|
|
|
} |
25
|
5 |
|
return $return; |
26
|
|
|
} |
27
|
|
|
|
28
|
25 |
|
public static function simulateRound(\TournamentGenerator\Round $round) { |
29
|
25 |
|
foreach ($round->getGroups() as $group) { |
30
|
25 |
|
if ($group->isPlayed()) continue; |
31
|
25 |
|
$group->simulate([], false); |
32
|
|
|
} |
33
|
25 |
|
return true; |
34
|
|
|
} |
35
|
|
|
|
36
|
13 |
|
public static function simulateTournament(\TournamentGenerator\Tournament $tournament) { |
37
|
13 |
|
if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) throw new \Exception('There are no rounds or categories to simulate games from.'); |
38
|
|
|
|
39
|
13 |
|
$games = []; |
40
|
|
|
|
41
|
13 |
|
foreach ($tournament->getRounds() as $round) { |
42
|
13 |
|
$games = array_merge($games, $round->genGames()); |
43
|
12 |
|
$round->simulate()->progress(true); |
44
|
|
|
} |
45
|
12 |
|
foreach ($tournament->getRounds() as $round) { |
46
|
12 |
|
$round->resetGames(); |
47
|
|
|
} |
48
|
|
|
|
49
|
12 |
|
return $games; |
50
|
|
|
} |
51
|
|
|
|
52
|
4 |
|
public static function simulateTournamentReal(\TournamentGenerator\Tournament $tournament) { |
53
|
4 |
|
$games = []; |
54
|
4 |
|
if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) throw new \Exception('There are no rounds or categories to simulate games from.'); |
55
|
|
|
|
56
|
4 |
|
foreach ($tournament->getRounds() as $round) { |
57
|
4 |
|
$games = array_merge($games, $round->genGames()); |
58
|
4 |
|
$round->simulate(); |
59
|
4 |
|
$round->progress(); |
60
|
|
|
} |
61
|
4 |
|
return $games; |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
public static function simulateCategory(\TournamentGenerator\Category $category) { |
65
|
1 |
|
if (count($category->getRounds()) === 0) throw new \Exception('There are no rounds to simulate games from.'); |
66
|
|
|
|
67
|
1 |
|
$games = []; |
68
|
|
|
|
69
|
1 |
|
foreach ($category->getRounds() as $round) { |
70
|
1 |
|
$games = array_merge($games, $round->genGames()); |
71
|
1 |
|
$round->simulate()->progress(true); |
72
|
|
|
} |
73
|
1 |
|
foreach ($category->getRounds() as $round) { |
74
|
1 |
|
$round->resetGames(); |
75
|
|
|
} |
76
|
|
|
|
77
|
1 |
|
return $games; |
78
|
|
|
} |
79
|
|
|
|
80
|
1 |
|
public static function simulateCategoryReal(\TournamentGenerator\Category $category) { |
81
|
1 |
|
$games = []; |
82
|
1 |
|
if (count($category->getRounds()) === 0) throw new \Exception('There are no rounds to simulate games from.'); |
83
|
|
|
|
84
|
1 |
|
foreach ($category->getRounds() as $round) { |
85
|
1 |
|
$games = array_merge($games, $round->genGames()); |
86
|
1 |
|
$round->simulate(); |
87
|
1 |
|
$round->progress(); |
88
|
|
|
} |
89
|
1 |
|
return $games; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
} |
93
|
|
|
|