@@ -5,26 +5,26 @@ |
||
5 | 5 | |
6 | 6 | class CreatePlayersTable |
7 | 7 | { |
8 | - /** |
|
9 | - * Run the migrations. |
|
10 | - * |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function run() |
|
14 | - { |
|
15 | - Capsule::schema()->dropIfExists('players'); |
|
16 | - Capsule::schema()->create('players', function (Blueprint $table) { |
|
17 | - $table->increments('id'); |
|
18 | - $table->string('name'); |
|
19 | - $table->string('surname'); |
|
20 | - $table->tinyInteger('age'); |
|
21 | - $table->string('nationality',2); |
|
22 | - $table->float('skillAvg'); |
|
23 | - $table->float('wageReq'); |
|
24 | - $table->float('val'); |
|
25 | - $table->string('role',2); |
|
26 | - $table->integer('team_id')->nullable(); |
|
27 | - $table->timestamps(); |
|
28 | - }); |
|
29 | - } |
|
8 | + /** |
|
9 | + * Run the migrations. |
|
10 | + * |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function run() |
|
14 | + { |
|
15 | + Capsule::schema()->dropIfExists('players'); |
|
16 | + Capsule::schema()->create('players', function (Blueprint $table) { |
|
17 | + $table->increments('id'); |
|
18 | + $table->string('name'); |
|
19 | + $table->string('surname'); |
|
20 | + $table->tinyInteger('age'); |
|
21 | + $table->string('nationality',2); |
|
22 | + $table->float('skillAvg'); |
|
23 | + $table->float('wageReq'); |
|
24 | + $table->float('val'); |
|
25 | + $table->string('role',2); |
|
26 | + $table->integer('team_id')->nullable(); |
|
27 | + $table->timestamps(); |
|
28 | + }); |
|
29 | + } |
|
30 | 30 | } |
@@ -13,16 +13,16 @@ |
||
13 | 13 | public function run() |
14 | 14 | { |
15 | 15 | Capsule::schema()->dropIfExists('players'); |
16 | - Capsule::schema()->create('players', function (Blueprint $table) { |
|
16 | + Capsule::schema()->create('players', function(Blueprint $table) { |
|
17 | 17 | $table->increments('id'); |
18 | 18 | $table->string('name'); |
19 | 19 | $table->string('surname'); |
20 | 20 | $table->tinyInteger('age'); |
21 | - $table->string('nationality',2); |
|
21 | + $table->string('nationality', 2); |
|
22 | 22 | $table->float('skillAvg'); |
23 | 23 | $table->float('wageReq'); |
24 | 24 | $table->float('val'); |
25 | - $table->string('role',2); |
|
25 | + $table->string('role', 2); |
|
26 | 26 | $table->integer('team_id')->nullable(); |
27 | 27 | $table->timestamps(); |
28 | 28 | }); |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | use Illuminate\Database\Capsule\Manager as Capsule; |
4 | 4 | |
5 | -$dotenv = new Dotenv\Dotenv(__DIR__ . "/../"); |
|
5 | +$dotenv = new Dotenv\Dotenv(__DIR__."/../"); |
|
6 | 6 | $dotenv->load(); |
7 | 7 | |
8 | 8 | /** |
@@ -4,9 +4,9 @@ discard block |
||
4 | 4 | |
5 | 5 | $dotenv = new Dotenv\Dotenv(__DIR__ . "/../"); |
6 | 6 | try { |
7 | - $dotenv->load(); |
|
7 | + $dotenv->load(); |
|
8 | 8 | } catch (Exception $e) { |
9 | - //yummy exception |
|
9 | + //yummy exception |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | /** |
@@ -14,14 +14,14 @@ discard block |
||
14 | 14 | */ |
15 | 15 | $capsule = new Capsule; |
16 | 16 | $capsule->addConnection(array( |
17 | - 'driver' => 'mysql', |
|
18 | - 'host' => 'localhost', |
|
19 | - 'database' => 'dsmanager', |
|
20 | - 'username' => getenv('USERNAME'), |
|
21 | - 'password' => getenv('PASSWORD'), |
|
22 | - 'charset' => 'utf8', |
|
23 | - 'collation' => 'utf8_general_ci', |
|
24 | - 'prefix' => '' |
|
17 | + 'driver' => 'mysql', |
|
18 | + 'host' => 'localhost', |
|
19 | + 'database' => 'dsmanager', |
|
20 | + 'username' => getenv('USERNAME'), |
|
21 | + 'password' => getenv('PASSWORD'), |
|
22 | + 'charset' => 'utf8', |
|
23 | + 'collation' => 'utf8_general_ci', |
|
24 | + 'prefix' => '' |
|
25 | 25 | )); |
26 | 26 | $capsule->setAsGlobal(); |
27 | 27 | $capsule->bootEloquent(); |
@@ -31,8 +31,8 @@ |
||
31 | 31 | |
32 | 32 | /** |
33 | 33 | * MatchResult constructor. |
34 | - * @param $goalHome |
|
35 | - * @param $goalAway |
|
34 | + * @param integer $goalHome |
|
35 | + * @param integer $goalAway |
|
36 | 36 | * @param Team $home |
37 | 37 | * @param Team $away |
38 | 38 | */ |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | namespace App\Lib\DsManager\Models; |
4 | 4 | |
5 | -use App\Lib\DsManager\Helpers\Randomizer; |
|
6 | -use App\Lib\DsManager\Models\Common\DsManagerModel; |
|
5 | +use App\Lib\DsManager\Helpers\Randomizer; |
|
6 | +use App\Lib\DsManager\Models\Common\DsManagerModel; |
|
7 | 7 | use App\Lib\Helpers\Config; |
8 | 8 | |
9 | 9 |
@@ -13,142 +13,142 @@ |
||
13 | 13 | */ |
14 | 14 | class MatchResult extends DsManagerModel |
15 | 15 | { |
16 | - /** |
|
17 | - * @var |
|
18 | - */ |
|
19 | - private $goalHome; |
|
20 | - /** |
|
21 | - * @var |
|
22 | - */ |
|
23 | - private $goalAway; |
|
24 | - /** |
|
25 | - * @var Team |
|
26 | - */ |
|
27 | - private $homeTeam; |
|
28 | - /** |
|
29 | - * @var Team |
|
30 | - */ |
|
31 | - private $awayTeam; |
|
16 | + /** |
|
17 | + * @var |
|
18 | + */ |
|
19 | + private $goalHome; |
|
20 | + /** |
|
21 | + * @var |
|
22 | + */ |
|
23 | + private $goalAway; |
|
24 | + /** |
|
25 | + * @var Team |
|
26 | + */ |
|
27 | + private $homeTeam; |
|
28 | + /** |
|
29 | + * @var Team |
|
30 | + */ |
|
31 | + private $awayTeam; |
|
32 | 32 | |
33 | - /** |
|
34 | - * MatchResult constructor. |
|
35 | - * @param $goalHome |
|
36 | - * @param $goalAway |
|
37 | - * @param Team $home |
|
38 | - * @param Team $away |
|
39 | - */ |
|
40 | - public function __construct($goalHome, $goalAway, Team $home, Team $away) |
|
41 | - { |
|
42 | - $this->goalHome = $goalHome; |
|
43 | - $this->goalAway = $goalAway; |
|
44 | - $this->homeTeam = $home; |
|
45 | - $this->awayTeam = $away; |
|
46 | - } |
|
33 | + /** |
|
34 | + * MatchResult constructor. |
|
35 | + * @param $goalHome |
|
36 | + * @param $goalAway |
|
37 | + * @param Team $home |
|
38 | + * @param Team $away |
|
39 | + */ |
|
40 | + public function __construct($goalHome, $goalAway, Team $home, Team $away) |
|
41 | + { |
|
42 | + $this->goalHome = $goalHome; |
|
43 | + $this->goalAway = $goalAway; |
|
44 | + $this->homeTeam = $home; |
|
45 | + $this->awayTeam = $away; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return array |
|
50 | - */ |
|
51 | - public function getWinnerLoser() |
|
52 | - { |
|
53 | - $isDraw = false; |
|
54 | - $winner = null; |
|
55 | - $loser = null; |
|
56 | - if ($this->goalAway == $this->goalHome) { |
|
57 | - $isDraw = true; |
|
58 | - $winner = $this->homeTeam; |
|
59 | - $loser = $this->awayTeam; |
|
60 | - } else if ($this->goalHome > $this->goalAway) { |
|
61 | - $winner = $this->homeTeam; |
|
62 | - $loser = $this->awayTeam; |
|
63 | - } else { |
|
64 | - $winner = $this->awayTeam; |
|
65 | - $loser = $this->homeTeam; |
|
66 | - } |
|
48 | + /** |
|
49 | + * @return array |
|
50 | + */ |
|
51 | + public function getWinnerLoser() |
|
52 | + { |
|
53 | + $isDraw = false; |
|
54 | + $winner = null; |
|
55 | + $loser = null; |
|
56 | + if ($this->goalAway == $this->goalHome) { |
|
57 | + $isDraw = true; |
|
58 | + $winner = $this->homeTeam; |
|
59 | + $loser = $this->awayTeam; |
|
60 | + } else if ($this->goalHome > $this->goalAway) { |
|
61 | + $winner = $this->homeTeam; |
|
62 | + $loser = $this->awayTeam; |
|
63 | + } else { |
|
64 | + $winner = $this->awayTeam; |
|
65 | + $loser = $this->homeTeam; |
|
66 | + } |
|
67 | 67 | |
68 | - return [ |
|
69 | - 'is_draw' => $isDraw, |
|
70 | - 'winner' => $this->cleanTeam($winner->toArray()), |
|
71 | - 'loser' => $this->cleanTeam($loser->toArray()) |
|
72 | - ]; |
|
73 | - } |
|
68 | + return [ |
|
69 | + 'is_draw' => $isDraw, |
|
70 | + 'winner' => $this->cleanTeam($winner->toArray()), |
|
71 | + 'loser' => $this->cleanTeam($loser->toArray()) |
|
72 | + ]; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @return array |
|
77 | - */ |
|
78 | - public function toArray() |
|
79 | - { |
|
80 | - $result = []; |
|
81 | - $result["goal_home"] = $this->goalHome; |
|
82 | - $result["goal_away"] = $this->goalAway; |
|
83 | - $result['info'] = $this->getWinnerLoser(); |
|
84 | - $result['info']['scorers'] = $this->getScorers(); |
|
85 | - $result['simulated'] = true; |
|
86 | - return $result; |
|
87 | - } |
|
75 | + /** |
|
76 | + * @return array |
|
77 | + */ |
|
78 | + public function toArray() |
|
79 | + { |
|
80 | + $result = []; |
|
81 | + $result["goal_home"] = $this->goalHome; |
|
82 | + $result["goal_away"] = $this->goalAway; |
|
83 | + $result['info'] = $this->getWinnerLoser(); |
|
84 | + $result['info']['scorers'] = $this->getScorers(); |
|
85 | + $result['simulated'] = true; |
|
86 | + return $result; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @param array $team |
|
91 | - * @return array |
|
92 | - */ |
|
93 | - private function cleanTeam(array $team) |
|
94 | - { |
|
95 | - $fieldsToClean = [ |
|
96 | - 'coach', |
|
97 | - 'roster', |
|
98 | - ]; |
|
89 | + /** |
|
90 | + * @param array $team |
|
91 | + * @return array |
|
92 | + */ |
|
93 | + private function cleanTeam(array $team) |
|
94 | + { |
|
95 | + $fieldsToClean = [ |
|
96 | + 'coach', |
|
97 | + 'roster', |
|
98 | + ]; |
|
99 | 99 | |
100 | - foreach ($fieldsToClean as $field) { |
|
101 | - if (array_key_exists($field, $team)) { |
|
102 | - unset($team[$field]); |
|
103 | - } |
|
104 | - } |
|
105 | - return $team; |
|
106 | - } |
|
100 | + foreach ($fieldsToClean as $field) { |
|
101 | + if (array_key_exists($field, $team)) { |
|
102 | + unset($team[$field]); |
|
103 | + } |
|
104 | + } |
|
105 | + return $team; |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - private function getScorers() |
|
112 | - { |
|
113 | - $scorers = [ |
|
114 | - 'home' => [], |
|
115 | - 'away' => [] |
|
116 | - ]; |
|
117 | - for ($i = 0; $i < $this->goalHome; $i++) { |
|
118 | - $scorers['home'][] = $this->pickAScorer($this->homeTeam); |
|
119 | - } |
|
120 | - for ($i = 0; $i < $this->goalAway; $i++) { |
|
121 | - $scorers['away'][] = $this->pickAScorer($this->awayTeam); |
|
122 | - } |
|
123 | - return $scorers; |
|
124 | - } |
|
108 | + /** |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + private function getScorers() |
|
112 | + { |
|
113 | + $scorers = [ |
|
114 | + 'home' => [], |
|
115 | + 'away' => [] |
|
116 | + ]; |
|
117 | + for ($i = 0; $i < $this->goalHome; $i++) { |
|
118 | + $scorers['home'][] = $this->pickAScorer($this->homeTeam); |
|
119 | + } |
|
120 | + for ($i = 0; $i < $this->goalAway; $i++) { |
|
121 | + $scorers['away'][] = $this->pickAScorer($this->awayTeam); |
|
122 | + } |
|
123 | + return $scorers; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * @param Team $team |
|
128 | - * @return Player |
|
129 | - */ |
|
130 | - private function pickAScorer(Team $team) |
|
131 | - { |
|
132 | - $player = null; |
|
133 | - if (Randomizer::boolOnPercentage(70)) { |
|
134 | - $roles = Config::get('modules.roles'); |
|
135 | - $forwards = array_splice($roles, count($roles) / 2); |
|
136 | - $pos = array_rand($forwards); |
|
137 | - unset($forwards[$pos]); |
|
138 | - $player = $team->getBestPlayerForRole($pos); |
|
139 | - while (empty($player)) { |
|
140 | - if (!empty($forwards)) { |
|
141 | - $pos = array_rand($forwards); |
|
142 | - unset($forwards[$pos]); |
|
143 | - $player = $team->getBestPlayerForRole($pos); |
|
144 | - } else { |
|
145 | - $player = $team->roster[array_rand($team->roster)]; |
|
146 | - } |
|
147 | - } |
|
148 | - } else { |
|
149 | - $player = $team->roster[array_rand($team->roster)]; |
|
150 | - } |
|
151 | - return $player; |
|
152 | - } |
|
126 | + /** |
|
127 | + * @param Team $team |
|
128 | + * @return Player |
|
129 | + */ |
|
130 | + private function pickAScorer(Team $team) |
|
131 | + { |
|
132 | + $player = null; |
|
133 | + if (Randomizer::boolOnPercentage(70)) { |
|
134 | + $roles = Config::get('modules.roles'); |
|
135 | + $forwards = array_splice($roles, count($roles) / 2); |
|
136 | + $pos = array_rand($forwards); |
|
137 | + unset($forwards[$pos]); |
|
138 | + $player = $team->getBestPlayerForRole($pos); |
|
139 | + while (empty($player)) { |
|
140 | + if (!empty($forwards)) { |
|
141 | + $pos = array_rand($forwards); |
|
142 | + unset($forwards[$pos]); |
|
143 | + $player = $team->getBestPlayerForRole($pos); |
|
144 | + } else { |
|
145 | + $player = $team->roster[array_rand($team->roster)]; |
|
146 | + } |
|
147 | + } |
|
148 | + } else { |
|
149 | + $player = $team->roster[array_rand($team->roster)]; |
|
150 | + } |
|
151 | + return $player; |
|
152 | + } |
|
153 | 153 | |
154 | 154 | } |
155 | 155 | \ No newline at end of file |
@@ -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 |
@@ -3,20 +3,20 @@ |
||
3 | 3 | |
4 | 4 | class BMatchesSeeder |
5 | 5 | { |
6 | - function run() |
|
7 | - { |
|
8 | - $teams = \App\Lib\DsManager\Models\Orm\Team::all()->toArray(); |
|
9 | - $halfTheTeams = count($teams) / 2; |
|
10 | - $chunks = array_chunk($teams, $halfTheTeams); |
|
11 | - $teamsSlice1 = $chunks[0]; |
|
12 | - $teamsSlice2 = $chunks[1]; |
|
13 | - for ($i = 0; $i < $halfTheTeams; $i++) { |
|
14 | - \App\Lib\DsManager\Models\Orm\Match::create( |
|
15 | - [ |
|
16 | - 'home_team_id' => $teamsSlice1[$i]['id'], |
|
17 | - 'away_team_id' => $teamsSlice2[$i]['id'] |
|
18 | - ] |
|
19 | - ); |
|
20 | - } |
|
21 | - } |
|
6 | + function run() |
|
7 | + { |
|
8 | + $teams = \App\Lib\DsManager\Models\Orm\Team::all()->toArray(); |
|
9 | + $halfTheTeams = count($teams) / 2; |
|
10 | + $chunks = array_chunk($teams, $halfTheTeams); |
|
11 | + $teamsSlice1 = $chunks[0]; |
|
12 | + $teamsSlice2 = $chunks[1]; |
|
13 | + for ($i = 0; $i < $halfTheTeams; $i++) { |
|
14 | + \App\Lib\DsManager\Models\Orm\Match::create( |
|
15 | + [ |
|
16 | + 'home_team_id' => $teamsSlice1[$i]['id'], |
|
17 | + 'away_team_id' => $teamsSlice2[$i]['id'] |
|
18 | + ] |
|
19 | + ); |
|
20 | + } |
|
21 | + } |
|
22 | 22 | } |
23 | 23 | \ No newline at end of file |
@@ -5,24 +5,24 @@ |
||
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('home_team_id'); |
|
19 | - $table->integer('goal_home')->default(0); |
|
20 | - $table->integer('away_team_id'); |
|
21 | - $table->integer('goal_away')->default(0); |
|
22 | - $table->boolean('simulated')->default(false); |
|
23 | - $table->text('info')->nullable(); |
|
24 | - $table->date('match_date')->default(\Carbon\Carbon::now()); |
|
25 | - $table->timestamps(); |
|
26 | - }); |
|
27 | - } |
|
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('home_team_id'); |
|
19 | + $table->integer('goal_home')->default(0); |
|
20 | + $table->integer('away_team_id'); |
|
21 | + $table->integer('goal_away')->default(0); |
|
22 | + $table->boolean('simulated')->default(false); |
|
23 | + $table->text('info')->nullable(); |
|
24 | + $table->date('match_date')->default(\Carbon\Carbon::now()); |
|
25 | + $table->timestamps(); |
|
26 | + }); |
|
27 | + } |
|
28 | 28 | } |
@@ -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); |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | $c = new \Slim\Container($configuration); |
18 | 18 | $api = new \Slim\App($c); |
19 | 19 | |
20 | -$api->get('/ping', function ($request, $response, $args) { |
|
20 | +$api->get('/ping', function($request, $response, $args) { |
|
21 | 21 | $jsonResp = json_encode( |
22 | 22 | [ |
23 | 23 | "status" => "service up", |
@@ -28,34 +28,34 @@ discard block |
||
28 | 28 | return Responder::getJsonResponse($jsonResp, $response); |
29 | 29 | }); |
30 | 30 | |
31 | -$api->get('/players', function ($request, $response, $args) { |
|
31 | +$api->get('/players', function($request, $response, $args) { |
|
32 | 32 | $json = json_encode(Player::all()); |
33 | 33 | return Responder::getJsonResponse($json, $response); |
34 | 34 | }); |
35 | 35 | |
36 | 36 | |
37 | -$api->get('/players/{id}', function ($request, $response, $args) { |
|
37 | +$api->get('/players/{id}', function($request, $response, $args) { |
|
38 | 38 | return Responder::getJsonResponse( |
39 | 39 | Player::findOrFail($args['id']), |
40 | 40 | $response |
41 | 41 | ); |
42 | 42 | }); |
43 | 43 | |
44 | -$api->get('/coaches', function ($request, $response, $args) { |
|
44 | +$api->get('/coaches', function($request, $response, $args) { |
|
45 | 45 | return Responder::getJsonResponse( |
46 | 46 | Coach::all(), |
47 | 47 | $response |
48 | 48 | ); |
49 | 49 | }); |
50 | 50 | |
51 | -$api->get('/teams', function ($request, $response, $args) { |
|
51 | +$api->get('/teams', function($request, $response, $args) { |
|
52 | 52 | return Responder::getJsonResponse( |
53 | 53 | Team::all(), |
54 | 54 | $response |
55 | 55 | ); |
56 | 56 | }); |
57 | 57 | |
58 | -$api->get('/teams/{id}', function ($request, $response, $args) { |
|
58 | +$api->get('/teams/{id}', function($request, $response, $args) { |
|
59 | 59 | return Responder::getJsonResponse( |
60 | 60 | Team::with( |
61 | 61 | 'roster', |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | ); |
70 | 70 | }); |
71 | 71 | |
72 | -$api->get('/teams/{id}/players', function ($request, $response, $args) { |
|
72 | +$api->get('/teams/{id}/players', function($request, $response, $args) { |
|
73 | 73 | return Responder::getJsonResponse( |
74 | 74 | Team::with( |
75 | 75 | 'roster' |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | ); |
83 | 83 | }); |
84 | 84 | |
85 | -$api->get('/teams/{id}/players/{playerId}', function ($request, $response, $args) { |
|
85 | +$api->get('/teams/{id}/players/{playerId}', function($request, $response, $args) { |
|
86 | 86 | return Responder::getJsonResponse( |
87 | 87 | Player::where( |
88 | 88 | [ |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | ); |
95 | 95 | }); |
96 | 96 | |
97 | -$api->get('/teams/{id}/coach', function ($request, $response, $args) { |
|
97 | +$api->get('/teams/{id}/coach', function($request, $response, $args) { |
|
98 | 98 | return Responder::getJsonResponse( |
99 | 99 | Team::with( |
100 | 100 | 'coach' |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | ); |
108 | 108 | }); |
109 | 109 | |
110 | -$api->get('/matches', function ($request, $response, $args) { |
|
110 | +$api->get('/matches', function($request, $response, $args) { |
|
111 | 111 | return Responder::getJsonResponse( |
112 | 112 | \App\Lib\DsManager\Models\Orm\Match::with( |
113 | 113 | 'homeTeam', |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | ); |
118 | 118 | }); |
119 | 119 | |
120 | -$api->get('/matches/{id}', function ($request, $response, $args) { |
|
120 | +$api->get('/matches/{id}', function($request, $response, $args) { |
|
121 | 121 | return Responder::getJsonResponse( |
122 | 122 | \App\Lib\DsManager\Models\Orm\Match::with( |
123 | 123 | 'homeTeam', |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | ); |
136 | 136 | }); |
137 | 137 | |
138 | -$api->get('/matches/{id}/result', function ($request, $response, $args) { |
|
138 | +$api->get('/matches/{id}/result', function($request, $response, $args) { |
|
139 | 139 | $result = \App\Lib\DsManager\Models\Orm\MatchResult::with( |
140 | 140 | 'homeTeam', |
141 | 141 | 'homeTeam.roster', |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | ); |
156 | 156 | }); |
157 | 157 | |
158 | -$api->put('/matches/{id}/simulate', function ($request, $response, $args) { |
|
158 | +$api->put('/matches/{id}/simulate', function($request, $response, $args) { |
|
159 | 159 | $result = \App\Lib\DsManager\Models\Orm\MatchResult::with( |
160 | 160 | 'homeTeam', |
161 | 161 | 'homeTeam.roster', |
@@ -10,184 +10,184 @@ |
||
10 | 10 | use \App\Lib\DsManager\Models\Orm\Coach; |
11 | 11 | |
12 | 12 | $configuration = [ |
13 | - 'settings' => [ |
|
14 | - 'displayErrorDetails' => true, |
|
15 | - ], |
|
13 | + 'settings' => [ |
|
14 | + 'displayErrorDetails' => true, |
|
15 | + ], |
|
16 | 16 | ]; |
17 | 17 | $c = new \Slim\Container($configuration); |
18 | 18 | $api = new \Slim\App($c); |
19 | 19 | |
20 | 20 | $api->get('/ping', function ($request, $response, $args) { |
21 | - $jsonResp = json_encode( |
|
22 | - [ |
|
23 | - "status" => "service up", |
|
24 | - "message" => "in a bottle", |
|
25 | - "config" => \App\Lib\Helpers\Config::get("config1.stuff") |
|
26 | - ] |
|
27 | - ); |
|
28 | - return Responder::getJsonResponse($jsonResp, $response); |
|
21 | + $jsonResp = json_encode( |
|
22 | + [ |
|
23 | + "status" => "service up", |
|
24 | + "message" => "in a bottle", |
|
25 | + "config" => \App\Lib\Helpers\Config::get("config1.stuff") |
|
26 | + ] |
|
27 | + ); |
|
28 | + return Responder::getJsonResponse($jsonResp, $response); |
|
29 | 29 | }); |
30 | 30 | |
31 | 31 | $api->get('/players', function ($request, $response, $args) { |
32 | - $json = json_encode(Player::all()); |
|
33 | - return Responder::getJsonResponse($json, $response); |
|
32 | + $json = json_encode(Player::all()); |
|
33 | + return Responder::getJsonResponse($json, $response); |
|
34 | 34 | }); |
35 | 35 | |
36 | 36 | |
37 | 37 | $api->get('/players/{id}', function ($request, $response, $args) { |
38 | - return Responder::getJsonResponse( |
|
39 | - Player::findOrFail($args['id']), |
|
40 | - $response |
|
41 | - ); |
|
38 | + return Responder::getJsonResponse( |
|
39 | + Player::findOrFail($args['id']), |
|
40 | + $response |
|
41 | + ); |
|
42 | 42 | }); |
43 | 43 | |
44 | 44 | $api->get('/coaches', function ($request, $response, $args) { |
45 | - return Responder::getJsonResponse( |
|
46 | - Coach::all(), |
|
47 | - $response |
|
48 | - ); |
|
45 | + return Responder::getJsonResponse( |
|
46 | + Coach::all(), |
|
47 | + $response |
|
48 | + ); |
|
49 | 49 | }); |
50 | 50 | |
51 | 51 | $api->get('/teams', function ($request, $response, $args) { |
52 | - return Responder::getJsonResponse( |
|
53 | - Team::all(), |
|
54 | - $response |
|
55 | - ); |
|
52 | + return Responder::getJsonResponse( |
|
53 | + Team::all(), |
|
54 | + $response |
|
55 | + ); |
|
56 | 56 | }); |
57 | 57 | |
58 | 58 | $api->get('/teams/{id}', function ($request, $response, $args) { |
59 | - return Responder::getJsonResponse( |
|
60 | - Team::with( |
|
61 | - 'roster', |
|
62 | - 'coach' |
|
63 | - )->where( |
|
64 | - [ |
|
65 | - 'id' => $args['id'] |
|
66 | - ] |
|
67 | - )->get(), |
|
68 | - $response |
|
69 | - ); |
|
59 | + return Responder::getJsonResponse( |
|
60 | + Team::with( |
|
61 | + 'roster', |
|
62 | + 'coach' |
|
63 | + )->where( |
|
64 | + [ |
|
65 | + 'id' => $args['id'] |
|
66 | + ] |
|
67 | + )->get(), |
|
68 | + $response |
|
69 | + ); |
|
70 | 70 | }); |
71 | 71 | |
72 | 72 | $api->get('/teams/{id}/players', function ($request, $response, $args) { |
73 | - return Responder::getJsonResponse( |
|
74 | - Team::with( |
|
75 | - 'roster' |
|
76 | - )->where( |
|
77 | - [ |
|
78 | - 'id' => $args['id'] |
|
79 | - ] |
|
80 | - )->get(), |
|
81 | - $response |
|
82 | - ); |
|
73 | + return Responder::getJsonResponse( |
|
74 | + Team::with( |
|
75 | + 'roster' |
|
76 | + )->where( |
|
77 | + [ |
|
78 | + 'id' => $args['id'] |
|
79 | + ] |
|
80 | + )->get(), |
|
81 | + $response |
|
82 | + ); |
|
83 | 83 | }); |
84 | 84 | |
85 | 85 | $api->get('/teams/{id}/players/{playerId}', function ($request, $response, $args) { |
86 | - return Responder::getJsonResponse( |
|
87 | - Player::where( |
|
88 | - [ |
|
89 | - 'id' => $args['playerId'], |
|
90 | - 'team_id' => $args['id'] |
|
91 | - ] |
|
92 | - )->get(), |
|
93 | - $response |
|
94 | - ); |
|
86 | + return Responder::getJsonResponse( |
|
87 | + Player::where( |
|
88 | + [ |
|
89 | + 'id' => $args['playerId'], |
|
90 | + 'team_id' => $args['id'] |
|
91 | + ] |
|
92 | + )->get(), |
|
93 | + $response |
|
94 | + ); |
|
95 | 95 | }); |
96 | 96 | |
97 | 97 | $api->get('/teams/{id}/coach', function ($request, $response, $args) { |
98 | - return Responder::getJsonResponse( |
|
99 | - Team::with( |
|
100 | - 'coach' |
|
101 | - )->where( |
|
102 | - [ |
|
103 | - 'id' => $args['id'] |
|
104 | - ] |
|
105 | - )->get(), |
|
106 | - $response |
|
107 | - ); |
|
98 | + return Responder::getJsonResponse( |
|
99 | + Team::with( |
|
100 | + 'coach' |
|
101 | + )->where( |
|
102 | + [ |
|
103 | + 'id' => $args['id'] |
|
104 | + ] |
|
105 | + )->get(), |
|
106 | + $response |
|
107 | + ); |
|
108 | 108 | }); |
109 | 109 | |
110 | 110 | $api->get('/matches', function ($request, $response, $args) { |
111 | - return Responder::getJsonResponse( |
|
112 | - \App\Lib\DsManager\Models\Orm\Match::with( |
|
113 | - 'homeTeam', |
|
114 | - 'awayTeam' |
|
115 | - )->get(), |
|
116 | - $response |
|
117 | - ); |
|
111 | + return Responder::getJsonResponse( |
|
112 | + \App\Lib\DsManager\Models\Orm\Match::with( |
|
113 | + 'homeTeam', |
|
114 | + 'awayTeam' |
|
115 | + )->get(), |
|
116 | + $response |
|
117 | + ); |
|
118 | 118 | }); |
119 | 119 | |
120 | 120 | $api->get('/matches/{id}', function ($request, $response, $args) { |
121 | - return Responder::getJsonResponse( |
|
122 | - \App\Lib\DsManager\Models\Orm\Match::with( |
|
123 | - 'homeTeam', |
|
124 | - 'homeTeam.roster', |
|
125 | - 'homeTeam.coach', |
|
126 | - 'awayTeam', |
|
127 | - 'awayTeam.roster', |
|
128 | - 'awayTeam.coach' |
|
129 | - )->where( |
|
130 | - [ |
|
131 | - 'id' => $args['id'] |
|
132 | - ] |
|
133 | - )->first(), |
|
134 | - $response |
|
135 | - ); |
|
121 | + return Responder::getJsonResponse( |
|
122 | + \App\Lib\DsManager\Models\Orm\Match::with( |
|
123 | + 'homeTeam', |
|
124 | + 'homeTeam.roster', |
|
125 | + 'homeTeam.coach', |
|
126 | + 'awayTeam', |
|
127 | + 'awayTeam.roster', |
|
128 | + 'awayTeam.coach' |
|
129 | + )->where( |
|
130 | + [ |
|
131 | + 'id' => $args['id'] |
|
132 | + ] |
|
133 | + )->first(), |
|
134 | + $response |
|
135 | + ); |
|
136 | 136 | }); |
137 | 137 | |
138 | 138 | $api->get('/matches/{id}/result', function ($request, $response, $args) { |
139 | - $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
140 | - ->where( |
|
141 | - [ |
|
142 | - 'id' => $args['id'] |
|
143 | - ] |
|
144 | - )->first(); |
|
145 | - |
|
146 | - return Responder::getJsonResponse( |
|
147 | - $result, |
|
148 | - $response |
|
149 | - ); |
|
139 | + $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
140 | + ->where( |
|
141 | + [ |
|
142 | + 'id' => $args['id'] |
|
143 | + ] |
|
144 | + )->first(); |
|
145 | + |
|
146 | + return Responder::getJsonResponse( |
|
147 | + $result, |
|
148 | + $response |
|
149 | + ); |
|
150 | 150 | }); |
151 | 151 | |
152 | 152 | $api->put('/matches/{id}/simulate', function ($request, $response, $args) { |
153 | - $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
154 | - ->where( |
|
155 | - [ |
|
156 | - 'id' => $args['id'] |
|
157 | - ] |
|
158 | - )->first(); |
|
159 | - |
|
160 | - if (!empty($result) && !$result->simulated) { |
|
161 | - //simulate match |
|
162 | - $match = \App\Lib\DsManager\Models\Match::fromArray( |
|
163 | - \App\Lib\DsManager\Models\Orm\Match::complete() |
|
164 | - ->where( |
|
165 | - [ |
|
166 | - 'id' => $args['id'] |
|
167 | - ] |
|
168 | - )->first()->toArray() |
|
169 | - ); |
|
170 | - $matchResult = $match->simulate()->toArray(); |
|
171 | - $result = \App\Lib\DsManager\Models\Orm\MatchResult::where( |
|
172 | - [ |
|
173 | - 'id' => $args['id'] |
|
174 | - ] |
|
175 | - )->update( |
|
176 | - \App\Lib\DsManager\Models\Orm\MatchResult::castAttributes($matchResult) |
|
177 | - ); |
|
178 | - if ($result === 1) { |
|
179 | - $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
180 | - ->where( |
|
181 | - [ |
|
182 | - 'id' => $args['id'] |
|
183 | - ] |
|
184 | - )->first(); |
|
185 | - } |
|
186 | - |
|
187 | - } |
|
188 | - return Responder::getJsonResponse( |
|
189 | - $result, |
|
190 | - $response |
|
191 | - ); |
|
153 | + $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
154 | + ->where( |
|
155 | + [ |
|
156 | + 'id' => $args['id'] |
|
157 | + ] |
|
158 | + )->first(); |
|
159 | + |
|
160 | + if (!empty($result) && !$result->simulated) { |
|
161 | + //simulate match |
|
162 | + $match = \App\Lib\DsManager\Models\Match::fromArray( |
|
163 | + \App\Lib\DsManager\Models\Orm\Match::complete() |
|
164 | + ->where( |
|
165 | + [ |
|
166 | + 'id' => $args['id'] |
|
167 | + ] |
|
168 | + )->first()->toArray() |
|
169 | + ); |
|
170 | + $matchResult = $match->simulate()->toArray(); |
|
171 | + $result = \App\Lib\DsManager\Models\Orm\MatchResult::where( |
|
172 | + [ |
|
173 | + 'id' => $args['id'] |
|
174 | + ] |
|
175 | + )->update( |
|
176 | + \App\Lib\DsManager\Models\Orm\MatchResult::castAttributes($matchResult) |
|
177 | + ); |
|
178 | + if ($result === 1) { |
|
179 | + $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
180 | + ->where( |
|
181 | + [ |
|
182 | + 'id' => $args['id'] |
|
183 | + ] |
|
184 | + )->first(); |
|
185 | + } |
|
186 | + |
|
187 | + } |
|
188 | + return Responder::getJsonResponse( |
|
189 | + $result, |
|
190 | + $response |
|
191 | + ); |
|
192 | 192 | }); |
193 | 193 | $api->run(); |
194 | 194 | \ No newline at end of file |
@@ -9,62 +9,62 @@ |
||
9 | 9 | class Match extends DsManagerOrm |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $table = 'matches'; |
|
12 | + /** |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $table = 'matches'; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - protected $fillable = [ |
|
21 | - 'home_team_id', |
|
22 | - 'away_team_id' |
|
23 | - ]; |
|
17 | + /** |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + protected $fillable = [ |
|
21 | + 'home_team_id', |
|
22 | + 'away_team_id' |
|
23 | + ]; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $hidden = [ |
|
29 | - 'home_team_id', |
|
30 | - 'away_team_id', |
|
31 | - 'created_at', |
|
32 | - 'updated_at', |
|
33 | - 'info' |
|
34 | - ]; |
|
25 | + /** |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $hidden = [ |
|
29 | + 'home_team_id', |
|
30 | + 'away_team_id', |
|
31 | + 'created_at', |
|
32 | + 'updated_at', |
|
33 | + 'info' |
|
34 | + ]; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $casts = [ |
|
40 | - 'simulated' => 'boolean' |
|
41 | - ]; |
|
36 | + /** |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $casts = [ |
|
40 | + 'simulated' => 'boolean' |
|
41 | + ]; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
45 | - */ |
|
46 | - public function homeTeam() |
|
47 | - { |
|
48 | - return $this->belongsTo(Team::class, 'home_team_id'); |
|
49 | - } |
|
43 | + /** |
|
44 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
45 | + */ |
|
46 | + public function homeTeam() |
|
47 | + { |
|
48 | + return $this->belongsTo(Team::class, 'home_team_id'); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
53 | - */ |
|
54 | - public function awayTeam() |
|
55 | - { |
|
56 | - return $this->belongsTo(Team::class, 'away_team_id'); |
|
57 | - } |
|
51 | + /** |
|
52 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
53 | + */ |
|
54 | + public function awayTeam() |
|
55 | + { |
|
56 | + return $this->belongsTo(Team::class, 'away_team_id'); |
|
57 | + } |
|
58 | 58 | |
59 | - public function scopeComplete($query){ |
|
60 | - return $query->with( |
|
61 | - 'homeTeam', |
|
62 | - 'homeTeam.roster', |
|
63 | - 'homeTeam.coach', |
|
64 | - 'awayTeam', |
|
65 | - 'awayTeam.roster', |
|
66 | - 'awayTeam.coach' |
|
67 | - ); |
|
68 | - } |
|
59 | + public function scopeComplete($query){ |
|
60 | + return $query->with( |
|
61 | + 'homeTeam', |
|
62 | + 'homeTeam.roster', |
|
63 | + 'homeTeam.coach', |
|
64 | + 'awayTeam', |
|
65 | + 'awayTeam.roster', |
|
66 | + 'awayTeam.coach' |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | } |
71 | 71 | \ 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', |
@@ -8,222 +8,222 @@ |
||
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->assertNotEmpty($team->name); |
|
97 | - $this->assertNotEmpty($team->nationality); |
|
98 | - $this->assertNotEmpty($team->getAvgSkill()); |
|
99 | - $this->assertNotEmpty($team->getAvgAge()); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @group Match |
|
105 | - */ |
|
106 | - public function testGetRandomMatch() |
|
107 | - { |
|
108 | - for ($i = 1; $i <= 30; $i++) { |
|
109 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
110 | - $spanish = $rndF->getTeam(); |
|
111 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
112 | - $italian = $rndF->getTeam(); |
|
113 | - $this->assertNotEmpty($spanish); |
|
114 | - $this->assertNotEmpty($italian); |
|
115 | - $this->assertNotEmpty($italian->name); |
|
116 | - $this->assertNotEmpty($spanish); |
|
117 | - $this->assertNotEmpty($spanish->name); |
|
118 | - |
|
119 | - $this->assertNotEmpty($italian->getAvgSkill()); |
|
120 | - $this->assertNotEmpty($spanish->getAvgSkill()); |
|
121 | - $result = (new \App\Lib\DsManager\Models\Match($italian, $spanish))->simulate()->toArray(); |
|
122 | - $this->assertNotEmpty($result); |
|
123 | - $this->assertGreaterThanOrEqual(0, $result['goal_home']); |
|
124 | - $this->assertGreaterThanOrEqual(0, $result['goal_away']); |
|
125 | - |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @group Match |
|
131 | - * @group MatchResult |
|
132 | - * @group matchresultoutput |
|
133 | - */ |
|
134 | - public function testMatchFromExistingTeams() |
|
135 | - { |
|
136 | - $teamHome = 1; |
|
137 | - $teamAway = 2; |
|
138 | - $homeOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamHome])->first(); |
|
139 | - $awayOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamAway])->first(); |
|
140 | - $home = \App\Lib\DsManager\Models\Team::fromArray($homeOrm->toArray()); |
|
141 | - $away = \App\Lib\DsManager\Models\Team::fromArray($awayOrm->toArray()); |
|
142 | - |
|
143 | - $match = new \App\Lib\DsManager\Models\Match($home, $away); |
|
144 | - $result = $match->simulate()->toArray(); |
|
145 | - $this->assertNotEmpty($result); |
|
146 | - $this->assertGreaterThanOrEqual(0, $result['goal_away']); |
|
147 | - $this->assertGreaterThanOrEqual(0, $result['goal_home']); |
|
148 | - if ($result['goal_home'] > 0) { |
|
149 | - $this->assertNotEmpty($result['info']['scorers']['home']); |
|
150 | - foreach ($result['info']['scorers']['home'] as $scorerHome) { |
|
151 | - $this->assertEquals($scorerHome->team_id, $teamHome); |
|
152 | - } |
|
153 | - } else { |
|
154 | - $this->assertEmpty($result['info']['scorers']['home']); |
|
155 | - } |
|
156 | - if ($result['goal_away'] > 0) { |
|
157 | - $this->assertNotEmpty($result['info']['scorers']['away']); |
|
158 | - foreach ($result['info']['scorers']['away'] as $scorerAway) { |
|
159 | - $this->assertEquals($scorerAway->team_id, $teamAway); |
|
160 | - } |
|
161 | - } else { |
|
162 | - $this->assertEmpty($result['info']['scorers']['away']); |
|
163 | - } |
|
164 | - if ($result['goal_home'] == $result['goal_away']) { |
|
165 | - $this->assertTrue($result['info']['is_draw']); |
|
166 | - } else { |
|
167 | - $this->assertFalse($result['info']['is_draw']); |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @group Matches |
|
173 | - */ |
|
174 | - public function testGetRandomMatchesOneTeam() |
|
175 | - { |
|
176 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
177 | - $myTeam = $rndF->getTeam(); |
|
178 | - $win = 0; |
|
179 | - $lost = 0; |
|
180 | - $draw = 0; |
|
181 | - |
|
182 | - for ($i = 1; $i <= 2; $i++) { |
|
183 | - |
|
184 | - $randomLocale = \App\Lib\Helpers\Config::get('generic.localesSmall'); |
|
185 | - shuffle($randomLocale); |
|
186 | - $randomLocale = $randomLocale[0]; |
|
187 | - |
|
188 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller($randomLocale); |
|
189 | - $opponent = $rndF->getTeam(); |
|
190 | - $result = (new \App\Lib\DsManager\Models\Match($opponent, $myTeam))->simulate()->toArray(); |
|
191 | - $this->assertNotEmpty($result); |
|
192 | - $result = $result['info']; |
|
193 | - if (!$result['is_draw']) { |
|
194 | - if ($result['winner']['name'] == $myTeam->name) { |
|
195 | - $win++; |
|
196 | - } else { |
|
197 | - $lost++; |
|
198 | - } |
|
199 | - } else { |
|
200 | - $draw++; |
|
201 | - } |
|
202 | - } |
|
203 | - $this->assertGreaterThanOrEqual(0, $win); |
|
204 | - $this->assertGreaterThanOrEqual(0, $lost); |
|
205 | - $this->assertGreaterThanOrEqual(0, $draw); |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * @group Module |
|
210 | - */ |
|
211 | - public function testModule() |
|
212 | - { |
|
213 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
214 | - $team = $rndF->getTeam(); |
|
215 | - |
|
216 | - $modules = \App\Lib\Helpers\Config::get("modules.modules"); |
|
217 | - $modules = array_keys($modules); |
|
218 | - foreach ($modules as $mod) { |
|
219 | - $module = new \App\Lib\DsManager\Models\Module($mod); |
|
220 | - $this->assertNotEmpty($module); |
|
221 | - $this->assertNotNull($module->isDefensive()); |
|
222 | - $this->assertNotNull($module->isBalanced()); |
|
223 | - $this->assertNotNull($module->isOffensive()); |
|
224 | - $this->assertTrue(is_array($module->getRoleNeeded())); |
|
225 | - } |
|
226 | - $this->assertGreaterThan(0, $team->playersPerRoleArray()); |
|
227 | - } |
|
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->assertNotEmpty($team->name); |
|
97 | + $this->assertNotEmpty($team->nationality); |
|
98 | + $this->assertNotEmpty($team->getAvgSkill()); |
|
99 | + $this->assertNotEmpty($team->getAvgAge()); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @group Match |
|
105 | + */ |
|
106 | + public function testGetRandomMatch() |
|
107 | + { |
|
108 | + for ($i = 1; $i <= 30; $i++) { |
|
109 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
110 | + $spanish = $rndF->getTeam(); |
|
111 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
112 | + $italian = $rndF->getTeam(); |
|
113 | + $this->assertNotEmpty($spanish); |
|
114 | + $this->assertNotEmpty($italian); |
|
115 | + $this->assertNotEmpty($italian->name); |
|
116 | + $this->assertNotEmpty($spanish); |
|
117 | + $this->assertNotEmpty($spanish->name); |
|
118 | + |
|
119 | + $this->assertNotEmpty($italian->getAvgSkill()); |
|
120 | + $this->assertNotEmpty($spanish->getAvgSkill()); |
|
121 | + $result = (new \App\Lib\DsManager\Models\Match($italian, $spanish))->simulate()->toArray(); |
|
122 | + $this->assertNotEmpty($result); |
|
123 | + $this->assertGreaterThanOrEqual(0, $result['goal_home']); |
|
124 | + $this->assertGreaterThanOrEqual(0, $result['goal_away']); |
|
125 | + |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @group Match |
|
131 | + * @group MatchResult |
|
132 | + * @group matchresultoutput |
|
133 | + */ |
|
134 | + public function testMatchFromExistingTeams() |
|
135 | + { |
|
136 | + $teamHome = 1; |
|
137 | + $teamAway = 2; |
|
138 | + $homeOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamHome])->first(); |
|
139 | + $awayOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamAway])->first(); |
|
140 | + $home = \App\Lib\DsManager\Models\Team::fromArray($homeOrm->toArray()); |
|
141 | + $away = \App\Lib\DsManager\Models\Team::fromArray($awayOrm->toArray()); |
|
142 | + |
|
143 | + $match = new \App\Lib\DsManager\Models\Match($home, $away); |
|
144 | + $result = $match->simulate()->toArray(); |
|
145 | + $this->assertNotEmpty($result); |
|
146 | + $this->assertGreaterThanOrEqual(0, $result['goal_away']); |
|
147 | + $this->assertGreaterThanOrEqual(0, $result['goal_home']); |
|
148 | + if ($result['goal_home'] > 0) { |
|
149 | + $this->assertNotEmpty($result['info']['scorers']['home']); |
|
150 | + foreach ($result['info']['scorers']['home'] as $scorerHome) { |
|
151 | + $this->assertEquals($scorerHome->team_id, $teamHome); |
|
152 | + } |
|
153 | + } else { |
|
154 | + $this->assertEmpty($result['info']['scorers']['home']); |
|
155 | + } |
|
156 | + if ($result['goal_away'] > 0) { |
|
157 | + $this->assertNotEmpty($result['info']['scorers']['away']); |
|
158 | + foreach ($result['info']['scorers']['away'] as $scorerAway) { |
|
159 | + $this->assertEquals($scorerAway->team_id, $teamAway); |
|
160 | + } |
|
161 | + } else { |
|
162 | + $this->assertEmpty($result['info']['scorers']['away']); |
|
163 | + } |
|
164 | + if ($result['goal_home'] == $result['goal_away']) { |
|
165 | + $this->assertTrue($result['info']['is_draw']); |
|
166 | + } else { |
|
167 | + $this->assertFalse($result['info']['is_draw']); |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @group Matches |
|
173 | + */ |
|
174 | + public function testGetRandomMatchesOneTeam() |
|
175 | + { |
|
176 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
177 | + $myTeam = $rndF->getTeam(); |
|
178 | + $win = 0; |
|
179 | + $lost = 0; |
|
180 | + $draw = 0; |
|
181 | + |
|
182 | + for ($i = 1; $i <= 2; $i++) { |
|
183 | + |
|
184 | + $randomLocale = \App\Lib\Helpers\Config::get('generic.localesSmall'); |
|
185 | + shuffle($randomLocale); |
|
186 | + $randomLocale = $randomLocale[0]; |
|
187 | + |
|
188 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller($randomLocale); |
|
189 | + $opponent = $rndF->getTeam(); |
|
190 | + $result = (new \App\Lib\DsManager\Models\Match($opponent, $myTeam))->simulate()->toArray(); |
|
191 | + $this->assertNotEmpty($result); |
|
192 | + $result = $result['info']; |
|
193 | + if (!$result['is_draw']) { |
|
194 | + if ($result['winner']['name'] == $myTeam->name) { |
|
195 | + $win++; |
|
196 | + } else { |
|
197 | + $lost++; |
|
198 | + } |
|
199 | + } else { |
|
200 | + $draw++; |
|
201 | + } |
|
202 | + } |
|
203 | + $this->assertGreaterThanOrEqual(0, $win); |
|
204 | + $this->assertGreaterThanOrEqual(0, $lost); |
|
205 | + $this->assertGreaterThanOrEqual(0, $draw); |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * @group Module |
|
210 | + */ |
|
211 | + public function testModule() |
|
212 | + { |
|
213 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
|
214 | + $team = $rndF->getTeam(); |
|
215 | + |
|
216 | + $modules = \App\Lib\Helpers\Config::get("modules.modules"); |
|
217 | + $modules = array_keys($modules); |
|
218 | + foreach ($modules as $mod) { |
|
219 | + $module = new \App\Lib\DsManager\Models\Module($mod); |
|
220 | + $this->assertNotEmpty($module); |
|
221 | + $this->assertNotNull($module->isDefensive()); |
|
222 | + $this->assertNotNull($module->isBalanced()); |
|
223 | + $this->assertNotNull($module->isOffensive()); |
|
224 | + $this->assertTrue(is_array($module->getRoleNeeded())); |
|
225 | + } |
|
226 | + $this->assertGreaterThan(0, $team->playersPerRoleArray()); |
|
227 | + } |
|
228 | 228 | |
229 | 229 | } |