@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace App\Lib\DsManager\Models; |
4 | 4 | |
5 | -use App\Lib\DsManager\Helpers\Randomizer; |
|
5 | +use App\Lib\DsManager\Helpers\Randomizer; |
|
6 | 6 | use App\Lib\Helpers\Config; |
7 | 7 | |
8 | 8 |
@@ -11,164 +11,164 @@ |
||
11 | 11 | */ |
12 | 12 | class Match extends DsManagerModel |
13 | 13 | { |
14 | - /** |
|
15 | - * @var Team |
|
16 | - */ |
|
17 | - private $homeTeam; |
|
18 | - /** |
|
19 | - * @var Team |
|
20 | - */ |
|
21 | - private $awayTeam; |
|
22 | - |
|
23 | - /** |
|
24 | - * Match constructor. |
|
25 | - * @param Team $home |
|
26 | - * @param Team $away |
|
27 | - */ |
|
28 | - public function __construct(Team $home, Team $away) |
|
29 | - { |
|
30 | - $this->homeTeam = $home; |
|
31 | - $this->awayTeam = $away; |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * @return MatchResult |
|
36 | - */ |
|
37 | - public function simulate() |
|
38 | - { |
|
39 | - $homePoints = $this->homeTeam->getAvgSkill(); |
|
40 | - $awayPoints = $this->awayTeam->getAvgSkill(); |
|
41 | - |
|
42 | - $homePoints += $this->malusModule( |
|
43 | - $this->homeTeam->coach->favouriteModule, |
|
44 | - $this->homeTeam->playersPerRoleArray() |
|
45 | - ); |
|
46 | - $awayPoints += $this->malusModule( |
|
47 | - $this->awayTeam->coach->favouriteModule, |
|
48 | - $this->awayTeam->playersPerRoleArray() |
|
49 | - ); |
|
50 | - |
|
51 | - $goalHome = 0; |
|
52 | - $goalAway = 0; |
|
53 | - |
|
54 | - if (Randomizer::boolOnPercentage(80)) { |
|
55 | - if (($homePoints - $awayPoints) < 0) { |
|
56 | - $goalAway = ($awayPoints - $homePoints) % 6; |
|
57 | - $goalHome += $this->chance(); |
|
58 | - $goalAway += $this->chance(); |
|
59 | - $goalHome += $this->bonusHome(); |
|
60 | - } else { |
|
61 | - $goalHome = ($homePoints - $awayPoints) % 6; |
|
62 | - $goalAway += $this->chance(); |
|
63 | - $goalHome += $this->bonusHome(); |
|
64 | - } |
|
65 | - } else { |
|
66 | - $goalHome += $this->chance(); |
|
67 | - $goalAway += $this->chance(); |
|
68 | - $goalHome += $this->bonusHome(); |
|
69 | - } |
|
70 | - $goalHome += $this->bonusAge($this->homeTeam); |
|
71 | - $goalAway += $this->bonusAge($this->awayTeam); |
|
72 | - |
|
73 | - //Bonus on Good GoalKeeper |
|
74 | - $goalies = $this->homeTeam->getBestPlayerForRole("GK"); |
|
75 | - $goalAway -= $this->bonusGoalKeeper($goalies); |
|
76 | - $goalies = $this->awayTeam->getBestPlayerForRole("GK"); |
|
77 | - $goalHome -= $this->bonusGoalKeeper($goalies); |
|
78 | - // |
|
79 | - $homeModule = new Module($this->homeTeam->coach->favouriteModule); |
|
80 | - $awayModule = new Module($this->awayTeam->coach->favouriteModule); |
|
81 | - if ($homeModule->isOffensive()) { |
|
82 | - $goalHome += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0; |
|
83 | - $goalAway += Randomizer::boolOnPercentage(20) ? 1 : 0; |
|
84 | - } |
|
85 | - if ($awayModule->isOffensive()) { |
|
86 | - $goalAway += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0; |
|
87 | - $goalHome += Randomizer::boolOnPercentage(20) ? 1 : 0; |
|
88 | - } |
|
89 | - if ($awayModule->isDefensive()) { |
|
90 | - $goalHome -= Randomizer::boolOnPercentage(50) ? 1 : 0; |
|
91 | - } |
|
92 | - if ($homeModule->isDefensive()) { |
|
93 | - $goalAway -= Randomizer::boolOnPercentage(50) ? 1 : 0; |
|
94 | - } |
|
95 | - $goalHome = $goalHome < 0 ? 0 : $goalHome; |
|
96 | - $goalAway = $goalAway < 0 ? 0 : $goalAway; |
|
97 | - return new MatchResult($goalHome, $goalAway, $this->homeTeam, $this->awayTeam); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @param Team $team |
|
102 | - * @return int |
|
103 | - */ |
|
104 | - private function bonusAge(Team $team) |
|
105 | - { |
|
106 | - if ($team->getAvgAge() > 29 || $team->getAvgAge() < 24) { |
|
107 | - return $this->chance(); |
|
108 | - } |
|
109 | - return 0; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @param $goalkeeper |
|
114 | - * @return int |
|
115 | - */ |
|
116 | - private function bonusGoalKeeper($goalkeeper) |
|
117 | - { |
|
118 | - $skillGoalkeeper = empty($goalkeeper) ? 1 : $goalkeeper->skillAvg; |
|
119 | - return (Randomizer::boolOnPercentage($skillGoalkeeper) ? 1 : 0); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @return int |
|
124 | - */ |
|
125 | - private function chance() |
|
126 | - { |
|
127 | - return rand(0, 3); |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @return int |
|
132 | - */ |
|
133 | - private function bonusHome() |
|
134 | - { |
|
135 | - return Randomizer::boolOnPercentage(66) ? 1 : 0; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @param $moduleString |
|
140 | - * @param $playersRoleArray |
|
141 | - * @return int |
|
142 | - */ |
|
143 | - private function malusModule($moduleString, $playersRoleArray) |
|
144 | - { |
|
145 | - $module = new Module($moduleString); |
|
146 | - if ($module->isApplicableToArray($playersRoleArray)) { |
|
147 | - return rand(1, 10); |
|
148 | - } else { |
|
149 | - return (-1) * rand(1, 10); |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * @param array $ormMatchArray |
|
155 | - * @return Match |
|
156 | - */ |
|
157 | - public static function fromArray($ormMatchArray = []) |
|
158 | - { |
|
159 | - $homeTeam = Team::fromArray($ormMatchArray['home_team']); |
|
160 | - $awayTeam = Team::fromArray($ormMatchArray['away_team']); |
|
161 | - return new Match($homeTeam, $awayTeam); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * @return mixed |
|
166 | - */ |
|
167 | - function toArray() |
|
168 | - { |
|
169 | - $result = []; |
|
170 | - $result['home_team_id'] = $this->homeTeam->id; |
|
171 | - $result['away_team_id'] = $this->awayTeam->id; |
|
172 | - return $result; |
|
173 | - } |
|
14 | + /** |
|
15 | + * @var Team |
|
16 | + */ |
|
17 | + private $homeTeam; |
|
18 | + /** |
|
19 | + * @var Team |
|
20 | + */ |
|
21 | + private $awayTeam; |
|
22 | + |
|
23 | + /** |
|
24 | + * Match constructor. |
|
25 | + * @param Team $home |
|
26 | + * @param Team $away |
|
27 | + */ |
|
28 | + public function __construct(Team $home, Team $away) |
|
29 | + { |
|
30 | + $this->homeTeam = $home; |
|
31 | + $this->awayTeam = $away; |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * @return MatchResult |
|
36 | + */ |
|
37 | + public function simulate() |
|
38 | + { |
|
39 | + $homePoints = $this->homeTeam->getAvgSkill(); |
|
40 | + $awayPoints = $this->awayTeam->getAvgSkill(); |
|
41 | + |
|
42 | + $homePoints += $this->malusModule( |
|
43 | + $this->homeTeam->coach->favouriteModule, |
|
44 | + $this->homeTeam->playersPerRoleArray() |
|
45 | + ); |
|
46 | + $awayPoints += $this->malusModule( |
|
47 | + $this->awayTeam->coach->favouriteModule, |
|
48 | + $this->awayTeam->playersPerRoleArray() |
|
49 | + ); |
|
50 | + |
|
51 | + $goalHome = 0; |
|
52 | + $goalAway = 0; |
|
53 | + |
|
54 | + if (Randomizer::boolOnPercentage(80)) { |
|
55 | + if (($homePoints - $awayPoints) < 0) { |
|
56 | + $goalAway = ($awayPoints - $homePoints) % 6; |
|
57 | + $goalHome += $this->chance(); |
|
58 | + $goalAway += $this->chance(); |
|
59 | + $goalHome += $this->bonusHome(); |
|
60 | + } else { |
|
61 | + $goalHome = ($homePoints - $awayPoints) % 6; |
|
62 | + $goalAway += $this->chance(); |
|
63 | + $goalHome += $this->bonusHome(); |
|
64 | + } |
|
65 | + } else { |
|
66 | + $goalHome += $this->chance(); |
|
67 | + $goalAway += $this->chance(); |
|
68 | + $goalHome += $this->bonusHome(); |
|
69 | + } |
|
70 | + $goalHome += $this->bonusAge($this->homeTeam); |
|
71 | + $goalAway += $this->bonusAge($this->awayTeam); |
|
72 | + |
|
73 | + //Bonus on Good GoalKeeper |
|
74 | + $goalies = $this->homeTeam->getBestPlayerForRole("GK"); |
|
75 | + $goalAway -= $this->bonusGoalKeeper($goalies); |
|
76 | + $goalies = $this->awayTeam->getBestPlayerForRole("GK"); |
|
77 | + $goalHome -= $this->bonusGoalKeeper($goalies); |
|
78 | + // |
|
79 | + $homeModule = new Module($this->homeTeam->coach->favouriteModule); |
|
80 | + $awayModule = new Module($this->awayTeam->coach->favouriteModule); |
|
81 | + if ($homeModule->isOffensive()) { |
|
82 | + $goalHome += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0; |
|
83 | + $goalAway += Randomizer::boolOnPercentage(20) ? 1 : 0; |
|
84 | + } |
|
85 | + if ($awayModule->isOffensive()) { |
|
86 | + $goalAway += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0; |
|
87 | + $goalHome += Randomizer::boolOnPercentage(20) ? 1 : 0; |
|
88 | + } |
|
89 | + if ($awayModule->isDefensive()) { |
|
90 | + $goalHome -= Randomizer::boolOnPercentage(50) ? 1 : 0; |
|
91 | + } |
|
92 | + if ($homeModule->isDefensive()) { |
|
93 | + $goalAway -= Randomizer::boolOnPercentage(50) ? 1 : 0; |
|
94 | + } |
|
95 | + $goalHome = $goalHome < 0 ? 0 : $goalHome; |
|
96 | + $goalAway = $goalAway < 0 ? 0 : $goalAway; |
|
97 | + return new MatchResult($goalHome, $goalAway, $this->homeTeam, $this->awayTeam); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @param Team $team |
|
102 | + * @return int |
|
103 | + */ |
|
104 | + private function bonusAge(Team $team) |
|
105 | + { |
|
106 | + if ($team->getAvgAge() > 29 || $team->getAvgAge() < 24) { |
|
107 | + return $this->chance(); |
|
108 | + } |
|
109 | + return 0; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @param $goalkeeper |
|
114 | + * @return int |
|
115 | + */ |
|
116 | + private function bonusGoalKeeper($goalkeeper) |
|
117 | + { |
|
118 | + $skillGoalkeeper = empty($goalkeeper) ? 1 : $goalkeeper->skillAvg; |
|
119 | + return (Randomizer::boolOnPercentage($skillGoalkeeper) ? 1 : 0); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @return int |
|
124 | + */ |
|
125 | + private function chance() |
|
126 | + { |
|
127 | + return rand(0, 3); |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @return int |
|
132 | + */ |
|
133 | + private function bonusHome() |
|
134 | + { |
|
135 | + return Randomizer::boolOnPercentage(66) ? 1 : 0; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @param $moduleString |
|
140 | + * @param $playersRoleArray |
|
141 | + * @return int |
|
142 | + */ |
|
143 | + private function malusModule($moduleString, $playersRoleArray) |
|
144 | + { |
|
145 | + $module = new Module($moduleString); |
|
146 | + if ($module->isApplicableToArray($playersRoleArray)) { |
|
147 | + return rand(1, 10); |
|
148 | + } else { |
|
149 | + return (-1) * rand(1, 10); |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * @param array $ormMatchArray |
|
155 | + * @return Match |
|
156 | + */ |
|
157 | + public static function fromArray($ormMatchArray = []) |
|
158 | + { |
|
159 | + $homeTeam = Team::fromArray($ormMatchArray['home_team']); |
|
160 | + $awayTeam = Team::fromArray($ormMatchArray['away_team']); |
|
161 | + return new Match($homeTeam, $awayTeam); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * @return mixed |
|
166 | + */ |
|
167 | + function toArray() |
|
168 | + { |
|
169 | + $result = []; |
|
170 | + $result['home_team_id'] = $this->homeTeam->id; |
|
171 | + $result['away_team_id'] = $this->awayTeam->id; |
|
172 | + return $result; |
|
173 | + } |
|
174 | 174 | } |
175 | 175 | \ No newline at end of file |
@@ -13,7 +13,7 @@ |
||
13 | 13 | public function run() |
14 | 14 | { |
15 | 15 | Capsule::schema()->dropIfExists('matches'); |
16 | - Capsule::schema()->create('matches', function (Blueprint $table) { |
|
16 | + Capsule::schema()->create('matches', function(Blueprint $table) { |
|
17 | 17 | $table->increments('id'); |
18 | 18 | $table->integer('home_team_id'); |
19 | 19 | $table->integer('goal_home')->default(0); |
@@ -5,25 +5,25 @@ |
||
5 | 5 | |
6 | 6 | class CreateMatchTable |
7 | 7 | { |
8 | - /** |
|
9 | - * Run the migrations. |
|
10 | - * |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function run() |
|
14 | - { |
|
15 | - Capsule::schema()->dropIfExists('matches'); |
|
16 | - Capsule::schema()->create('matches', function (Blueprint $table) { |
|
17 | - $table->increments('id'); |
|
18 | - $table->integer('league_round_id')->nullable(); |
|
19 | - $table->integer('home_team_id'); |
|
20 | - $table->integer('goal_home')->default(0); |
|
21 | - $table->integer('away_team_id'); |
|
22 | - $table->integer('goal_away')->default(0); |
|
23 | - $table->boolean('simulated')->default(false); |
|
24 | - $table->text('info')->nullable(); |
|
25 | - $table->date('match_date')->default(\Carbon\Carbon::now()); |
|
26 | - $table->timestamps(); |
|
27 | - }); |
|
28 | - } |
|
8 | + /** |
|
9 | + * Run the migrations. |
|
10 | + * |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function run() |
|
14 | + { |
|
15 | + Capsule::schema()->dropIfExists('matches'); |
|
16 | + Capsule::schema()->create('matches', function (Blueprint $table) { |
|
17 | + $table->increments('id'); |
|
18 | + $table->integer('league_round_id')->nullable(); |
|
19 | + $table->integer('home_team_id'); |
|
20 | + $table->integer('goal_home')->default(0); |
|
21 | + $table->integer('away_team_id'); |
|
22 | + $table->integer('goal_away')->default(0); |
|
23 | + $table->boolean('simulated')->default(false); |
|
24 | + $table->text('info')->nullable(); |
|
25 | + $table->date('match_date')->default(\Carbon\Carbon::now()); |
|
26 | + $table->timestamps(); |
|
27 | + }); |
|
28 | + } |
|
29 | 29 | } |
@@ -74,10 +74,10 @@ |
||
74 | 74 | 'ro_MD', |
75 | 75 | 'tr_TR' |
76 | 76 | ], |
77 | - 'rosters' => [ |
|
78 | - 'min' => 11, |
|
79 | - 'max' => 18 |
|
80 | - ], |
|
77 | + 'rosters' => [ |
|
78 | + 'min' => 11, |
|
79 | + 'max' => 18 |
|
80 | + ], |
|
81 | 81 | ]; |
82 | 82 | |
83 | 83 |
@@ -8,101 +8,101 @@ |
||
8 | 8 | { |
9 | 9 | |
10 | 10 | |
11 | - /** |
|
12 | - * @group OrmModels |
|
13 | - * @group PlayerOrm |
|
14 | - */ |
|
15 | - public function testPlayerOrmGetSet() |
|
16 | - { |
|
17 | - $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
18 | - $playerM = $rndFiller->getPlayer(); |
|
19 | - $arrayPl = $playerM->toArray(); |
|
20 | - $playerO = \App\Lib\DsManager\Models\Orm\Player::create($arrayPl); |
|
21 | - $this->assertNotEmpty($playerO); |
|
11 | + /** |
|
12 | + * @group OrmModels |
|
13 | + * @group PlayerOrm |
|
14 | + */ |
|
15 | + public function testPlayerOrmGetSet() |
|
16 | + { |
|
17 | + $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
18 | + $playerM = $rndFiller->getPlayer(); |
|
19 | + $arrayPl = $playerM->toArray(); |
|
20 | + $playerO = \App\Lib\DsManager\Models\Orm\Player::create($arrayPl); |
|
21 | + $this->assertNotEmpty($playerO); |
|
22 | 22 | |
23 | - $newPlayer = \App\Lib\DsManager\Models\Player::fromArray($playerO->toArray()); |
|
24 | - $this->assertNotEmpty($newPlayer); |
|
25 | - } |
|
23 | + $newPlayer = \App\Lib\DsManager\Models\Player::fromArray($playerO->toArray()); |
|
24 | + $this->assertNotEmpty($newPlayer); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @group OrmModels |
|
29 | - * @group CoachOrm |
|
30 | - */ |
|
31 | - public function testCoachOrmGetSet() |
|
32 | - { |
|
33 | - $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
34 | - $coach = $rndFiller->getCoach(); |
|
35 | - $arrayPl = $coach->toArray(); |
|
36 | - $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($arrayPl); |
|
37 | - $this->assertNotEmpty($coachO); |
|
27 | + /** |
|
28 | + * @group OrmModels |
|
29 | + * @group CoachOrm |
|
30 | + */ |
|
31 | + public function testCoachOrmGetSet() |
|
32 | + { |
|
33 | + $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
34 | + $coach = $rndFiller->getCoach(); |
|
35 | + $arrayPl = $coach->toArray(); |
|
36 | + $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($arrayPl); |
|
37 | + $this->assertNotEmpty($coachO); |
|
38 | 38 | |
39 | - $newCoach = \App\Lib\DsManager\Models\Coach::fromArray($coachO->toArray()); |
|
40 | - $this->assertNotEmpty($newCoach); |
|
41 | - } |
|
39 | + $newCoach = \App\Lib\DsManager\Models\Coach::fromArray($coachO->toArray()); |
|
40 | + $this->assertNotEmpty($newCoach); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @group OrmModels |
|
45 | - * @group TeamOrm |
|
46 | - */ |
|
47 | - public function testTeamOrm() |
|
48 | - { |
|
49 | - $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
50 | - $team = $rndFiller->getTeam($rndFiller->getLocale()); |
|
51 | - $teamArray = $team->toArray(); |
|
52 | - $this->assertNotEmpty($team); |
|
53 | - $teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray); |
|
54 | - $this->assertNotEmpty($teamArray); |
|
55 | - $this->assertNotEmpty($teamArray['roster']); |
|
56 | - foreach ($teamArray['roster'] as $player) { |
|
57 | - $player['team_id'] = $teamO->id; |
|
58 | - $playerO = \App\Lib\DsManager\Models\Orm\Player::create($player); |
|
59 | - $this->assertNotEmpty($playerO); |
|
60 | - } |
|
61 | - $teamArray['coach']['team_id'] = $teamO->id; |
|
62 | - $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']); |
|
63 | - $this->assertNotEmpty($coachO); |
|
43 | + /** |
|
44 | + * @group OrmModels |
|
45 | + * @group TeamOrm |
|
46 | + */ |
|
47 | + public function testTeamOrm() |
|
48 | + { |
|
49 | + $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
50 | + $team = $rndFiller->getTeam($rndFiller->getLocale()); |
|
51 | + $teamArray = $team->toArray(); |
|
52 | + $this->assertNotEmpty($team); |
|
53 | + $teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray); |
|
54 | + $this->assertNotEmpty($teamArray); |
|
55 | + $this->assertNotEmpty($teamArray['roster']); |
|
56 | + foreach ($teamArray['roster'] as $player) { |
|
57 | + $player['team_id'] = $teamO->id; |
|
58 | + $playerO = \App\Lib\DsManager\Models\Orm\Player::create($player); |
|
59 | + $this->assertNotEmpty($playerO); |
|
60 | + } |
|
61 | + $teamArray['coach']['team_id'] = $teamO->id; |
|
62 | + $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']); |
|
63 | + $this->assertNotEmpty($coachO); |
|
64 | 64 | |
65 | - $this->assertNotEmpty( |
|
66 | - \App\Lib\DsManager\Models\Orm\Team::with( |
|
67 | - 'roster' |
|
68 | - )->with( |
|
69 | - 'coach' |
|
70 | - )->where( |
|
71 | - [ |
|
72 | - 'id' => $teamO->id |
|
73 | - ] |
|
74 | - )->get()->toArray() |
|
75 | - ); |
|
76 | - } |
|
65 | + $this->assertNotEmpty( |
|
66 | + \App\Lib\DsManager\Models\Orm\Team::with( |
|
67 | + 'roster' |
|
68 | + )->with( |
|
69 | + 'coach' |
|
70 | + )->where( |
|
71 | + [ |
|
72 | + 'id' => $teamO->id |
|
73 | + ] |
|
74 | + )->get()->toArray() |
|
75 | + ); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @group Match |
|
80 | - * @group createnewmatch |
|
81 | - */ |
|
82 | - public function testCreateNewMatch() |
|
83 | - { |
|
84 | - $teams = \App\Lib\DsManager\Models\Orm\Team::with( |
|
85 | - 'roster', |
|
86 | - 'coach' |
|
87 | - )->get(); |
|
88 | - $this->assertNotNull($teams); |
|
89 | - $teams = $teams->toArray(); |
|
90 | - $homeIndex = array_rand($teams); |
|
91 | - $teamHome = $teams[$homeIndex]; |
|
92 | - unset($teams[$homeIndex]); |
|
93 | - $teamAway = $teams[array_rand($teams)]; |
|
94 | - $this->assertNotNull($teamHome); |
|
95 | - $this->assertNotNull($teamAway); |
|
96 | - $matchO = \App\Lib\DsManager\Models\Orm\Match::create( |
|
97 | - [ |
|
98 | - 'home_team_id' => $teamHome['id'], |
|
99 | - 'away_team_id' => $teamAway['id'] |
|
100 | - ] |
|
101 | - ); |
|
102 | - $this->assertNotNull($matchO); |
|
103 | - $matchNew = \App\Lib\DsManager\Models\Orm\Match::complete()->where('id', $matchO->id)->first(); |
|
104 | - $this->assertNotNull($matchNew); |
|
105 | - $match = \App\Lib\DsManager\Models\Match::fromArray($matchNew->toArray()); |
|
106 | - $this->assertNotNull($match); |
|
107 | - } |
|
78 | + /** |
|
79 | + * @group Match |
|
80 | + * @group createnewmatch |
|
81 | + */ |
|
82 | + public function testCreateNewMatch() |
|
83 | + { |
|
84 | + $teams = \App\Lib\DsManager\Models\Orm\Team::with( |
|
85 | + 'roster', |
|
86 | + 'coach' |
|
87 | + )->get(); |
|
88 | + $this->assertNotNull($teams); |
|
89 | + $teams = $teams->toArray(); |
|
90 | + $homeIndex = array_rand($teams); |
|
91 | + $teamHome = $teams[$homeIndex]; |
|
92 | + unset($teams[$homeIndex]); |
|
93 | + $teamAway = $teams[array_rand($teams)]; |
|
94 | + $this->assertNotNull($teamHome); |
|
95 | + $this->assertNotNull($teamAway); |
|
96 | + $matchO = \App\Lib\DsManager\Models\Orm\Match::create( |
|
97 | + [ |
|
98 | + 'home_team_id' => $teamHome['id'], |
|
99 | + 'away_team_id' => $teamAway['id'] |
|
100 | + ] |
|
101 | + ); |
|
102 | + $this->assertNotNull($matchO); |
|
103 | + $matchNew = \App\Lib\DsManager\Models\Orm\Match::complete()->where('id', $matchO->id)->first(); |
|
104 | + $this->assertNotNull($matchNew); |
|
105 | + $match = \App\Lib\DsManager\Models\Match::fromArray($matchNew->toArray()); |
|
106 | + $this->assertNotNull($match); |
|
107 | + } |
|
108 | 108 | } |
@@ -8,45 +8,45 @@ |
||
8 | 8 | */ |
9 | 9 | class Team extends DsManagerOrm |
10 | 10 | { |
11 | - /** |
|
12 | - * @var string |
|
13 | - */ |
|
14 | - protected $table = 'teams'; |
|
11 | + /** |
|
12 | + * @var string |
|
13 | + */ |
|
14 | + protected $table = 'teams'; |
|
15 | 15 | |
16 | - /** |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - protected $fillable = [ |
|
20 | - 'name', |
|
21 | - 'nationality' |
|
22 | - ]; |
|
16 | + /** |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + protected $fillable = [ |
|
20 | + 'name', |
|
21 | + 'nationality' |
|
22 | + ]; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
26 | - */ |
|
27 | - public function roster() |
|
28 | - { |
|
29 | - return $this->hasMany(Player::class); |
|
30 | - } |
|
24 | + /** |
|
25 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
26 | + */ |
|
27 | + public function roster() |
|
28 | + { |
|
29 | + return $this->hasMany(Player::class); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
34 | - */ |
|
35 | - public function coach() |
|
36 | - { |
|
37 | - return $this->hasOne(Coach::class); |
|
38 | - } |
|
32 | + /** |
|
33 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
34 | + */ |
|
35 | + public function coach() |
|
36 | + { |
|
37 | + return $this->hasOne(Coach::class); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param $query |
|
42 | - * @return mixed |
|
43 | - */ |
|
44 | - public function scopeComplete($query) |
|
45 | - { |
|
46 | - return $query->with( |
|
47 | - 'roster', |
|
48 | - 'coach' |
|
49 | - ); |
|
50 | - } |
|
40 | + /** |
|
41 | + * @param $query |
|
42 | + * @return mixed |
|
43 | + */ |
|
44 | + public function scopeComplete($query) |
|
45 | + { |
|
46 | + return $query->with( |
|
47 | + 'roster', |
|
48 | + 'coach' |
|
49 | + ); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | } |
53 | 53 | \ No newline at end of file |
@@ -9,47 +9,47 @@ |
||
9 | 9 | class MatchPlayer extends DsManagerOrm |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $table = 'match_players'; |
|
16 | - |
|
17 | - /** |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - protected $fillable = [ |
|
21 | - 'match_id', |
|
22 | - 'team_id', |
|
23 | - 'player_id', |
|
24 | - 'goals', |
|
25 | - 'vote' |
|
26 | - ]; |
|
27 | - |
|
28 | - /** |
|
29 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
30 | - */ |
|
31 | - public function player() |
|
32 | - { |
|
33 | - return $this->belongsTo(Player::class, 'player_id'); |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
38 | - */ |
|
39 | - public function team() |
|
40 | - { |
|
41 | - return $this->belongsTo(Team::class, 'team_id'); |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * @param $query |
|
46 | - * @return mixed |
|
47 | - */ |
|
48 | - public function scopeComplete($query){ |
|
49 | - return $query->with( |
|
50 | - 'team', |
|
51 | - 'player' |
|
52 | - ); |
|
53 | - } |
|
12 | + /** |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $table = 'match_players'; |
|
16 | + |
|
17 | + /** |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + protected $fillable = [ |
|
21 | + 'match_id', |
|
22 | + 'team_id', |
|
23 | + 'player_id', |
|
24 | + 'goals', |
|
25 | + 'vote' |
|
26 | + ]; |
|
27 | + |
|
28 | + /** |
|
29 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
30 | + */ |
|
31 | + public function player() |
|
32 | + { |
|
33 | + return $this->belongsTo(Player::class, 'player_id'); |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
38 | + */ |
|
39 | + public function team() |
|
40 | + { |
|
41 | + return $this->belongsTo(Team::class, 'team_id'); |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * @param $query |
|
46 | + * @return mixed |
|
47 | + */ |
|
48 | + public function scopeComplete($query){ |
|
49 | + return $query->with( |
|
50 | + 'team', |
|
51 | + 'player' |
|
52 | + ); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | } |
56 | 56 | \ No newline at end of file |
@@ -56,7 +56,7 @@ |
||
56 | 56 | return $this->belongsTo(Team::class, 'away_team_id'); |
57 | 57 | } |
58 | 58 | |
59 | - public function scopeComplete($query){ |
|
59 | + public function scopeComplete($query) { |
|
60 | 60 | return $query->with( |
61 | 61 | 'homeTeam', |
62 | 62 | 'homeTeam.roster', |
@@ -5,22 +5,22 @@ |
||
5 | 5 | |
6 | 6 | class CreateMatchPlayersTable |
7 | 7 | { |
8 | - /** |
|
9 | - * Run the migrations. |
|
10 | - * |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function run() |
|
14 | - { |
|
15 | - Capsule::schema()->dropIfExists('match_players'); |
|
16 | - Capsule::schema()->create('match_players', function (Blueprint $table) { |
|
17 | - $table->increments('id'); |
|
18 | - $table->integer('match_id'); |
|
19 | - $table->integer('team_id'); |
|
20 | - $table->integer('player_id')->default(0); |
|
21 | - $table->unsignedTinyInteger('goals')->default(0); |
|
22 | - $table->unsignedTinyInteger('vote')->default(6); |
|
23 | - $table->timestamps(); |
|
24 | - }); |
|
25 | - } |
|
8 | + /** |
|
9 | + * Run the migrations. |
|
10 | + * |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function run() |
|
14 | + { |
|
15 | + Capsule::schema()->dropIfExists('match_players'); |
|
16 | + Capsule::schema()->create('match_players', function (Blueprint $table) { |
|
17 | + $table->increments('id'); |
|
18 | + $table->integer('match_id'); |
|
19 | + $table->integer('team_id'); |
|
20 | + $table->integer('player_id')->default(0); |
|
21 | + $table->unsignedTinyInteger('goals')->default(0); |
|
22 | + $table->unsignedTinyInteger('vote')->default(6); |
|
23 | + $table->timestamps(); |
|
24 | + }); |
|
25 | + } |
|
26 | 26 | } |
@@ -13,7 +13,7 @@ |
||
13 | 13 | public function run() |
14 | 14 | { |
15 | 15 | Capsule::schema()->dropIfExists('match_players'); |
16 | - Capsule::schema()->create('match_players', function (Blueprint $table) { |
|
16 | + Capsule::schema()->create('match_players', function(Blueprint $table) { |
|
17 | 17 | $table->increments('id'); |
18 | 18 | $table->integer('match_id'); |
19 | 19 | $table->integer('team_id'); |
@@ -8,227 +8,227 @@ |
||
8 | 8 | { |
9 | 9 | |
10 | 10 | |
11 | - /** |
|
12 | - * @group Player |
|
13 | - */ |
|
14 | - public function testGetRandomPlayer() |
|
15 | - { |
|
16 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
17 | - $player = $rndF->getPlayer(null, $rndF->getLocale()); |
|
18 | - $array = $player->toArray(); |
|
19 | - $this->assertNotEmpty($array); |
|
20 | - |
|
21 | - $newPlayer = \App\Lib\DsManager\Models\Player::fromArray($array); |
|
22 | - $this->assertNotEmpty($newPlayer->toArray()); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * @group Coach |
|
27 | - */ |
|
28 | - public function testGetRandomCoach() |
|
29 | - { |
|
30 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
31 | - $coach = $rndF->getCoach(); |
|
32 | - $this->assertNotEmpty($coach->toArray()); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * @group Coaches |
|
37 | - */ |
|
38 | - public function testGetRandomCoaches() |
|
39 | - { |
|
40 | - foreach (\App\Lib\Helpers\Config::get('generic.localesSmall') as $nat) { |
|
41 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller($nat); |
|
42 | - $coach = $rndF->getCoach(); |
|
43 | - $this->assertNotEmpty($coach->toArray()); |
|
44 | - } |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * @group Players |
|
49 | - */ |
|
50 | - public function testGetRandomPlayers() |
|
51 | - { |
|
52 | - foreach (\App\Lib\Helpers\Config::get('generic.localesSmall') as $nat) { |
|
53 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller($nat); |
|
54 | - $player = $rndF->getPlayer(); |
|
55 | - $this->assertNotEmpty($player->toArray()); |
|
56 | - } |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @group Team |
|
61 | - */ |
|
62 | - public function testGetRandomTeam() |
|
63 | - { |
|
64 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
65 | - $team = $rndF->getTeam(); |
|
66 | - $this->assertNotEmpty($team); |
|
67 | - $this->assertNotEmpty($team->name); |
|
68 | - $this->assertNotEmpty($team->getAvgSkill()); |
|
69 | - |
|
70 | - //After Adding a player |
|
71 | - $player = $rndF->getPlayer(); |
|
72 | - $this->assertNotEmpty($player->toArray()); |
|
73 | - $team->roster[] = $player; |
|
74 | - $this->assertNotEmpty($team->getAvgSkill()); |
|
75 | - $this->assertNotEmpty($team->getAvgAge()); |
|
76 | - |
|
77 | - $this->assertNotEmpty($team->coach->toArray()); |
|
78 | - |
|
79 | - $teamArray = $team->toArray(); |
|
80 | - $this->assertNotEmpty($teamArray); |
|
81 | - |
|
82 | - $newTeam = \App\Lib\DsManager\Models\Team::fromArray($teamArray); |
|
83 | - $this->assertNotEmpty($newTeam->toArray()); |
|
84 | - |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @group Teams |
|
89 | - */ |
|
90 | - public function testGetRandomTeams() |
|
91 | - { |
|
92 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
93 | - |
|
94 | - for ($i = 1; $i <= 20; $i++) { |
|
95 | - $team = $rndF->getTeam(); |
|
96 | - $this->assertGreaterThanOrEqual( |
|
97 | - \App\Lib\Helpers\Config::get('generic.rosters')['min'], |
|
98 | - count($team->roster) |
|
99 | - ); |
|
100 | - $this->assertNotEmpty($team->name); |
|
101 | - $this->assertNotEmpty($team->nationality); |
|
102 | - $this->assertNotEmpty($team->getAvgSkill()); |
|
103 | - $this->assertNotEmpty($team->getAvgAge()); |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @group Match |
|
109 | - */ |
|
110 | - public function testGetRandomMatch() |
|
111 | - { |
|
112 | - for ($i = 1; $i <= 30; $i++) { |
|
113 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
114 | - $spanish = $rndF->getTeam(); |
|
115 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
116 | - $italian = $rndF->getTeam(); |
|
117 | - $this->assertNotEmpty($spanish); |
|
118 | - $this->assertNotEmpty($italian); |
|
119 | - $this->assertNotEmpty($italian->name); |
|
120 | - $this->assertNotEmpty($spanish); |
|
121 | - $this->assertNotEmpty($spanish->name); |
|
122 | - |
|
123 | - $this->assertNotEmpty($italian->getAvgSkill()); |
|
124 | - $this->assertNotEmpty($spanish->getAvgSkill()); |
|
125 | - $result = (new \App\Lib\DsManager\Models\Match($italian, $spanish))->simulate()->toArray(); |
|
126 | - $this->assertNotEmpty($result); |
|
127 | - $this->assertGreaterThanOrEqual(0, $result['goal_home']); |
|
128 | - $this->assertGreaterThanOrEqual(0, $result['goal_away']); |
|
129 | - |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * @group Match |
|
135 | - * @group MatchResult |
|
136 | - * @group matchresultoutput |
|
137 | - */ |
|
138 | - public function testMatchFromExistingTeams() |
|
139 | - { |
|
140 | - $teamHome = 1; |
|
141 | - $teamAway = 2; |
|
142 | - $homeOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamHome])->first(); |
|
143 | - $awayOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamAway])->first(); |
|
144 | - $home = \App\Lib\DsManager\Models\Team::fromArray($homeOrm->toArray()); |
|
145 | - $away = \App\Lib\DsManager\Models\Team::fromArray($awayOrm->toArray()); |
|
146 | - |
|
147 | - $match = new \App\Lib\DsManager\Models\Match($home, $away); |
|
148 | - $result = $match->simulate()->toArray(); |
|
149 | - $this->assertNotEmpty($result); |
|
150 | - $this->assertGreaterThanOrEqual(0, $result['goal_away']); |
|
151 | - $this->assertGreaterThanOrEqual(0, $result['goal_home']); |
|
152 | - if ($result['goal_home'] > 0) { |
|
153 | - $this->assertNotEmpty($result['info']['scorers']['home']); |
|
154 | - foreach ($result['info']['scorers']['home'] as $scorerHome) { |
|
155 | - $this->assertEquals($scorerHome->team_id, $teamHome); |
|
156 | - } |
|
157 | - } else { |
|
158 | - $this->assertEmpty($result['info']['scorers']['home']); |
|
159 | - } |
|
160 | - if ($result['goal_away'] > 0) { |
|
161 | - $this->assertNotEmpty($result['info']['scorers']['away']); |
|
162 | - foreach ($result['info']['scorers']['away'] as $scorerAway) { |
|
163 | - $this->assertEquals($scorerAway->team_id, $teamAway); |
|
164 | - } |
|
165 | - } else { |
|
166 | - $this->assertEmpty($result['info']['scorers']['away']); |
|
167 | - } |
|
168 | - if ($result['goal_home'] == $result['goal_away']) { |
|
169 | - $this->assertTrue($result['info']['is_draw']); |
|
170 | - } else { |
|
171 | - $this->assertFalse($result['info']['is_draw']); |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * @group Matches |
|
177 | - */ |
|
178 | - public function testGetRandomMatchesOneTeam() |
|
179 | - { |
|
180 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
181 | - $myTeam = $rndF->getTeam(); |
|
182 | - $myTeam->id = 1000; |
|
183 | - $win = 0; |
|
184 | - $lost = 0; |
|
185 | - $draw = 0; |
|
186 | - |
|
187 | - for ($i = 1; $i <= 2; $i++) { |
|
188 | - |
|
189 | - $randomLocale = \App\Lib\Helpers\Config::get('generic.localesSmall'); |
|
190 | - shuffle($randomLocale); |
|
191 | - $randomLocale = $randomLocale[0]; |
|
192 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller($randomLocale); |
|
193 | - $opponent = $rndF->getTeam(); |
|
194 | - $opponent->id = 6000; |
|
195 | - $result = (new \App\Lib\DsManager\Models\Match($opponent, $myTeam))->simulate()->toArray(); |
|
196 | - $this->assertNotEmpty($result); |
|
197 | - $result = $result['info']; |
|
198 | - if (!$result['is_draw']) { |
|
199 | - if ($result['winner_id'] == $myTeam->id) { |
|
200 | - $win++; |
|
201 | - } else { |
|
202 | - $lost++; |
|
203 | - } |
|
204 | - } else { |
|
205 | - $draw++; |
|
206 | - } |
|
207 | - } |
|
208 | - $this->assertGreaterThanOrEqual(0, $win); |
|
209 | - $this->assertGreaterThanOrEqual(0, $lost); |
|
210 | - $this->assertGreaterThanOrEqual(0, $draw); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * @group Module |
|
215 | - */ |
|
216 | - public function testModule() |
|
217 | - { |
|
218 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
219 | - $team = $rndF->getTeam(); |
|
220 | - |
|
221 | - $modules = \App\Lib\Helpers\Config::get("modules.modules"); |
|
222 | - $modules = array_keys($modules); |
|
223 | - foreach ($modules as $mod) { |
|
224 | - $module = new \App\Lib\DsManager\Models\Module($mod); |
|
225 | - $this->assertNotEmpty($module); |
|
226 | - $this->assertNotNull($module->isDefensive()); |
|
227 | - $this->assertNotNull($module->isBalanced()); |
|
228 | - $this->assertNotNull($module->isOffensive()); |
|
229 | - $this->assertTrue(is_array($module->getRoleNeeded())); |
|
230 | - } |
|
231 | - $this->assertGreaterThan(0, $team->playersPerRoleArray()); |
|
232 | - } |
|
11 | + /** |
|
12 | + * @group Player |
|
13 | + */ |
|
14 | + public function testGetRandomPlayer() |
|
15 | + { |
|
16 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
17 | + $player = $rndF->getPlayer(null, $rndF->getLocale()); |
|
18 | + $array = $player->toArray(); |
|
19 | + $this->assertNotEmpty($array); |
|
20 | + |
|
21 | + $newPlayer = \App\Lib\DsManager\Models\Player::fromArray($array); |
|
22 | + $this->assertNotEmpty($newPlayer->toArray()); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * @group Coach |
|
27 | + */ |
|
28 | + public function testGetRandomCoach() |
|
29 | + { |
|
30 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
31 | + $coach = $rndF->getCoach(); |
|
32 | + $this->assertNotEmpty($coach->toArray()); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * @group Coaches |
|
37 | + */ |
|
38 | + public function testGetRandomCoaches() |
|
39 | + { |
|
40 | + foreach (\App\Lib\Helpers\Config::get('generic.localesSmall') as $nat) { |
|
41 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller($nat); |
|
42 | + $coach = $rndF->getCoach(); |
|
43 | + $this->assertNotEmpty($coach->toArray()); |
|
44 | + } |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * @group Players |
|
49 | + */ |
|
50 | + public function testGetRandomPlayers() |
|
51 | + { |
|
52 | + foreach (\App\Lib\Helpers\Config::get('generic.localesSmall') as $nat) { |
|
53 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller($nat); |
|
54 | + $player = $rndF->getPlayer(); |
|
55 | + $this->assertNotEmpty($player->toArray()); |
|
56 | + } |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @group Team |
|
61 | + */ |
|
62 | + public function testGetRandomTeam() |
|
63 | + { |
|
64 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
65 | + $team = $rndF->getTeam(); |
|
66 | + $this->assertNotEmpty($team); |
|
67 | + $this->assertNotEmpty($team->name); |
|
68 | + $this->assertNotEmpty($team->getAvgSkill()); |
|
69 | + |
|
70 | + //After Adding a player |
|
71 | + $player = $rndF->getPlayer(); |
|
72 | + $this->assertNotEmpty($player->toArray()); |
|
73 | + $team->roster[] = $player; |
|
74 | + $this->assertNotEmpty($team->getAvgSkill()); |
|
75 | + $this->assertNotEmpty($team->getAvgAge()); |
|
76 | + |
|
77 | + $this->assertNotEmpty($team->coach->toArray()); |
|
78 | + |
|
79 | + $teamArray = $team->toArray(); |
|
80 | + $this->assertNotEmpty($teamArray); |
|
81 | + |
|
82 | + $newTeam = \App\Lib\DsManager\Models\Team::fromArray($teamArray); |
|
83 | + $this->assertNotEmpty($newTeam->toArray()); |
|
84 | + |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @group Teams |
|
89 | + */ |
|
90 | + public function testGetRandomTeams() |
|
91 | + { |
|
92 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
93 | + |
|
94 | + for ($i = 1; $i <= 20; $i++) { |
|
95 | + $team = $rndF->getTeam(); |
|
96 | + $this->assertGreaterThanOrEqual( |
|
97 | + \App\Lib\Helpers\Config::get('generic.rosters')['min'], |
|
98 | + count($team->roster) |
|
99 | + ); |
|
100 | + $this->assertNotEmpty($team->name); |
|
101 | + $this->assertNotEmpty($team->nationality); |
|
102 | + $this->assertNotEmpty($team->getAvgSkill()); |
|
103 | + $this->assertNotEmpty($team->getAvgAge()); |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @group Match |
|
109 | + */ |
|
110 | + public function testGetRandomMatch() |
|
111 | + { |
|
112 | + for ($i = 1; $i <= 30; $i++) { |
|
113 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
114 | + $spanish = $rndF->getTeam(); |
|
115 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
116 | + $italian = $rndF->getTeam(); |
|
117 | + $this->assertNotEmpty($spanish); |
|
118 | + $this->assertNotEmpty($italian); |
|
119 | + $this->assertNotEmpty($italian->name); |
|
120 | + $this->assertNotEmpty($spanish); |
|
121 | + $this->assertNotEmpty($spanish->name); |
|
122 | + |
|
123 | + $this->assertNotEmpty($italian->getAvgSkill()); |
|
124 | + $this->assertNotEmpty($spanish->getAvgSkill()); |
|
125 | + $result = (new \App\Lib\DsManager\Models\Match($italian, $spanish))->simulate()->toArray(); |
|
126 | + $this->assertNotEmpty($result); |
|
127 | + $this->assertGreaterThanOrEqual(0, $result['goal_home']); |
|
128 | + $this->assertGreaterThanOrEqual(0, $result['goal_away']); |
|
129 | + |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * @group Match |
|
135 | + * @group MatchResult |
|
136 | + * @group matchresultoutput |
|
137 | + */ |
|
138 | + public function testMatchFromExistingTeams() |
|
139 | + { |
|
140 | + $teamHome = 1; |
|
141 | + $teamAway = 2; |
|
142 | + $homeOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamHome])->first(); |
|
143 | + $awayOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamAway])->first(); |
|
144 | + $home = \App\Lib\DsManager\Models\Team::fromArray($homeOrm->toArray()); |
|
145 | + $away = \App\Lib\DsManager\Models\Team::fromArray($awayOrm->toArray()); |
|
146 | + |
|
147 | + $match = new \App\Lib\DsManager\Models\Match($home, $away); |
|
148 | + $result = $match->simulate()->toArray(); |
|
149 | + $this->assertNotEmpty($result); |
|
150 | + $this->assertGreaterThanOrEqual(0, $result['goal_away']); |
|
151 | + $this->assertGreaterThanOrEqual(0, $result['goal_home']); |
|
152 | + if ($result['goal_home'] > 0) { |
|
153 | + $this->assertNotEmpty($result['info']['scorers']['home']); |
|
154 | + foreach ($result['info']['scorers']['home'] as $scorerHome) { |
|
155 | + $this->assertEquals($scorerHome->team_id, $teamHome); |
|
156 | + } |
|
157 | + } else { |
|
158 | + $this->assertEmpty($result['info']['scorers']['home']); |
|
159 | + } |
|
160 | + if ($result['goal_away'] > 0) { |
|
161 | + $this->assertNotEmpty($result['info']['scorers']['away']); |
|
162 | + foreach ($result['info']['scorers']['away'] as $scorerAway) { |
|
163 | + $this->assertEquals($scorerAway->team_id, $teamAway); |
|
164 | + } |
|
165 | + } else { |
|
166 | + $this->assertEmpty($result['info']['scorers']['away']); |
|
167 | + } |
|
168 | + if ($result['goal_home'] == $result['goal_away']) { |
|
169 | + $this->assertTrue($result['info']['is_draw']); |
|
170 | + } else { |
|
171 | + $this->assertFalse($result['info']['is_draw']); |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * @group Matches |
|
177 | + */ |
|
178 | + public function testGetRandomMatchesOneTeam() |
|
179 | + { |
|
180 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
181 | + $myTeam = $rndF->getTeam(); |
|
182 | + $myTeam->id = 1000; |
|
183 | + $win = 0; |
|
184 | + $lost = 0; |
|
185 | + $draw = 0; |
|
186 | + |
|
187 | + for ($i = 1; $i <= 2; $i++) { |
|
188 | + |
|
189 | + $randomLocale = \App\Lib\Helpers\Config::get('generic.localesSmall'); |
|
190 | + shuffle($randomLocale); |
|
191 | + $randomLocale = $randomLocale[0]; |
|
192 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller($randomLocale); |
|
193 | + $opponent = $rndF->getTeam(); |
|
194 | + $opponent->id = 6000; |
|
195 | + $result = (new \App\Lib\DsManager\Models\Match($opponent, $myTeam))->simulate()->toArray(); |
|
196 | + $this->assertNotEmpty($result); |
|
197 | + $result = $result['info']; |
|
198 | + if (!$result['is_draw']) { |
|
199 | + if ($result['winner_id'] == $myTeam->id) { |
|
200 | + $win++; |
|
201 | + } else { |
|
202 | + $lost++; |
|
203 | + } |
|
204 | + } else { |
|
205 | + $draw++; |
|
206 | + } |
|
207 | + } |
|
208 | + $this->assertGreaterThanOrEqual(0, $win); |
|
209 | + $this->assertGreaterThanOrEqual(0, $lost); |
|
210 | + $this->assertGreaterThanOrEqual(0, $draw); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * @group Module |
|
215 | + */ |
|
216 | + public function testModule() |
|
217 | + { |
|
218 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
219 | + $team = $rndF->getTeam(); |
|
220 | + |
|
221 | + $modules = \App\Lib\Helpers\Config::get("modules.modules"); |
|
222 | + $modules = array_keys($modules); |
|
223 | + foreach ($modules as $mod) { |
|
224 | + $module = new \App\Lib\DsManager\Models\Module($mod); |
|
225 | + $this->assertNotEmpty($module); |
|
226 | + $this->assertNotNull($module->isDefensive()); |
|
227 | + $this->assertNotNull($module->isBalanced()); |
|
228 | + $this->assertNotNull($module->isOffensive()); |
|
229 | + $this->assertTrue(is_array($module->getRoleNeeded())); |
|
230 | + } |
|
231 | + $this->assertGreaterThan(0, $team->playersPerRoleArray()); |
|
232 | + } |
|
233 | 233 | |
234 | 234 | } |
@@ -10,22 +10,22 @@ |
||
10 | 10 | */ |
11 | 11 | class Randomizer |
12 | 12 | { |
13 | - /** |
|
14 | - * @param $percentage |
|
15 | - * @return bool |
|
16 | - */ |
|
17 | - public static function boolOnPercentage($percentage) |
|
18 | - { |
|
19 | - return (rand(0, 100) < $percentage); |
|
20 | - } |
|
13 | + /** |
|
14 | + * @param $percentage |
|
15 | + * @return bool |
|
16 | + */ |
|
17 | + public static function boolOnPercentage($percentage) |
|
18 | + { |
|
19 | + return (rand(0, 100) < $percentage); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param $skill |
|
24 | - * @return int |
|
25 | - */ |
|
26 | - public static function voteFromSkill($skill) |
|
27 | - { |
|
28 | - return rand((2 * ($skill - 100) / 25), 10); |
|
29 | - } |
|
22 | + /** |
|
23 | + * @param $skill |
|
24 | + * @return int |
|
25 | + */ |
|
26 | + public static function voteFromSkill($skill) |
|
27 | + { |
|
28 | + return rand((2 * ($skill - 100) / 25), 10); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | } |
32 | 32 | \ No newline at end of file |