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 int $teamIndex
  *
  * @return Player
  */
 protected function createEntity($teamIndex)
 {
     $player = new Player();
     $player->setSkillDefense(rand(1, 100));
     $player->setSkillOffense(rand(1, 100));
     return $player;
 }
 public function testPlayerLinkFilter()
 {
     $player = new Player();
     $player->setId(1);
     $player->setName('Daniel Mecke');
     $this->assertEquals('<a href="generated_link">Daniel Mecke</a>', $this->linkExtension->playerLinkFilter($player));
 }
 public function testAddAndGetByPlayer()
 {
     $scorerManager = new ScorerManager();
     $player1 = new Player();
     $player1->setId(1);
     $scorer = $scorerManager->addAndGetByPlayer($player1);
     $this->assertEquals($player1, $scorer->getPlayer());
     $player2 = new Player();
     $player2->setId(2);
     $scorer = $scorerManager->addAndGetByPlayer($player2);
     $this->assertEquals($player2, $scorer->getPlayer());
     $scorer = $scorerManager->addAndGetByPlayer($player1);
     $this->assertEquals($player1, $scorer->getPlayer());
 }
Example #5
0
 public function testTrainByOffensiveTrainerWithSkill100()
 {
     $this->setUpPlayer(0, 0);
     $this->setUpTrainer(100, Trainer::PREFERRED_TRAINING_OFFENSIVE);
     $this->trainer->train($this->player);
     $this->assertEquals(25, $this->player->getTrainingValueDefense());
     $this->assertEquals(75, $this->player->getTrainingValueOffense());
 }
Example #6
0
 public function testUpdateSkill()
 {
     $this->setUpPlayer(20, 50, 100, -100);
     $this->player->updateSkills();
     $this->assertGreaterThanOrEqual(20, $this->player->getSkillDefense());
     $this->assertLessThanOrEqual(30, $this->player->getSkillDefense());
     $this->assertEquals(0, $this->player->getTrainingValueDefense());
     $this->assertGreaterThanOrEqual(0, $this->player->getSkillChangeDefense());
     $this->assertLessThanOrEqual(10, $this->player->getSkillChangeDefense());
     $this->assertGreaterThanOrEqual(40, $this->player->getSkillOffense());
     $this->assertLessThanOrEqual(50, $this->player->getSkillOffense());
     $this->assertEquals(0, $this->player->getTrainingValueOffense());
     $this->assertGreaterThanOrEqual(-10, $this->player->getSkillChangeOffense());
     $this->assertLessThanOrEqual(0, $this->player->getSkillChangeOffense());
 }
 /**
  * @param UserEvent $event
  */
 public function onRegister(UserEvent $event)
 {
     /** @var User $user */
     $user = $event->getUser();
     $player = new Player();
     $player->setName($user->getUsername());
     $player->setSkillDefense(rand(1, 100));
     $player->setSkillOffense(rand(1, 100));
     /** @var Team[] $teams */
     $teams = $this->entityManager->getRepository('CoreBundle:Team')->findAll();
     $player->setTeam($teams[rand(0, count($teams) - 1)]);
     $this->entityManager->persist($player);
     $user->setPlayer($player);
     $this->entityManager->flush();
 }
Example #8
0
 /**
  * @param GameDate $gameDate
  *
  * @return Transfer
  */
 public function execute(GameDate $gameDate)
 {
     $this->targetTeam->sendMoney($this->originTeam, $this->amount);
     $this->player->setTeam($this->targetTeam);
     return Transfer::createFromOffer($this, $gameDate);
 }
Example #9
0
 public function testHandleTraining()
 {
     $this->team->setTrainer(new Trainer());
     $this->team->addPlayer(new Player());
     $player = new Player();
     $player->setTrainingValueDefense(10);
     $player->setTrainingValueOffense(10);
     $this->team->addPlayer($player);
     $this->team->train();
     $players = $this->team->getPlayers();
     $this->assertEquals(1, $players[0]->getTrainingValueDefense());
     $this->assertEquals(1, $players[0]->getTrainingValueOffense());
     $this->assertEquals(11, $players[1]->getTrainingValueDefense());
     $this->assertEquals(11, $players[1]->getTrainingValueOffense());
 }
 /**
  * @param Player $player
  *
  * @return float
  */
 private function calculateBaseValue(Player $player)
 {
     $skill = $player->getSkillDefense() * $this->manager->getTransferFactorDefensiveSkill() + $player->getSkillOffense() * $this->manager->getTransferFactorOffensiveSkill();
     return $skill / ($this->manager->getTransferFactorDefensiveSkill() + $this->manager->getTransferFactorOffensiveSkill());
 }
Example #11
0
 public function testCreateTransferOffer()
 {
     $originTeam = new Team();
     $targetTeam = new Team();
     $this->manager->setTeam($targetTeam);
     $player = new Player();
     $player->setSkillDefense(10);
     $player->setSkillOffense(10);
     $player->setTeam($originTeam);
     $transferOffer = $this->manager->createTransferOffer($player);
     $this->assertEquals($originTeam, $transferOffer->getOriginTeam());
     $this->assertEquals($targetTeam, $transferOffer->getTargetTeam());
     $this->assertEquals($player, $transferOffer->getPlayer());
     $this->assertEquals(100, $transferOffer->getAmount());
 }
Example #12
0
 /**
  * @param Player $a
  * @param Player $b
  *
  * @return bool
  */
 public static function compareAverageSkill(Player $a, Player $b)
 {
     return $a->getSkillAverage() < $b->getSkillAverage();
 }
Example #13
0
 /**
  * @param Player $player
  *
  * @return string
  */
 public function playerLinkFilter(Player $player)
 {
     return '<a href="' . $this->router->generate('profile_player', array('id' => $player->getId())) . '">' . $player->getName() . '</a>';
 }
 /**
  * @param int $skillDefense
  * @param int $skillOffense
  *
  * @return Player
  */
 private function createPlayer($skillDefense, $skillOffense)
 {
     $player = new Player();
     $player->setSkillDefense($skillDefense);
     $player->setSkillOffense($skillOffense);
     return $player;
 }
Example #15
0
 /**
  * @param Player $player
  */
 public function train(Player $player)
 {
     $defensive = ceil($this->skill * $this->getTrainingFactorDefensive());
     $offensive = ceil($this->skill * $this->getTrainingFactorOffensive());
     $player->addTrainingValueDefense($defensive);
     $player->addTrainingValueOffense($offensive);
 }