mirror of
https://github.com/furyfire/trueskill.git
synced 2025-04-18 20:04:28 +00:00
Cleanup in src/, adding namespaces, removing php closing tag and general code cleanup
This commit is contained in:
@ -1,11 +1,8 @@
|
||||
<?php
|
||||
namespace Moserware\Skills;
|
||||
<?php namespace Moserware\Skills;
|
||||
|
||||
require_once(dirname(__FILE__) . "/GameInfo.php");
|
||||
require_once(dirname(__FILE__) . "/PlayersRange.php");
|
||||
require_once(dirname(__FILE__) . "/TeamsRange.php");
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Base class for all skill calculator implementations.
|
||||
*/
|
||||
abstract class SkillCalculator
|
||||
@ -13,7 +10,7 @@ abstract class SkillCalculator
|
||||
private $_supportedOptions;
|
||||
private $_playersPerTeamAllowed;
|
||||
private $_totalTeamsAllowed;
|
||||
|
||||
|
||||
protected function __construct($supportedOptions, TeamsRange $totalTeamsAllowed, PlayersRange $playerPerTeamAllowed)
|
||||
{
|
||||
$this->_supportedOptions = $supportedOptions;
|
||||
@ -23,9 +20,10 @@ abstract class SkillCalculator
|
||||
|
||||
/**
|
||||
* Calculates new ratings based on the prior ratings and team ranks.
|
||||
* @param $gameInfo Parameters for the game.
|
||||
* @param $teams A mapping of team players and their ratings.
|
||||
* @param $teamRanks The ranks of the teams where 1 is first place. For a tie, repeat the number (e.g. 1, 2, 2).
|
||||
* @param GameInfo $gameInfo Parameters for the game.
|
||||
* @param array $teamsOfPlayerToRatings A mapping of team players and their ratings.
|
||||
* @param array $teamRanks The ranks of the teams where 1 is first place. For a tie, repeat the number (e.g. 1, 2, 2).
|
||||
*
|
||||
* @return All the players and their new ratings.
|
||||
*/
|
||||
public abstract function calculateNewRatings(GameInfo &$gameInfo,
|
||||
@ -34,18 +32,18 @@ abstract class SkillCalculator
|
||||
|
||||
/**
|
||||
* Calculates the match quality as the likelihood of all teams drawing.
|
||||
*
|
||||
* @param $gameInfo Parameters for the game.
|
||||
* @param $teams A mapping of team players and their ratings.
|
||||
*
|
||||
* @param GameInfo $gameInfo Parameters for the game.
|
||||
* @param array $teamsOfPlayerToRatings A mapping of team players and their ratings.
|
||||
* @return The quality of the match between the teams as a percentage (0% = bad, 100% = well matched).
|
||||
*/
|
||||
public abstract function calculateMatchQuality(GameInfo &$gameInfo,
|
||||
array &$teamsOfPlayerToRatings);
|
||||
|
||||
public function isSupported($option)
|
||||
{
|
||||
return ($this->_supportedOptions & $option) == $option;
|
||||
}
|
||||
{
|
||||
return ($this->_supportedOptions & $option) == $option;
|
||||
}
|
||||
|
||||
protected function validateTeamCountAndPlayersCountPerTeam(array &$teamsOfPlayerToRatings)
|
||||
{
|
||||
@ -56,20 +54,17 @@ abstract class SkillCalculator
|
||||
array &$teams,
|
||||
TeamsRange &$totalTeams,
|
||||
PlayersRange &$playersPerTeam)
|
||||
{
|
||||
{
|
||||
$countOfTeams = 0;
|
||||
|
||||
foreach ($teams as $currentTeam)
|
||||
{
|
||||
if (!$playersPerTeam->isInRange($currentTeam->count()))
|
||||
{
|
||||
throw new \Exception("Player count is not in range");
|
||||
|
||||
foreach ($teams as $currentTeam) {
|
||||
if (!$playersPerTeam->isInRange($currentTeam->count())) {
|
||||
throw new Exception("Player count is not in range");
|
||||
}
|
||||
$countOfTeams++;
|
||||
}
|
||||
|
||||
if (!$totalTeams->isInRange($countOfTeams))
|
||||
{
|
||||
if (!$totalTeams->isInRange($countOfTeams)) {
|
||||
throw new Exception("Team range is not in range");
|
||||
}
|
||||
}
|
||||
@ -80,5 +75,4 @@ class SkillCalculatorSupportedOptions
|
||||
const NONE = 0x00;
|
||||
const PARTIAL_PLAY = 0x01;
|
||||
const PARTIAL_UPDATE = 0x02;
|
||||
}
|
||||
?>
|
||||
}
|
Reference in New Issue
Block a user