mirror of
https://github.com/furyfire/trueskill.git
synced 2025-01-16 01:47:39 +00:00
Fixed up older calculators and started some file cleanup
This commit is contained in:
@ -39,7 +39,7 @@ class RatingContainer
|
|||||||
|
|
||||||
public function count()
|
public function count()
|
||||||
{
|
{
|
||||||
return \count($this->_playerToRating->count());
|
return $this->_playerToRating->count();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -14,7 +14,7 @@ abstract class SkillCalculator
|
|||||||
private $_playersPerTeamAllowed;
|
private $_playersPerTeamAllowed;
|
||||||
private $_totalTeamsAllowed;
|
private $_totalTeamsAllowed;
|
||||||
|
|
||||||
protected function __construct($supportedOptions, TeamsRange &$totalTeamsAllowed, PlayersRange &$playerPerTeamAllowed)
|
protected function __construct($supportedOptions, TeamsRange $totalTeamsAllowed, PlayersRange $playerPerTeamAllowed)
|
||||||
{
|
{
|
||||||
$this->_supportedOptions = $supportedOptions;
|
$this->_supportedOptions = $supportedOptions;
|
||||||
$this->_totalTeamsAllowed = $totalTeamsAllowed;
|
$this->_totalTeamsAllowed = $totalTeamsAllowed;
|
||||||
|
@ -7,7 +7,7 @@ require_once(dirname(__FILE__) . '/RatingContainer.php');
|
|||||||
|
|
||||||
class Team extends RatingContainer
|
class Team extends RatingContainer
|
||||||
{
|
{
|
||||||
public function __construct(Player &$player = null, Rating &$rating = null)
|
public function __construct(Player &$player = null, Rating $rating = null)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ class Team extends RatingContainer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addPlayer(Player &$player, Rating &$rating)
|
public function addPlayer(Player &$player, Rating $rating)
|
||||||
{
|
{
|
||||||
$this->setRating($player, $rating);
|
$this->setRating($player, $rating);
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -140,7 +140,7 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public function calculateMatchQuality(GameInfo $gameInfo, array $teams)
|
public function calculateMatchQuality(GameInfo &$gameInfo, array &$teams)
|
||||||
{
|
{
|
||||||
Guard::argumentNotNull($gameInfo, "gameInfo");
|
Guard::argumentNotNull($gameInfo, "gameInfo");
|
||||||
$this->validateTeamCountAndPlayersCountPerTeam($teams);
|
$this->validateTeamCountAndPlayersCountPerTeam($teams);
|
||||||
|
@ -47,7 +47,7 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
|
|||||||
parent::__construct(SkillCalculatorSupportedOptions::NONE, TeamsRange::exactly(2), PlayersRange::atLeast(1));
|
parent::__construct(SkillCalculatorSupportedOptions::NONE, TeamsRange::exactly(2), PlayersRange::atLeast(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function calculateNewRatings(GameInfo $gameInfo,
|
public function calculateNewRatings(GameInfo &$gameInfo,
|
||||||
array $teams,
|
array $teams,
|
||||||
array $teamRanks)
|
array $teamRanks)
|
||||||
{
|
{
|
||||||
@ -146,7 +146,8 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
|
|||||||
$rankMultiplier = 1;
|
$rankMultiplier = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($selfTeam->getAllPlayers() as &$selfTeamCurrentPlayer)
|
$selfTeamAllPlayers = &$selfTeam->getAllPlayers();
|
||||||
|
foreach ($selfTeamAllPlayers as &$selfTeamCurrentPlayer)
|
||||||
{
|
{
|
||||||
$localSelfTeamCurrentPlayer = &$selfTeamCurrentPlayer;
|
$localSelfTeamCurrentPlayer = &$selfTeamCurrentPlayer;
|
||||||
$previousPlayerRating = $selfTeam->getRating($localSelfTeamCurrentPlayer);
|
$previousPlayerRating = $selfTeam->getRating($localSelfTeamCurrentPlayer);
|
||||||
@ -165,7 +166,8 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public function calculateMatchQuality(GameInfo $gameInfo, array $teams)
|
public function calculateMatchQuality(GameInfo &$gameInfo,
|
||||||
|
array &$teams)
|
||||||
{
|
{
|
||||||
Guard::argumentNotNull($gameInfo, "gameInfo");
|
Guard::argumentNotNull($gameInfo, "gameInfo");
|
||||||
$this->validateTeamCountAndPlayersCountPerTeam($teams);
|
$this->validateTeamCountAndPlayersCountPerTeam($teams);
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
require_once 'PHPUnit/Framework.php';
|
|
||||||
require_once 'PHPUnit/TextUI/TestRunner.php';
|
|
||||||
|
|
||||||
require_once(dirname(__FILE__) . '/../PHPSkills/RankSorter.php');
|
|
||||||
|
|
||||||
|
|
||||||
use \PHPUnit_Framework_TestCase;
|
|
||||||
|
|
||||||
class RankSorterTest extends PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
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]);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$testSuite = new \PHPUnit_Framework_TestSuite();
|
|
||||||
$testSuite->addTest( new RankSorterTest("testSort"));
|
|
||||||
|
|
||||||
\PHPUnit_TextUI_TestRunner::run($testSuite);
|
|
Reference in New Issue
Block a user