Test Failed
Push — master ( 9aea1c...7949ab )
by Tomáš
02:12
created

Simulator::simulateCategoryReal()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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