mirror of
https://github.com/furyfire/trueskill.git
synced 2025-04-16 11:04:27 +00:00
Refactoring for PHP8.2
This commit is contained in:
@ -11,21 +11,21 @@ use Exception;
|
||||
*/
|
||||
class Guard
|
||||
{
|
||||
public static function argumentNotNull($value, $parameterName)
|
||||
public static function argumentNotNull(mixed $value, string $parameterName): void
|
||||
{
|
||||
if ($value == null) {
|
||||
throw new Exception($parameterName.' can not be null');
|
||||
}
|
||||
}
|
||||
|
||||
public static function argumentIsValidIndex($index, $count, $parameterName)
|
||||
public static function argumentIsValidIndex(int $index, int $count, string $parameterName): void
|
||||
{
|
||||
if (($index < 0) || ($index >= $count)) {
|
||||
throw new Exception($parameterName.' is an invalid index');
|
||||
}
|
||||
}
|
||||
|
||||
public static function argumentInRangeInclusive($value, $min, $max, $parameterName)
|
||||
public static function argumentInRangeInclusive(float $value, float $min, float $max, string $parameterName): void
|
||||
{
|
||||
if (($value < $min) || ($value > $max)) {
|
||||
throw new Exception($parameterName.' is not in the valid range ['.$min.', '.$max.']');
|
||||
|
@ -7,20 +7,11 @@ namespace DNW\Skills;
|
||||
*
|
||||
* @internal The actual values for the enum were chosen so that the also correspond to the multiplier for updates to means.
|
||||
*/
|
||||
class PairwiseComparison
|
||||
enum PairwiseComparison: int
|
||||
{
|
||||
final const WIN = 1;
|
||||
case WIN = 1;
|
||||
|
||||
final const DRAW = 0;
|
||||
case DRAW = 0;
|
||||
|
||||
final const LOSE = -1;
|
||||
|
||||
public static function getRankFromComparison($comparison)
|
||||
{
|
||||
return match ($comparison) {
|
||||
PairwiseComparison::WIN => [1, 2],
|
||||
PairwiseComparison::LOSE => [2, 1],
|
||||
default => [1, 1],
|
||||
};
|
||||
}
|
||||
case LOSE = -1;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
parent::__construct($parentGraph);
|
||||
}
|
||||
|
||||
public function getLocalFactors()
|
||||
public function getLocalFactors(): array
|
||||
{
|
||||
return array_merge($this->_TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors(),
|
||||
$this->_TeamDifferencesComparisonLayer->getLocalFactors()
|
||||
@ -36,7 +36,7 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
$this->_TeamDifferencesComparisonLayer->buildLayer();
|
||||
}
|
||||
|
||||
public function createPriorSchedule()
|
||||
public function createPriorSchedule(): ScheduleSequence
|
||||
{
|
||||
switch (is_countable($this->getInputVariablesGroups()) ? count($this->getInputVariablesGroups()) : 0) {
|
||||
case 0:
|
||||
|
@ -102,7 +102,7 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator
|
||||
// non-draw case
|
||||
$v = TruncatedGaussianCorrectionFunctions::vExceedsMarginScaled($meanDelta, $drawMargin, $c);
|
||||
$w = TruncatedGaussianCorrectionFunctions::wExceedsMarginScaled($meanDelta, $drawMargin, $c);
|
||||
$rankMultiplier = (int) $comparison;
|
||||
$rankMultiplier = $comparison->value;
|
||||
} else {
|
||||
$v = TruncatedGaussianCorrectionFunctions::vWithinMarginScaled($meanDelta, $drawMargin, $c);
|
||||
$w = TruncatedGaussianCorrectionFunctions::wWithinMarginScaled($meanDelta, $drawMargin, $c);
|
||||
|
@ -27,7 +27,7 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
|
||||
parent::__construct(SkillCalculatorSupportedOptions::NONE, TeamsRange::exactly(2), PlayersRange::atLeast(1));
|
||||
}
|
||||
|
||||
public function calculateNewRatings(GameInfo $gameInfo, array $teams, array $teamRanks)
|
||||
public function calculateNewRatings(GameInfo $gameInfo, array $teams, array $teamRanks): RatingContainer
|
||||
{
|
||||
Guard::argumentNotNull($gameInfo, 'gameInfo');
|
||||
$this->validateTeamCountAndPlayersCountPerTeam($teams);
|
||||
@ -60,7 +60,7 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
|
||||
RatingContainer $newPlayerRatings,
|
||||
Team $selfTeam,
|
||||
Team $otherTeam,
|
||||
$selfToOtherTeamComparison)
|
||||
PairwiseComparison $selfToOtherTeamComparison): void
|
||||
{
|
||||
$drawMargin = DrawMargin::getDrawMarginFromDrawProbability(
|
||||
$gameInfo->getDrawProbability(),
|
||||
@ -107,7 +107,7 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
|
||||
// non-draw case
|
||||
$v = TruncatedGaussianCorrectionFunctions::vExceedsMarginScaled($meanDelta, $drawMargin, $c);
|
||||
$w = TruncatedGaussianCorrectionFunctions::wExceedsMarginScaled($meanDelta, $drawMargin, $c);
|
||||
$rankMultiplier = (int) $selfToOtherTeamComparison;
|
||||
$rankMultiplier = $selfToOtherTeamComparison->value;
|
||||
} else {
|
||||
// assume draw
|
||||
$v = TruncatedGaussianCorrectionFunctions::vWithinMarginScaled($meanDelta, $drawMargin, $c);
|
||||
@ -137,7 +137,7 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function calculateMatchQuality(GameInfo $gameInfo, array $teams)
|
||||
public function calculateMatchQuality(GameInfo $gameInfo, array $teams): float
|
||||
{
|
||||
Guard::argumentNotNull($gameInfo, 'gameInfo');
|
||||
$this->validateTeamCountAndPlayersCountPerTeam($teams);
|
||||
|
Reference in New Issue
Block a user