/**
  * @param Team $team
  * @return Player
  */
 private function pickAScorer(Team $team)
 {
     $player = null;
     if (Randomizer::boolOnPercentage(70)) {
         $roles = Config::get('modules.roles');
         $forwards = array_splice($roles, count($roles) / 2);
         $pos = array_rand($forwards);
         unset($forwards[$pos]);
         $player = $team->getBestPlayerForRole($pos);
         while (empty($player)) {
             if (!empty($forwards)) {
                 $pos = array_rand($forwards);
                 unset($forwards[$pos]);
                 $player = $team->getBestPlayerForRole($pos);
             } else {
                 $player = $team->roster[array_rand($team->roster)];
             }
         }
     } else {
         $player = $team->roster[array_rand($team->roster)];
     }
     return $player;
 }
 /**
  * @group Match
  * @group MatchResult
  * @group matchresultoutput
  */
 public function testMatchFromExistingTeams()
 {
     $teamHome = 1;
     $teamAway = 2;
     $homeOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamHome])->first();
     $awayOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamAway])->first();
     $home = \App\Lib\DsManager\Models\Team::fromArray($homeOrm->toArray());
     $away = \App\Lib\DsManager\Models\Team::fromArray($awayOrm->toArray());
     $match = new \App\Lib\DsManager\Models\Match($home, $away);
     $result = $match->simulate()->toArray();
     $this->assertNotEmpty($result);
     $this->assertGreaterThanOrEqual(0, $result['goal_away']);
     $this->assertGreaterThanOrEqual(0, $result['goal_home']);
     if ($result['goal_home'] > 0) {
         $this->assertNotEmpty($result['info']['scorers']['home']);
         foreach ($result['info']['scorers']['home'] as $scorerHome) {
             $this->assertEquals($scorerHome->team_id, $teamHome);
         }
     } else {
         $this->assertEmpty($result['info']['scorers']['home']);
     }
     if ($result['goal_away'] > 0) {
         $this->assertNotEmpty($result['info']['scorers']['away']);
         foreach ($result['info']['scorers']['away'] as $scorerAway) {
             $this->assertEquals($scorerAway->team_id, $teamAway);
         }
     } else {
         $this->assertEmpty($result['info']['scorers']['away']);
     }
     if ($result['goal_home'] == $result['goal_away']) {
         $this->assertTrue($result['info']['is_draw']);
     } else {
         $this->assertFalse($result['info']['is_draw']);
     }
 }
Exemple #3
0
 /**
  * @param Team $team
  * @return bool
  */
 public function isApplicableToTeam(Team $team)
 {
     return $this->isApplicableToArray($team->playersPerRoleArray());
 }
Exemple #4
0
 /**
  * @param array $ormMatchArray
  * @return Match
  */
 public static function fromArray($ormMatchArray = [])
 {
     $homeTeam = Team::fromArray($ormMatchArray['home_team']);
     $awayTeam = Team::fromArray($ormMatchArray['away_team']);
     return new Match($homeTeam, $awayTeam);
 }