public function calculateNewRatings(GameInfo $gameInfo, array $teams, array $teamRanks)
 {
     Guard::argumentNotNull($gameInfo, "gameInfo");
     $this->validateTeamCountAndPlayersCountPerTeam($teams);
     RankSorter::sort($teams, $teamRanks);
     $factorGraph = new TrueSkillFactorGraph($gameInfo, $teams, $teamRanks);
     $factorGraph->buildGraph();
     $factorGraph->runSchedule();
     $probabilityOfOutcome = $factorGraph->getProbabilityOfRanking();
     return $factorGraph->getUpdatedRatings();
 }
Пример #2
0
 public function testSort()
 {
     $team1 = array("a" => 1, "b" => 2);
     $team2 = array("c" => 3, "d" => 4);
     $team3 = array("e" => 5, "f" => 6);
     $teams = array($team1, $team2, $team3);
     $teamRanks = array(3, 1, 2);
     $sortedRanks = RankSorter::sort($teams, $teamRanks);
     $this->assertEquals($team2, $sortedRanks[0]);
     $this->assertEquals($team3, $sortedRanks[1]);
     $this->assertEquals($team1, $sortedRanks[2]);
 }
Пример #3
0
 public function calculateNewRatings(GameInfo &$gameInfo, array $teams, array $teamRanks)
 {
     Guard::argumentNotNull($gameInfo, "gameInfo");
     $this->validateTeamCountAndPlayersCountPerTeam($teams);
     RankSorter::sort($teams, $teamRanks);
     $team1 = $teams[0];
     $team2 = $teams[1];
     $wasDraw = $teamRanks[0] == $teamRanks[1];
     $results = new RatingContainer();
     self::updatePlayerRatings($gameInfo, $results, $team1, $team2, $wasDraw ? PairwiseComparison::DRAW : PairwiseComparison::WIN);
     self::updatePlayerRatings($gameInfo, $results, $team2, $team1, $wasDraw ? PairwiseComparison::DRAW : PairwiseComparison::LOSE);
     return $results;
 }
 public function calculateNewRatings($gameInfo, array $teamsOfPlayerToRatings, array $teamRanks)
 {
     $this->validateTeamCountAndPlayersCountPerTeam($teamsOfPlayerToRatings);
     RankSorter::sort($teamsOfPlayerToRatings, $teamRanks);
     $result = array();
     $isDraw = $teamRanks[0] === $teamRanks[1];
     $team1 = $teamsOfPlayerToRatings[0];
     $team2 = $teamsOfPlayerToRatings[1];
     $player1 = each($team1);
     $player2 = each($team2);
     $player1Rating = $player1["value"]->getMean();
     $player2Rating = $player2["value"]->getMean();
     $result[$player1["key"]] = $this->calculateNewRating($gameInfo, $player1Rating, $player2Rating, $isDraw ? PairwiseComparison::DRAW : PairwiseComparison::WIN);
     $result[$player2["key"]] = $this->calculateNewRating($gameInfo, $player2Rating, $player1Rating, $isDraw ? PairwiseComparison::DRAW : PairwiseComparison::LOSE);
     return $result;
 }
 public function calculateNewRatings(GameInfo $gameInfo, array $teams, array $teamRanks)
 {
     // Basic argument checking
     Guard::argumentNotNull($gameInfo, "gameInfo");
     $this->validateTeamCountAndPlayersCountPerTeam($teams);
     // Make sure things are in order
     $teams = RankSorter::sort($teams, $teamRanks);
     // Since we verified that each team has one player, we know the player is the first one
     $winningTeamPlayers = $teams[0]->getAllPlayers();
     $winner = $winningTeamPlayers[0];
     $winnerPreviousRating = $teams[0]->getRating($winner);
     $losingTeamPlayers = $teams[1]->getAllPlayers();
     $loser = $losingTeamPlayers[0];
     $loserPreviousRating = $teams[1]->getRating($loser);
     $wasDraw = $teamRanks[0] == $teamRanks[1];
     $results = new RatingContainer();
     $results->setRating($winner, self::calculateNewRating($gameInfo, $winnerPreviousRating, $loserPreviousRating, $wasDraw ? PairwiseComparison::DRAW : PairwiseComparison::WIN));
     $results->setRating($loser, self::calculateNewRating($gameInfo, $loserPreviousRating, $winnerPreviousRating, $wasDraw ? PairwiseComparison::DRAW : PairwiseComparison::LOSE));
     // And we're done!
     return $results;
 }