Exemplo n.º 1
0
 public function testScorer()
 {
     $league = new League();
     $team1 = new Team();
     $team1->setId(1);
     $league->addTeam($team1);
     $player1 = new Player();
     $player1->setId(1);
     $player1->setTeam($team1);
     $team2 = new Team();
     $team2->setId(2);
     $league->addTeam($team2);
     $player2 = new Player();
     $player2->setId(2);
     $player2->setTeam($team2);
     $fixture = new Fixture();
     $fixture->setTeamHome($team1);
     $fixture->setTeamAway($team2);
     $league->addFixture($fixture);
     $fixture->addEvent(Event::createGoal($fixture, $team1, $player1, 1));
     $fixture->addEvent(Event::createGoal($fixture, $team1, $player1, 2));
     $fixture->addEvent(Event::createGoal($fixture, $team2, $player2, 3));
     $scorer = $this->leagueService->getScorer(array($fixture));
     $this->assertEquals($player1, $scorer[0]->getPlayer());
     $this->assertEquals($player2, $scorer[1]->getPlayer());
     $this->assertEquals(2, $scorer[0]->getGoals());
     $this->assertEquals(1, $scorer[1]->getGoals());
 }
 /**
  * @param Fixture $fixture
  *
  * @return Event
  */
 public function createRandomEvent(Fixture $fixture)
 {
     $possibleTeams = array($fixture->getTeamHome(), $fixture->getTeamAway());
     /** @var Team $attackingTeam */
     $attackingTeam = $possibleTeams[mt_rand(0, count($possibleTeams) - 1)];
     $defendingTeam = $attackingTeam->equals($fixture->getTeamHome()) ? $fixture->getTeamAway() : $fixture->getTeamHome();
     $attacker = $attackingTeam->getRandomPlayerFromLineup();
     $defender = $defendingTeam->getRandomPlayerFromLineup();
     $eventType = $attacker->getSkillOffense() * 2 > $defender->getSkillDefense() * 3 ? Event::TYPE_GOAL : Event::TYPE_CHANCE;
     $event = Event::create($fixture, $eventType, $attackingTeam, $attacker, $fixture->getMinutesPlayed());
     return $event;
 }
Exemplo n.º 3
0
 /**
  * @param int $season
  *
  * @throws \Exception
  */
 public function createFixtures($season)
 {
     /** @var League $league */
     $league = $this->entityManager->getRepository('CoreBundle:League')->findOneBy(array());
     $generator = new Generator(count($league->getTeams()));
     $matches = $generator->createFixtures();
     $listOfTeams = $league->getTeams();
     foreach ($matches as $match) {
         $fixture = new Fixture();
         $fixture->setSeason($season);
         $fixture->setWeek($match->getWeek());
         $fixture->setTeamHome($listOfTeams[$match->getTeamHome() - 1]);
         $fixture->setTeamAway($listOfTeams[$match->getTeamAway() - 1]);
         $fixture->setLeague($league);
         $this->entityManager->persist($fixture);
     }
     $this->entityManager->flush();
 }
Exemplo n.º 4
0
 /**
  * @param Fixture $fixture
  * @param Team $team
  *
  * @return int
  */
 private function countGoalsInEvents(Fixture $fixture, Team $team)
 {
     $goalsInEvents = 0;
     foreach ($fixture->getEvents() as $event) {
         if ($event->isGoal() && $event->getTeam()->equals($team)) {
             $goalsInEvents++;
         }
     }
     return $goalsInEvents;
 }
 /**
  * @param Team $teamHome
  * @param Team $teamAway
  *
  * @return Fixture
  *
  * @throws MatchException
  */
 private function createFixture(Team $teamHome, Team $teamAway)
 {
     $fixture = new Fixture();
     $fixture->setTeamHome($teamHome);
     $fixture->setTeamAway($teamAway);
     return $fixture;
 }