From 7d4547df6a7dac8d686fcb47b4dab26f779d0abf Mon Sep 17 00:00:00 2001 From: Alex Wulf Date: Tue, 5 Jul 2022 15:55:47 +0200 Subject: [PATCH] Pint applied for formatting --- composer.json | 5 +- composer.lock | 71 +++++++++++++++++- src/FactorGraphs/DefaultVariable.php | 8 +- src/FactorGraphs/Factor.php | 31 +++++--- src/FactorGraphs/FactorGraph.php | 6 +- src/FactorGraphs/FactorGraphLayer.php | 18 +++-- src/FactorGraphs/FactorList.php | 9 ++- src/FactorGraphs/KeyedVariable.php | 6 +- src/FactorGraphs/Message.php | 9 ++- src/FactorGraphs/Schedule.php | 8 +- src/FactorGraphs/ScheduleLoop.php | 7 +- src/FactorGraphs/ScheduleSequence.php | 6 +- src/FactorGraphs/ScheduleStep.php | 8 +- src/FactorGraphs/Variable.php | 7 +- src/FactorGraphs/VariableFactory.php | 6 +- src/GameInfo.php | 15 +++- src/Guard.php | 12 +-- src/HashMap.php | 15 +++- src/ISupportPartialPlay.php | 6 +- src/ISupportPartialUpdate.php | 6 +- src/Numerics/BasicMath.php | 16 ++-- src/Numerics/DiagonalMatrix.php | 6 +- src/Numerics/GaussianDistribution.php | 21 ++++-- src/Numerics/IdentityMatrix.php | 6 +- src/Numerics/Matrix.php | 35 +++++---- src/Numerics/Range.php | 14 ++-- src/Numerics/SquareMatrix.php | 10 ++- src/Numerics/Vector.php | 10 ++- src/PairwiseComparison.php | 15 ++-- src/PartialPlay.php | 8 +- src/Player.php | 21 ++++-- src/PlayersRange.php | 6 +- src/RankSorter.php | 11 ++- src/Rating.php | 21 ++++-- src/RatingContainer.php | 4 +- src/SkillCalculator.php | 36 +++++---- src/Team.php | 10 ++- src/Teams.php | 8 +- src/TeamsRange.php | 6 +- src/TrueSkill/DrawMargin.php | 6 +- .../FactorGraphTrueSkillCalculator.php | 16 ++-- src/TrueSkill/Factors/GaussianFactor.php | 15 ++-- .../Factors/GaussianGreaterThanFactor.php | 14 ++-- .../Factors/GaussianLikelihoodFactor.php | 10 ++- src/TrueSkill/Factors/GaussianPriorFactor.php | 11 ++- .../Factors/GaussianWeightedSumFactor.php | 34 +++++---- .../Factors/GaussianWithinFactor.php | 14 ++-- .../IteratedTeamDifferencesInnerLayer.php | 73 ++++++++++--------- ...yerPerformancesToTeamPerformancesLayer.php | 31 ++++---- .../Layers/PlayerPriorValuesToSkillsLayer.php | 22 +++--- .../PlayerSkillsToPerformancesLayer.php | 23 +++--- .../Layers/TeamDifferencesComparisonLayer.php | 9 ++- ...ancesToTeamPerformanceDifferencesLayer.php | 21 +++--- .../Layers/TrueSkillFactorGraphLayer.php | 6 +- src/TrueSkill/TrueSkillFactorGraph.php | 27 ++++--- .../TruncatedGaussianCorrectionFunctions.php | 10 ++- .../TwoPlayerTrueSkillCalculator.php | 42 +++++------ src/TrueSkill/TwoTeamTrueSkillCalculator.php | 18 ++--- tests/Numerics/BasicMathTest.php | 6 +- tests/Numerics/GaussianDistributionTest.php | 6 +- tests/Numerics/MatrixTest.php | 20 ++--- tests/RankSorterTest.php | 16 ++-- tests/TestCase.php | 6 +- tests/TrueSkill/DrawMarginTest.php | 6 +- ...FactorGraphTeamTrueSkillCalculatorTest.php | 6 +- tests/TrueSkill/TrueSkillCalculatorTests.php | 69 +++++++++--------- .../TwoPlayerTrueSkillCalculatorTest.php | 6 +- .../TwoTeamTrueSkillCalculatorTest.php | 6 +- 68 files changed, 670 insertions(+), 402 deletions(-) diff --git a/composer.json b/composer.json index f4eb2fc..0e7f1ea 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,8 @@ "keywords": ["trueskill", "matchmaking", "ranking", "skill", "elo"], "version": "1.0.0", "require": { - "php": "^8.1" + "php": "^8.1", + "laravel/pint": "^0.2.3" }, "require-dev": { "phpunit/phpunit": "^9.0" @@ -18,4 +19,4 @@ "DNW\\Skills\\Tests\\": "tests/" } } -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index 335d7e4..8ed31ef 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,75 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c016c54cac9a371fa358f63b592c310d", - "packages": [], + "content-hash": "27116ea101bf0dd938fe452b46b9c1b7", + "packages": [ + { + "name": "laravel/pint", + "version": "v0.2.3", + "source": { + "type": "git", + "url": "https://github.com/laravel/pint.git", + "reference": "d0829631687c1238abdd660daac3d7218254b65c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/pint/zipball/d0829631687c1238abdd660daac3d7218254b65c", + "reference": "d0829631687c1238abdd660daac3d7218254b65c", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-mbstring": "*", + "ext-tokenizer": "*", + "ext-xml": "*", + "php": "^8.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.8.0", + "illuminate/view": "^9.17.0", + "laravel-zero/framework": "^9.1.1", + "mockery/mockery": "^1.5.0", + "nunomaduro/larastan": "^2.1.11", + "nunomaduro/termwind": "^1.10.1", + "pestphp/pest": "^1.21.3" + }, + "bin": [ + "builds/pint" + ], + "type": "project", + "autoload": { + "psr-4": { + "App\\": "app/", + "Database\\Seeders\\": "database/seeders/", + "Database\\Factories\\": "database/factories/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nuno Maduro", + "email": "enunomaduro@gmail.com" + } + ], + "description": "An opinionated code formatter for PHP.", + "homepage": "https://laravel.com", + "keywords": [ + "format", + "formatter", + "lint", + "linter", + "php" + ], + "support": { + "issues": "https://github.com/laravel/pint/issues", + "source": "https://github.com/laravel/pint" + }, + "time": "2022-07-04T16:04:06+00:00" + } + ], "packages-dev": [ { "name": "doctrine/instantiator", diff --git a/src/FactorGraphs/DefaultVariable.php b/src/FactorGraphs/DefaultVariable.php index 71a1f6c..8544d7a 100644 --- a/src/FactorGraphs/DefaultVariable.php +++ b/src/FactorGraphs/DefaultVariable.php @@ -1,4 +1,6 @@ -_name = "Factor[" . $name . "]"; + $this->_name = 'Factor['.$name.']'; $this->_messageToVariableBinding = new HashMap(); } @@ -46,14 +50,17 @@ abstract class Factor /** * Update the message and marginal of the i-th variable that the factor is connected to + * * @param $messageIndex + * * @throws Exception */ public function updateMessageIndex($messageIndex) { - Guard::argumentIsValidIndex($messageIndex, count($this->_messages), "messageIndex"); + Guard::argumentIsValidIndex($messageIndex, count($this->_messages), 'messageIndex'); $message = $this->_messages[$messageIndex]; $variable = $this->_messageToVariableBinding->getValue($message); + return $this->updateMessageVariable($message, $variable); } @@ -75,28 +82,32 @@ abstract class Factor /** * Sends the ith message to the marginal and returns the log-normalization constant + * * @param $messageIndex * @return + * * @throws Exception */ public function sendMessageIndex($messageIndex) { - Guard::argumentIsValidIndex($messageIndex, count($this->_messages), "messageIndex"); + Guard::argumentIsValidIndex($messageIndex, count($this->_messages), 'messageIndex'); $message = $this->_messages[$messageIndex]; $variable = $this->_messageToVariableBinding->getValue($message); + return $this->sendMessageVariable($message, $variable); } - protected abstract function sendMessageVariable(Message $message, Variable $variable); + abstract protected function sendMessageVariable(Message $message, Variable $variable); - public abstract function createVariableToMessageBinding(Variable $variable); + abstract public function createVariableToMessageBinding(Variable $variable); protected function createVariableToMessageBindingWithMessage(Variable $variable, Message $message) { $this->_messageToVariableBinding->setValue($message, $variable); $this->_messages[] = $message; $this->_variables[] = $variable; + return $message; } @@ -104,4 +115,4 @@ abstract class Factor { return $this->_name; } -} \ No newline at end of file +} diff --git a/src/FactorGraphs/FactorGraph.php b/src/FactorGraphs/FactorGraph.php index 7b9e5d3..2f4b51c 100644 --- a/src/FactorGraphs/FactorGraph.php +++ b/src/FactorGraphs/FactorGraph.php @@ -1,4 +1,6 @@ -_variableFactory = $factory; } -} \ No newline at end of file +} diff --git a/src/FactorGraphs/FactorGraphLayer.php b/src/FactorGraphs/FactorGraphLayer.php index ec71151..43673fb 100644 --- a/src/FactorGraphs/FactorGraphLayer.php +++ b/src/FactorGraphs/FactorGraphLayer.php @@ -1,10 +1,16 @@ -_localFactors[] = $factor; } - public abstract function buildLayer(); + abstract public function buildLayer(); public function createPriorSchedule() { @@ -65,4 +71,4 @@ abstract class FactorGraphLayer { return null; } -} \ No newline at end of file +} diff --git a/src/FactorGraphs/FactorList.php b/src/FactorGraphs/FactorList.php index 963991f..6d3bcd7 100644 --- a/src/FactorGraphs/FactorList.php +++ b/src/FactorGraphs/FactorList.php @@ -1,11 +1,13 @@ -_list[] = $factor; + return $factor; } -} \ No newline at end of file +} diff --git a/src/FactorGraphs/KeyedVariable.php b/src/FactorGraphs/KeyedVariable.php index 5aaf122..d48962e 100644 --- a/src/FactorGraphs/KeyedVariable.php +++ b/src/FactorGraphs/KeyedVariable.php @@ -1,4 +1,6 @@ -_key; } -} \ No newline at end of file +} diff --git a/src/FactorGraphs/Message.php b/src/FactorGraphs/Message.php index 1c6b8c7..9fbeadc 100644 --- a/src/FactorGraphs/Message.php +++ b/src/FactorGraphs/Message.php @@ -1,8 +1,11 @@ -_name; + return (string) $this->_name; } -} \ No newline at end of file +} diff --git a/src/FactorGraphs/Schedule.php b/src/FactorGraphs/Schedule.php index f013d54..64a5fbe 100644 --- a/src/FactorGraphs/Schedule.php +++ b/src/FactorGraphs/Schedule.php @@ -1,4 +1,6 @@ -_name = $name; } - public abstract function visit($depth = -1, $maxDepth = 0); + abstract public function visit($depth = -1, $maxDepth = 0); public function __toString() { return $this->_name; } -} \ No newline at end of file +} diff --git a/src/FactorGraphs/ScheduleLoop.php b/src/FactorGraphs/ScheduleLoop.php index c6d8713..4b875d6 100644 --- a/src/FactorGraphs/ScheduleLoop.php +++ b/src/FactorGraphs/ScheduleLoop.php @@ -1,8 +1,11 @@ -_factor; $delta = $currentFactor->updateMessageIndex($this->_index); + return $delta; } -} \ No newline at end of file +} diff --git a/src/FactorGraphs/Variable.php b/src/FactorGraphs/Variable.php index 43e6607..cd89eab 100644 --- a/src/FactorGraphs/Variable.php +++ b/src/FactorGraphs/Variable.php @@ -1,15 +1,18 @@ _name = "Variable[" . $name . "]"; + $this->_name = 'Variable['.$name.']'; $this->_prior = $prior; $this->resetToPrior(); } @@ -33,4 +36,4 @@ class Variable { return $this->_name; } -} \ No newline at end of file +} diff --git a/src/FactorGraphs/VariableFactory.php b/src/FactorGraphs/VariableFactory.php index 3042deb..af683a6 100644 --- a/src/FactorGraphs/VariableFactory.php +++ b/src/FactorGraphs/VariableFactory.php @@ -1,4 +1,6 @@ -_variablePriorInitializer; $newVar = new Variable($name, $initializer()); + return $newVar; } @@ -21,6 +24,7 @@ class VariableFactory { $initializer = $this->_variablePriorInitializer; $newVar = new KeyedVariable($key, $name, $initializer()); + return $newVar; } } diff --git a/src/GameInfo.php b/src/GameInfo.php index 1e979db..3c77b84 100644 --- a/src/GameInfo.php +++ b/src/GameInfo.php @@ -1,4 +1,6 @@ -_drawProbability = $drawProbability; } - public function getInitialMean() { return $this->_initialMean; @@ -60,4 +69,4 @@ class GameInfo { return new Rating($this->_initialMean, $this->_initialStandardDeviation); } -} \ No newline at end of file +} diff --git a/src/Guard.php b/src/Guard.php index fb2f41e..5438b61 100644 --- a/src/Guard.php +++ b/src/Guard.php @@ -1,4 +1,6 @@ -= $count)) { - throw new Exception($parameterName . " is an invalid index"); + throw new Exception($parameterName.' is an invalid index'); } } public static function argumentInRangeInclusive($value, $min, $max, $parameterName) { if (($value < $min) || ($value > $max)) { - throw new Exception($parameterName . " is not in the valid range [" . $min . ", " . $max . "]"); + throw new Exception($parameterName.' is not in the valid range ['.$min.', '.$max.']'); } } -} \ No newline at end of file +} diff --git a/src/HashMap.php b/src/HashMap.php index 7e7cac6..aca2315 100644 --- a/src/HashMap.php +++ b/src/HashMap.php @@ -1,17 +1,21 @@ -_hashToValue[$hash]; + return $hashValue; } @@ -20,18 +24,21 @@ class HashMap $hash = self::getHash($key); $this->_hashToKey[$hash] = $key; $this->_hashToValue[$hash] = $value; + return $this; } public function getAllKeys() { $keys = array_values($this->_hashToKey); + return $keys; } public function getAllValues() { $values = array_values($this->_hashToValue); + return $values; } @@ -48,4 +55,4 @@ class HashMap return $key; } -} \ No newline at end of file +} diff --git a/src/ISupportPartialPlay.php b/src/ISupportPartialPlay.php index a400041..a1de31a 100644 --- a/src/ISupportPartialPlay.php +++ b/src/ISupportPartialPlay.php @@ -1,4 +1,6 @@ -_variance = $this->_variance; $result->_precision = $this->_precision; $result->_precisionMean = $this->_precisionMean; + return $result; } @@ -94,6 +100,7 @@ class GaussianDistribution $result->_standardDeviation = \INF; $result->_mean = \NAN; } + return $result; } @@ -129,6 +136,7 @@ class GaussianDistribution $meanDifference = $left->_mean - $right->_mean; $logSqrt2Pi = log(sqrt(2 * M_PI)); + return -$logSqrt2Pi - (log($varianceSum) / 2.0) - (BasicMath::square($meanDifference) / (2.0 * $varianceSum)); } @@ -165,6 +173,7 @@ class GaussianDistribution $multiplier = 1.0 / ($standardDeviation * sqrt(2 * M_PI)); $expPart = exp((-1.0 * BasicMath::square($x - $mean)) / (2 * BasicMath::square($standardDeviation))); $result = $multiplier * $expPart; + return $result; } @@ -172,6 +181,7 @@ class GaussianDistribution { $invsqrt2 = -0.707106781186547524400844362104; $result = GaussianDistribution::errorFunctionCumulativeTo($invsqrt2 * $x); + return 0.5 * $result; } @@ -183,7 +193,7 @@ class GaussianDistribution $t = 2.0 / (2.0 + $z); $ty = 4 * $t - 2; - $coefficients = array( + $coefficients = [ -1.3026537197817094, 6.4196979235649026e-1, 1.9476473204185836e-2, @@ -211,7 +221,7 @@ class GaussianDistribution -1.523e-15, -9.4e-17, 1.21e-16, - -2.8e-17); + -2.8e-17, ]; $ncof = count($coefficients); $d = 0.0; @@ -224,6 +234,7 @@ class GaussianDistribution } $ans = $t * exp(-$z * $z + 0.5 * ($coefficients[0] + $ty * $d) - $dd); + return ($x >= 0.0) ? $ans : (2.0 - $ans); } @@ -258,6 +269,6 @@ class GaussianDistribution public function __toString() { - return sprintf("mean=%.4f standardDeviation=%.4f", $this->_mean, $this->_standardDeviation); + return sprintf('mean=%.4f standardDeviation=%.4f', $this->_mean, $this->_standardDeviation); } -} \ No newline at end of file +} diff --git a/src/Numerics/IdentityMatrix.php b/src/Numerics/IdentityMatrix.php index 9eccc0b..0f4d4e4 100644 --- a/src/Numerics/IdentityMatrix.php +++ b/src/Numerics/IdentityMatrix.php @@ -1,4 +1,6 @@ -_matrixRowData; for ($currentRowTransposeMatrix = 0; @@ -98,8 +102,8 @@ class Matrix public function getDeterminant() { // Basic argument checking - if (!$this->isSquare()) { - throw new Exception("Matrix must be square!"); + if (! $this->isSquare()) { + throw new Exception('Matrix must be square!'); } if ($this->_rowCount == 1) { @@ -117,6 +121,7 @@ class Matrix $b = $this->_matrixRowData[0][1]; $c = $this->_matrixRowData[1][0]; $d = $this->_matrixRowData[1][1]; + return $a * $d - $b * $c; } @@ -141,8 +146,8 @@ class Matrix public function getAdjugate() { - if (!$this->isSquare()) { - throw new Exception("Matrix must be square!"); + if (! $this->isSquare()) { + throw new Exception('Matrix must be square!'); } // See http://en.wikipedia.org/wiki/Adjugate_matrix @@ -165,7 +170,7 @@ class Matrix } // The idea is that it's the transpose of the cofactors - $result = array(); + $result = []; for ($currentColumn = 0; $currentColumn < $this->_columnCount; $currentColumn++) { for ($currentRow = 0; $currentRow < $this->_rowCount; $currentRow++) { @@ -194,7 +199,7 @@ class Matrix { $rows = $matrix->getRowCount(); $columns = $matrix->getColumnCount(); - $newValues = array(); + $newValues = []; for ($currentRow = 0; $currentRow < $rows; $currentRow++) { for ($currentColumn = 0; $currentColumn < $columns; $currentColumn++) { @@ -212,12 +217,12 @@ class Matrix || ($left->getColumnCount() != $right->getColumnCount()) ) { - throw new Exception("Matrices must be of the same size"); + throw new Exception('Matrices must be of the same size'); } // simple addition of each item - $resultMatrix = array(); + $resultMatrix = []; for ($currentRow = 0; $currentRow < $left->getRowCount(); $currentRow++) { for ($currentColumn = 0; $currentColumn < $right->getColumnCount(); $currentColumn++) { @@ -237,13 +242,13 @@ class Matrix // See http://en.wikipedia.org/wiki/Matrix_multiplication for details if ($left->getColumnCount() != $right->getRowCount()) { - throw new Exception("The width of the left matrix must match the height of the right matrix"); + throw new Exception('The width of the left matrix must match the height of the right matrix'); } $resultRows = $left->getRowCount(); $resultColumns = $right->getColumnCount(); - $resultMatrix = array(); + $resultMatrix = []; for ($currentRow = 0; $currentRow < $resultRows; $currentRow++) { for ($currentColumn = 0; $currentColumn < $resultColumns; $currentColumn++) { @@ -268,7 +273,7 @@ class Matrix // See http://en.wikipedia.org/wiki/Minor_(linear_algebra) // I'm going to use a horribly naïve algorithm... because I can :) - $result = array(); + $result = []; $actualRow = 0; @@ -334,4 +339,4 @@ class Matrix return true; } -} \ No newline at end of file +} diff --git a/src/Numerics/Range.php b/src/Numerics/Range.php index b8f0a46..40937fc 100644 --- a/src/Numerics/Range.php +++ b/src/Numerics/Range.php @@ -1,4 +1,6 @@ - $max) - { - throw new Exception("min > max"); + if ($min > $max) { + throw new Exception('min > max'); } $this->_min = $min; @@ -50,11 +52,11 @@ class Range public static function atLeast($minimumValue) { - return static::create($minimumValue, PHP_INT_MAX ); + return static::create($minimumValue, PHP_INT_MAX); } public function isInRange($value) { return ($this->_min <= $value) && ($value <= $this->_max); } -} \ No newline at end of file +} diff --git a/src/Numerics/SquareMatrix.php b/src/Numerics/SquareMatrix.php index 58949f0..3592c2c 100644 --- a/src/Numerics/SquareMatrix.php +++ b/src/Numerics/SquareMatrix.php @@ -1,14 +1,16 @@ -_Id = $id; $this->_PartialPlayPercentage = $partialPlayPercentage; $this->_PartialUpdatePercentage = $partialUpdatePercentage; @@ -57,6 +62,6 @@ class Player implements ISupportPartialPlay, ISupportPartialUpdate public function __toString() { - return (string)$this->_Id; + return (string) $this->_Id; } -} \ No newline at end of file +} diff --git a/src/PlayersRange.php b/src/PlayersRange.php index 12257d0..f456888 100644 --- a/src/PlayersRange.php +++ b/src/PlayersRange.php @@ -1,4 +1,6 @@ -getMean(), $prior->getStandardDeviation()); - $posteriorGaussian = new GaussianDistribution($fullPosterior->getMean(), $fullPosterior . getStandardDeviation()); + $posteriorGaussian = new GaussianDistribution($fullPosterior->getMean(), $fullPosterior.getStandardDeviation()); // From a clarification email from Ralf Herbrich: // "the idea is to compute a linear interpolation between the prior and posterior skills of each player @@ -60,7 +65,7 @@ class Rating $precisionDifference = $posteriorGaussian->getPrecision() - $priorGaussian->getPrecision(); $partialPrecisionDifference = $updatePercentage * $precisionDifference; - $precisionMeanDifference = $posteriorGaussian->getPrecisionMean() - $priorGaussian . getPrecisionMean(); + $precisionMeanDifference = $posteriorGaussian->getPrecisionMean() - $priorGaussian.getPrecisionMean(); $partialPrecisionMeanDifference = $updatePercentage * $precisionMeanDifference; $partialPosteriorGaussion = GaussianDistribution::fromPrecisionMean( @@ -73,6 +78,6 @@ class Rating public function __toString() { - return sprintf("mean=%.4f, standardDeviation=%.4f", $this->_mean, $this->_standardDeviation); + return sprintf('mean=%.4f, standardDeviation=%.4f', $this->_mean, $this->_standardDeviation); } -} \ No newline at end of file +} diff --git a/src/RatingContainer.php b/src/RatingContainer.php index bbc07e4..ec62d4c 100644 --- a/src/RatingContainer.php +++ b/src/RatingContainer.php @@ -1,4 +1,6 @@ -_totalTeamsAllowed, $this->_playersPerTeamAllowed); } - private static function validateTeamCountAndPlayersCountPerTeamWithRanges(array $teams, - TeamsRange $totalTeams, - PlayersRange $playersPerTeam) + private static function validateTeamCountAndPlayersCountPerTeamWithRanges(array $teams, TeamsRange $totalTeams, PlayersRange $playersPerTeam) { $countOfTeams = 0; foreach ($teams as $currentTeam) { - if (!$playersPerTeam->isInRange(count($currentTeam))) { - throw new Exception("Player count is not in range"); + if (! $playersPerTeam->isInRange(count($currentTeam))) { + throw new Exception('Player count is not in range'); } $countOfTeams++; } - if (!$totalTeams->isInRange($countOfTeams)) { - throw new Exception("Team range is not in range"); + if (! $totalTeams->isInRange($countOfTeams)) { + throw new Exception('Team range is not in range'); } } } @@ -71,6 +73,8 @@ abstract class SkillCalculator class SkillCalculatorSupportedOptions { const NONE = 0x00; + const PARTIAL_PLAY = 0x01; + const PARTIAL_UPDATE = 0x02; -} \ No newline at end of file +} diff --git a/src/Team.php b/src/Team.php index 5202ab0..749bbf5 100644 --- a/src/Team.php +++ b/src/Team.php @@ -1,4 +1,6 @@ -addPlayer($player, $rating); } } @@ -15,6 +16,7 @@ class Team extends RatingContainer public function addPlayer(Player $player, Rating $rating) { $this->setRating($player, $rating); + return $this; } -} \ No newline at end of file +} diff --git a/src/Teams.php b/src/Teams.php index 5c41395..8c1e89f 100644 --- a/src/Teams.php +++ b/src/Teams.php @@ -1,11 +1,13 @@ -validateTeamCountAndPlayersCountPerTeam($teams); RankSorter::sort($teams, $teamRanks); @@ -109,7 +109,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator // Helper function that gets a list of values for all player ratings private static function getPlayerRatingValues(array $teamAssignmentsList, $playerRatingFunction) { - $playerRatingValues = array(); + $playerRatingValues = []; foreach ($teamAssignmentsList as $currentTeam) { foreach ($currentTeam->getAllRatings() as $currentRating) { @@ -138,7 +138,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator // | -0.75 0.75 | // | 0.00 -1.00 | - $playerAssignments = array(); + $playerAssignments = []; $totalPreviousPlayers = 0; $teamAssignmentsListCount = count($teamAssignmentsList); @@ -150,7 +150,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator // Need to add in 0's for all the previous players, since they're not // on this team - $playerAssignments[$currentColumn] = ($totalPreviousPlayers > 0) ? \array_fill(0, $totalPreviousPlayers, 0) : array(); + $playerAssignments[$currentColumn] = ($totalPreviousPlayers > 0) ? \array_fill(0, $totalPreviousPlayers, 0) : []; foreach ($currentTeam->getAllPlayers() as $currentPlayer) { $playerAssignments[$currentColumn][] = PartialPlay::getPartialPlayPercentage($currentPlayer); @@ -179,4 +179,4 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator return $playerTeamAssignmentsMatrix; } -} \ No newline at end of file +} diff --git a/src/TrueSkill/Factors/GaussianFactor.php b/src/TrueSkill/Factors/GaussianFactor.php index b242850..3663878 100644 --- a/src/TrueSkill/Factors/GaussianFactor.php +++ b/src/TrueSkill/Factors/GaussianFactor.php @@ -1,4 +1,6 @@ -getValue(); $logZ = GaussianDistribution::logProductNormalization($marginal, $messageValue); $variable->setValue(GaussianDistribution::multiply($marginal, $messageValue)); + return $logZ; } @@ -33,7 +37,8 @@ abstract class GaussianFactor extends Factor $binding = parent::createVariableToMessageBindingWithMessage($variable, new Message( $newDistribution, - sprintf("message from %s to %s", $this, $variable))); + sprintf('message from %s to %s', $this, $variable))); + return $binding; } -} \ No newline at end of file +} diff --git a/src/TrueSkill/Factors/GaussianGreaterThanFactor.php b/src/TrueSkill/Factors/GaussianGreaterThanFactor.php index 15ab337..d1474c9 100644 --- a/src/TrueSkill/Factors/GaussianGreaterThanFactor.php +++ b/src/TrueSkill/Factors/GaussianGreaterThanFactor.php @@ -1,9 +1,11 @@ - %.2f", $variable, $epsilon)); + parent::__construct(\sprintf('%s > %.2f', $variable, $epsilon)); $this->_epsilon = $epsilon; $this->createVariableToMessageBinding($variable); } @@ -31,6 +33,7 @@ class GaussianGreaterThanFactor extends GaussianFactor $messages = $this->getMessages(); $message = $messages[0]->getValue(); $messageFromVariable = GaussianDistribution::divide($marginal, $message); + return -GaussianDistribution::logProductNormalization($messageFromVariable, $message) + log( @@ -39,7 +42,6 @@ class GaussianGreaterThanFactor extends GaussianFactor $messageFromVariable->getStandardDeviation() ) ); - } protected function updateMessageVariable(Message $message, Variable $variable) @@ -82,4 +84,4 @@ class GaussianGreaterThanFactor extends GaussianFactor // Return the difference in the new marginal return GaussianDistribution::subtract($newMarginal, $oldMarginal); } -} \ No newline at end of file +} diff --git a/src/TrueSkill/Factors/GaussianLikelihoodFactor.php b/src/TrueSkill/Factors/GaussianLikelihoodFactor.php index bfbeabd..6319c29 100644 --- a/src/TrueSkill/Factors/GaussianLikelihoodFactor.php +++ b/src/TrueSkill/Factors/GaussianLikelihoodFactor.php @@ -1,10 +1,12 @@ -_precision = 1.0 / $betaSquared; $this->createVariableToMessageBinding($variable1); $this->createVariableToMessageBinding($variable2); @@ -80,4 +82,4 @@ class GaussianLikelihoodFactor extends GaussianFactor throw new Exception(); } } -} \ No newline at end of file +} diff --git a/src/TrueSkill/Factors/GaussianPriorFactor.php b/src/TrueSkill/Factors/GaussianPriorFactor.php index 291f067..c026041 100644 --- a/src/TrueSkill/Factors/GaussianPriorFactor.php +++ b/src/TrueSkill/Factors/GaussianPriorFactor.php @@ -1,4 +1,6 @@ -_newMessage = new GaussianDistribution($mean, sqrt($variance)); $newMessage = new Message(GaussianDistribution::fromPrecisionMean(0, 0), - sprintf("message from %s to %s", $this, $variable)); + sprintf('message from %s to %s', $this, $variable)); $this->createVariableToMessageBindingWithMessage($variable, $newMessage); } @@ -34,6 +36,7 @@ class GaussianPriorFactor extends GaussianFactor $variable->setValue($newMarginal); $message->setValue($this->_newMessage); + return GaussianDistribution::subtract($oldMarginal, $newMarginal); } -} \ No newline at end of file +} diff --git a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php index 0f9c685..b612ec8 100644 --- a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php +++ b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php @@ -1,8 +1,10 @@ -_weights = array(); - $this->_weightsSquared = array(); + $this->_weights = []; + $this->_weightsSquared = []; // The first weights are a straightforward copy // v_0 = a_1*v_1 + a_2*v_2 + ... + a_n * v_n @@ -40,7 +43,7 @@ class GaussianWeightedSumFactor extends GaussianFactor $variablesToSumLength = count($variablesToSum); // 0..n-1 - $this->_variableIndexOrdersForWeights[0] = array(); + $this->_variableIndexOrdersForWeights[0] = []; for ($i = 0; $i < ($variablesToSumLength + 1); $i++) { $this->_variableIndexOrdersForWeights[0][] = $i; } @@ -178,6 +181,7 @@ class GaussianWeightedSumFactor extends GaussianFactor // Return the difference in the new marginal $finalDiff = GaussianDistribution::subtract($newMarginal, $marginal0); + return $finalDiff; } @@ -186,10 +190,10 @@ class GaussianWeightedSumFactor extends GaussianFactor $allMessages = $this->getMessages(); $allVariables = $this->getVariables(); - Guard::argumentIsValidIndex($messageIndex, count($allMessages), "messageIndex"); + Guard::argumentIsValidIndex($messageIndex, count($allMessages), 'messageIndex'); - $updatedMessages = array(); - $updatedVariables = array(); + $updatedMessages = []; + $updatedVariables = []; $indicesToUse = $this->_variableIndexOrdersForWeights[$messageIndex]; @@ -211,7 +215,7 @@ class GaussianWeightedSumFactor extends GaussianFactor private static function createName($sumVariable, $variablesToSum, $weights) { // TODO: Perf? Use PHP equivalent of StringBuilder? implode on arrays? - $result = (string)$sumVariable; + $result = (string) $sumVariable; $result .= ' = '; $totalVars = count($variablesToSum); @@ -222,15 +226,15 @@ class GaussianWeightedSumFactor extends GaussianFactor $result .= '-'; } - $absValue = sprintf("%.2f", \abs($weights[$i])); // 0.00? + $absValue = sprintf('%.2f', \abs($weights[$i])); // 0.00? $result .= $absValue; - $result .= "*["; - $result .= (string)$variablesToSum[$i]; + $result .= '*['; + $result .= (string) $variablesToSum[$i]; $result .= ']'; $isLast = ($i == ($totalVars - 1)); - if (!$isLast) { + if (! $isLast) { if ($weights[$i + 1] >= 0) { $result .= ' + '; } else { @@ -241,4 +245,4 @@ class GaussianWeightedSumFactor extends GaussianFactor return $result; } -} \ No newline at end of file +} diff --git a/src/TrueSkill/Factors/GaussianWithinFactor.php b/src/TrueSkill/Factors/GaussianWithinFactor.php index 1cb1722..4bac265 100644 --- a/src/TrueSkill/Factors/GaussianWithinFactor.php +++ b/src/TrueSkill/Factors/GaussianWithinFactor.php @@ -1,9 +1,11 @@ -_epsilon = $epsilon; $this->createVariableToMessageBinding($variable); } @@ -57,7 +59,7 @@ class GaussianWithinFactor extends GaussianFactor $denominator = 1.0 - TruncatedGaussianCorrectionFunctions::wWithinMargin($dOnSqrtC, $epsilonTimesSqrtC); $newPrecision = $c / $denominator; - $newPrecisionMean = ( $d + + $newPrecisionMean = ($d + $sqrtC * TruncatedGaussianCorrectionFunctions::vWithinMargin($dOnSqrtC, $epsilonTimesSqrtC) ) / $denominator; @@ -75,4 +77,4 @@ class GaussianWithinFactor extends GaussianFactor // Return the difference in the new marginal return GaussianDistribution::subtract($newMarginal, $oldMarginal); } -} \ No newline at end of file +} diff --git a/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php b/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php index 25cd27c..c6d9318 100644 --- a/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php +++ b/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php @@ -1,15 +1,18 @@ -scheduleSequence( $itemsToSequence, - "loop of just two teams inner sequence"); + 'loop of just two teams inner sequence'); } private function createMultipleTeamInnerPriorLoopSchedule() { $totalTeamDifferences = count($this->_TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors()); - $forwardScheduleList = array(); + $forwardScheduleList = []; for ($i = 0; $i < $totalTeamDifferences - 1; $i++) { $teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors = $this->_TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors(); @@ -118,24 +121,24 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer $currentForwardSchedulePiece = $this->scheduleSequence( - array( + [ new ScheduleStep( - sprintf("team perf to perf diff %d", $i), + sprintf('team perf to perf diff %d', $i), $currentTeamPerfToTeamPerfDiff, 0), new ScheduleStep( - sprintf("greater than or within result factor %d", $i), + sprintf('greater than or within result factor %d', $i), $currentTeamDiffComparison, 0), new ScheduleStep( - sprintf("team perf to perf diff factors [%d], 2", $i), - $currentTeamPerfToTeamPerfDiff, 2) - ), sprintf("current forward schedule piece %d", $i)); + sprintf('team perf to perf diff factors [%d], 2', $i), + $currentTeamPerfToTeamPerfDiff, 2), + ], sprintf('current forward schedule piece %d', $i)); $forwardScheduleList[] = $currentForwardSchedulePiece; } - $forwardSchedule = new ScheduleSequence("forward schedule", $forwardScheduleList); + $forwardSchedule = new ScheduleSequence('forward schedule', $forwardScheduleList); - $backwardScheduleList = array(); + $backwardScheduleList = []; for ($i = 0; $i < $totalTeamDifferences - 1; $i++) { $teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors = $this->_TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors(); @@ -146,35 +149,35 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer $performancesToDifferencesFactor = $teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors[$totalTeamDifferences - 1 - $i]; $currentBackwardSchedulePiece = new ScheduleSequence( - "current backward schedule piece", - array( + 'current backward schedule piece', + [ new ScheduleStep( - sprintf("teamPerformanceToPerformanceDifferenceFactors[totalTeamDifferences - 1 - %d] @ 0", $i), + sprintf('teamPerformanceToPerformanceDifferenceFactors[totalTeamDifferences - 1 - %d] @ 0', $i), $differencesFactor, 0), new ScheduleStep( - sprintf("greaterThanOrWithinResultFactors[totalTeamDifferences - 1 - %d] @ 0", $i), + sprintf('greaterThanOrWithinResultFactors[totalTeamDifferences - 1 - %d] @ 0', $i), $comparisonFactor, 0), new ScheduleStep( - sprintf("teamPerformanceToPerformanceDifferenceFactors[totalTeamDifferences - 1 - %d] @ 1", $i), - $performancesToDifferencesFactor, 1) - )); + sprintf('teamPerformanceToPerformanceDifferenceFactors[totalTeamDifferences - 1 - %d] @ 1', $i), + $performancesToDifferencesFactor, 1), + ]); $backwardScheduleList[] = $currentBackwardSchedulePiece; } - $backwardSchedule = new ScheduleSequence("backward schedule", $backwardScheduleList); + $backwardSchedule = new ScheduleSequence('backward schedule', $backwardScheduleList); $forwardBackwardScheduleToLoop = new ScheduleSequence( - "forward Backward Schedule To Loop", - array($forwardSchedule, $backwardSchedule)); + 'forward Backward Schedule To Loop', + [$forwardSchedule, $backwardSchedule]); $initialMaxDelta = 0.0001; $loop = new ScheduleLoop( - sprintf("loop with max delta of %f", $initialMaxDelta), + sprintf('loop with max delta of %f', $initialMaxDelta), $forwardBackwardScheduleToLoop, $initialMaxDelta); return $loop; } -} \ No newline at end of file +} diff --git a/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php b/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php index aa8b7fb..ac33f21 100644 --- a/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php +++ b/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php @@ -1,9 +1,9 @@ -getOutputVariablesGroups(); - $outputVariablesGroups[] = array($teamPerformance); + $outputVariablesGroups[] = [$teamPerformance]; } } @@ -37,10 +37,11 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye $sequence = $this->scheduleSequence( array_map( function ($weightedSumFactor) { - return new ScheduleStep("Perf to Team Perf Step", $weightedSumFactor, 0); + return new ScheduleStep('Perf to Team Perf Step', $weightedSumFactor, 0); }, $localFactors), - "all player perf to team perf schedule"); + 'all player perf to team perf schedule'); + return $sequence; } @@ -49,6 +50,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye $weights = array_map( function ($v) { $player = $v->getKey(); + return PartialPlay::getPartialPlayPercentage($player); }, $teamMembers); @@ -57,32 +59,33 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye $sumVariable, $teamMembers, $weights); - } public function createPosteriorSchedule() { - $allFactors = array(); + $allFactors = []; $localFactors = $this->getLocalFactors(); foreach ($localFactors as $currentFactor) { $localCurrentFactor = $currentFactor; $numberOfMessages = $localCurrentFactor->getNumberOfMessages(); for ($currentIteration = 1; $currentIteration < $numberOfMessages; $currentIteration++) { - $allFactors[] = new ScheduleStep("team sum perf @" . $currentIteration, + $allFactors[] = new ScheduleStep('team sum perf @'.$currentIteration, $localCurrentFactor, $currentIteration); } } + return $this->scheduleSequence($allFactors, "all of the team's sum iterations"); } private function createOutputVariable($team) { $memberNames = array_map(function ($currentPlayer) { - return (string)($currentPlayer->getKey()); + return (string) ($currentPlayer->getKey()); }, $team); - $teamMemberNames = \join(", ", $memberNames); - $outputVariable = $this->getParentFactorGraph()->getVariableFactory()->createBasicVariable("Team[" . $teamMemberNames . "]'s performance"); + $teamMemberNames = \implode(', ', $memberNames); + $outputVariable = $this->getParentFactorGraph()->getVariableFactory()->createBasicVariable('Team['.$teamMemberNames."]'s performance"); + return $outputVariable; } -} \ No newline at end of file +} diff --git a/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php b/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php index 2695e94..20d10f5 100644 --- a/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php +++ b/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php @@ -1,11 +1,13 @@ -_teams; foreach ($teams as $currentTeam) { $localCurrentTeam = $currentTeam; - $currentTeamSkills = array(); + $currentTeamSkills = []; $currentTeamAllPlayers = $localCurrentTeam->getAllPlayers(); foreach ($currentTeamAllPlayers as $currentTeamPlayer) { @@ -44,13 +46,14 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer public function createPriorSchedule() { $localFactors = $this->getLocalFactors(); + return $this->scheduleSequence( array_map( function ($prior) { - return new ScheduleStep("Prior to Skill Step", $prior, 0); + return new ScheduleStep('Prior to Skill Step', $prior, 0); }, $localFactors), - "All priors"); + 'All priors'); } private function createPriorFactor($player, Rating $priorRating, Variable $skillsVariable) @@ -67,7 +70,8 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer { $parentFactorGraph = $this->getParentFactorGraph(); $variableFactory = $parentFactorGraph->getVariableFactory(); - $skillOutputVariable = $variableFactory->createKeyedVariable($key, $key . "'s skill"); + $skillOutputVariable = $variableFactory->createKeyedVariable($key, $key."'s skill"); + return $skillOutputVariable; } -} \ No newline at end of file +} diff --git a/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php b/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php index d2e4d62..104f593 100644 --- a/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php +++ b/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php @@ -1,10 +1,12 @@ -getOutputVariablesGroups(); foreach ($inputVariablesGroups as $currentTeam) { - $currentTeamPlayerPerformances = array(); + $currentTeamPlayerPerformances = []; foreach ($currentTeam as $playerSkillVariable) { $localPlayerSkillVariable = $playerSkillVariable; @@ -45,31 +47,34 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer private function createOutputVariable($key) { - $outputVariable = $this->getParentFactorGraph()->getVariableFactory()->createKeyedVariable($key, $key . "'s performance"); + $outputVariable = $this->getParentFactorGraph()->getVariableFactory()->createKeyedVariable($key, $key."'s performance"); + return $outputVariable; } public function createPriorSchedule() { $localFactors = $this->getLocalFactors(); + return $this->scheduleSequence( array_map( function ($likelihood) { - return new ScheduleStep("Skill to Perf step", $likelihood, 0); + return new ScheduleStep('Skill to Perf step', $likelihood, 0); }, $localFactors), - "All skill to performance sending"); + 'All skill to performance sending'); } public function createPosteriorSchedule() { $localFactors = $this->getLocalFactors(); + return $this->scheduleSequence( array_map( function ($likelihood) { - return new ScheduleStep("name", $likelihood, 1); + return new ScheduleStep('name', $likelihood, 1); }, $localFactors), - "All skill to performance sending"); + 'All skill to performance sending'); } } diff --git a/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php b/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php index 71f74cc..ccd00cc 100644 --- a/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php +++ b/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php @@ -1,13 +1,16 @@ -addLayerFactor($factor); } } -} \ No newline at end of file +} diff --git a/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php b/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php index a0615f2..3f06af6 100644 --- a/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php +++ b/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php @@ -1,8 +1,10 @@ -getOutputVariablesGroups(); - for ($i = 0; $i < $inputVariablesGroupsCount - 1; $i++) - { + for ($i = 0; $i < $inputVariablesGroupsCount - 1; $i++) { $strongerTeam = $inputVariablesGroups[$i][0]; $weakerTeam = $inputVariablesGroups[$i + 1][0]; @@ -27,7 +28,7 @@ class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorG $this->addLayerFactor($newDifferencesFactor); // REVIEW: Does it make sense to have groups of one? - $outputVariablesGroup[] = array($currentDifference); + $outputVariablesGroup[] = [$currentDifference]; } } @@ -35,14 +36,16 @@ class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorG Variable $weakerTeam, Variable $output) { - $teams = array($strongerTeam, $weakerTeam); - $weights = array(1.0, -1.0); + $teams = [$strongerTeam, $weakerTeam]; + $weights = [1.0, -1.0]; + return new GaussianWeightedSumFactor($output, $teams, $weights); } private function createOutputVariable() { - $outputVariable = $this->getParentFactorGraph()->getVariableFactory()->createBasicVariable("Team performance difference"); + $outputVariable = $this->getParentFactorGraph()->getVariableFactory()->createBasicVariable('Team performance difference'); + return $outputVariable; } -} \ No newline at end of file +} diff --git a/src/TrueSkill/Layers/TrueSkillFactorGraphLayer.php b/src/TrueSkill/Layers/TrueSkillFactorGraphLayer.php index 1edc6eb..e2c32b7 100644 --- a/src/TrueSkill/Layers/TrueSkillFactorGraphLayer.php +++ b/src/TrueSkill/Layers/TrueSkillFactorGraphLayer.php @@ -1,4 +1,6 @@ -setVariableFactory($newFactory); - $this->_layers = array( + $this->_layers = [ $this->_priorLayer, new PlayerSkillsToPerformancesLayer($this), new PlayerPerformancesToTeamPerformancesLayer($this), new IteratedTeamDifferencesInnerLayer( $this, new TeamPerformancesToTeamPerformanceDifferencesLayer($this), - new TeamDifferencesComparisonLayer($this, $teamRanks)) - ); + new TeamDifferencesComparisonLayer($this, $teamRanks)), + ]; } public function getGameInfo() @@ -83,12 +87,13 @@ class TrueSkillFactorGraph extends FactorGraph } $logZ = $factorList->getLogNormalization(); + return exp($logZ); } private function createFullSchedule() { - $fullSchedule = array(); + $fullSchedule = []; $layers = $this->_layers; foreach ($layers as $currentLayer) { @@ -107,7 +112,7 @@ class TrueSkillFactorGraph extends FactorGraph } } - return new ScheduleSequence("Full schedule", $fullSchedule); + return new ScheduleSequence('Full schedule', $fullSchedule); } public function getUpdatedRatings() @@ -127,4 +132,4 @@ class TrueSkillFactorGraph extends FactorGraph return $result; } -} \ No newline at end of file +} diff --git a/src/TrueSkill/TruncatedGaussianCorrectionFunctions.php b/src/TrueSkill/TruncatedGaussianCorrectionFunctions.php index 290cfe0..13f4f47 100644 --- a/src/TrueSkill/TruncatedGaussianCorrectionFunctions.php +++ b/src/TrueSkill/TruncatedGaussianCorrectionFunctions.php @@ -1,4 +1,6 @@ -validateTeamCountAndPlayersCountPerTeam($teams); // Make sure things are in order @@ -83,8 +85,7 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator $winningMean = $selfRating->getMean(); $losingMean = $opponentRating->getMean(); - switch ($comparison) - { + switch ($comparison) { case PairwiseComparison::WIN: case PairwiseComparison::DRAW: // NOP @@ -97,37 +98,34 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator $meanDelta = $winningMean - $losingMean; - if ($comparison != PairwiseComparison::DRAW) - { + if ($comparison != PairwiseComparison::DRAW) { // non-draw case $v = TruncatedGaussianCorrectionFunctions::vExceedsMarginScaled($meanDelta, $drawMargin, $c); $w = TruncatedGaussianCorrectionFunctions::wExceedsMarginScaled($meanDelta, $drawMargin, $c); $rankMultiplier = (int) $comparison; - } - else - { + } else { $v = TruncatedGaussianCorrectionFunctions::vWithinMarginScaled($meanDelta, $drawMargin, $c); $w = TruncatedGaussianCorrectionFunctions::wWithinMarginScaled($meanDelta, $drawMargin, $c); $rankMultiplier = 1; } - $meanMultiplier = (BasicMath::square($selfRating->getStandardDeviation()) + BasicMath::square($gameInfo->getDynamicsFactor()))/$c; + $meanMultiplier = (BasicMath::square($selfRating->getStandardDeviation()) + BasicMath::square($gameInfo->getDynamicsFactor())) / $c; $varianceWithDynamics = BasicMath::square($selfRating->getStandardDeviation()) + BasicMath::square($gameInfo->getDynamicsFactor()); - $stdDevMultiplier = $varianceWithDynamics/BasicMath::square($c); + $stdDevMultiplier = $varianceWithDynamics / BasicMath::square($c); - $newMean = $selfRating->getMean() + ($rankMultiplier*$meanMultiplier*$v); - $newStdDev = sqrt($varianceWithDynamics*(1 - $w*$stdDevMultiplier)); + $newMean = $selfRating->getMean() + ($rankMultiplier * $meanMultiplier * $v); + $newStdDev = sqrt($varianceWithDynamics * (1 - $w * $stdDevMultiplier)); return new Rating($newMean, $newStdDev); } /** - * {@inheritdoc } + * {@inheritdoc} */ public function calculateMatchQuality(GameInfo $gameInfo, array $teams) { - Guard::argumentNotNull($gameInfo, "gameInfo"); + Guard::argumentNotNull($gameInfo, 'gameInfo'); $this->validateTeamCountAndPlayersCountPerTeam($teams); $team1 = $teams[0]; @@ -146,18 +144,18 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator // This is the square root part of the equation: $sqrtPart = sqrt( - (2*$betaSquared) + (2 * $betaSquared) / - (2*$betaSquared + $player1SigmaSquared + $player2SigmaSquared) + (2 * $betaSquared + $player1SigmaSquared + $player2SigmaSquared) ); // This is the exponent part of the equation: $expPart = exp( - (-1*BasicMath::square($player1Rating->getMean() - $player2Rating->getMean())) + (-1 * BasicMath::square($player1Rating->getMean() - $player2Rating->getMean())) / - (2*(2*$betaSquared + $player1SigmaSquared + $player2SigmaSquared)) + (2 * (2 * $betaSquared + $player1SigmaSquared + $player2SigmaSquared)) ); - return $sqrtPart*$expPart; + return $sqrtPart * $expPart; } -} \ No newline at end of file +} diff --git a/src/TrueSkill/TwoTeamTrueSkillCalculator.php b/src/TrueSkill/TwoTeamTrueSkillCalculator.php index 165c7bc..106d4d1 100644 --- a/src/TrueSkill/TwoTeamTrueSkillCalculator.php +++ b/src/TrueSkill/TwoTeamTrueSkillCalculator.php @@ -1,19 +1,19 @@ -validateTeamCountAndPlayersCountPerTeam($teams); RankSorter::sort($teams, $teamRanks); @@ -111,7 +111,7 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator // non-draw case $v = TruncatedGaussianCorrectionFunctions::vExceedsMarginScaled($meanDelta, $drawMargin, $c); $w = TruncatedGaussianCorrectionFunctions::wExceedsMarginScaled($meanDelta, $drawMargin, $c); - $rankMultiplier = (int)$selfToOtherTeamComparison; + $rankMultiplier = (int) $selfToOtherTeamComparison; } else { // assume draw $v = TruncatedGaussianCorrectionFunctions::vWithinMarginScaled($meanDelta, $drawMargin, $c); @@ -143,7 +143,7 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator */ public function calculateMatchQuality(GameInfo $gameInfo, array $teams) { - Guard::argumentNotNull($gameInfo, "gameInfo"); + Guard::argumentNotNull($gameInfo, 'gameInfo'); $this->validateTeamCountAndPlayersCountPerTeam($teams); // We've verified that there's just two teams @@ -189,4 +189,4 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator return $expPart * $sqrtPart; } -} \ No newline at end of file +} diff --git a/tests/Numerics/BasicMathTest.php b/tests/Numerics/BasicMathTest.php index a0c04e8..5e9057d 100644 --- a/tests/Numerics/BasicMathTest.php +++ b/tests/Numerics/BasicMathTest.php @@ -1,4 +1,6 @@ -assertEquals(1.44, BasicMath::square(1.2)); $this->assertEquals(4, BasicMath::square(2)); } -} \ No newline at end of file +} diff --git a/tests/Numerics/GaussianDistributionTest.php b/tests/Numerics/GaussianDistributionTest.php index e09416e..a298405 100644 --- a/tests/Numerics/GaussianDistributionTest.php +++ b/tests/Numerics/GaussianDistributionTest.php @@ -1,4 +1,6 @@ -assertEqualsWithDelta(0.4330127018922193, $absDiff2, GaussianDistributionTest::ERROR_TOLERANCE); } -} \ No newline at end of file +} diff --git a/tests/Numerics/MatrixTest.php b/tests/Numerics/MatrixTest.php index 41d515f..cf9edba 100644 --- a/tests/Numerics/MatrixTest.php +++ b/tests/Numerics/MatrixTest.php @@ -1,4 +1,6 @@ -assertTrue($b->equals($a->getAdjugate())); - $c = new SquareMatrix(-3, 2, -5, -1, 0, -2, 3, -4, 1); $d = new SquareMatrix(-8, 18, -4, -5, 12, -1, - 4, -6, 2); + 4, -6, 2); $this->assertTrue($d->equals($c->getAdjugate())); } @@ -175,8 +176,7 @@ class MatrixTest extends TestCase $cInverse = $c->getInverse(); $d = Matrix::scalarMultiply((1.0 / 22), new SquareMatrix(24, -12, -2, 5, 3, -5, - -4, 2, 4)); - + -4, 2, 4)); $this->assertTrue($d->equals($cInverse)); $identity3x3 = new IdentityMatrix(3); @@ -184,4 +184,4 @@ class MatrixTest extends TestCase $ccInverse = Matrix::multiply($c, $cInverse); $this->assertTrue($identity3x3->equals($ccInverse)); } -} \ No newline at end of file +} diff --git a/tests/RankSorterTest.php b/tests/RankSorterTest.php index b30d427..6044857 100644 --- a/tests/RankSorterTest.php +++ b/tests/RankSorterTest.php @@ -1,4 +1,6 @@ - 1, "b" => 2); - $team2 = array("c" => 3, "d" => 4); - $team3 = array("e" => 5, "f" => 6); + $team1 = ['a' => 1, 'b' => 2]; + $team2 = ['c' => 3, 'd' => 4]; + $team3 = ['e' => 5, 'f' => 6]; - $teams = array($team1, $team2, $team3); + $teams = [$team1, $team2, $team3]; - $teamRanks = array(3, 1, 2); + $teamRanks = [3, 1, 2]; $sortedRanks = RankSorter::sort($teams, $teamRanks); @@ -30,4 +32,4 @@ class RankSorterTest extends TestCase $this->assertEquals($teams[1], $sortedRanks[1]); $this->assertEquals($teams[2], $sortedRanks[2]); } -} \ No newline at end of file +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 62cc21b..9ea9fe6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,5 +1,7 @@ -assertEqualsWithDelta($expected, $actual, DrawMarginTest::ERROR_TOLERANCE); } -} \ No newline at end of file +} diff --git a/tests/TrueSkill/FactorGraphTeamTrueSkillCalculatorTest.php b/tests/TrueSkill/FactorGraphTeamTrueSkillCalculatorTest.php index 23a0c24..c5f3bad 100644 --- a/tests/TrueSkill/FactorGraphTeamTrueSkillCalculatorTest.php +++ b/tests/TrueSkill/FactorGraphTeamTrueSkillCalculatorTest.php @@ -1,4 +1,6 @@ -getDefaultRating()); - $team2 = new Team($player2, $gameInfo->getDefaultRating());; + $team2 = new Team($player2, $gameInfo->getDefaultRating()); $teams = Teams::concat($team1, $team2); - $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 2)); + $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]); $player1NewRating = $newRatings->getRating($player1); self::assertRating($testClass, 29.39583201999924, 7.171475587326186, $player1NewRating); @@ -104,7 +107,7 @@ class TrueSkillCalculatorTests $team2 = new Team($player2, $gameInfo->getDefaultRating()); $teams = Teams::concat($team1, $team2); - $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 1)); + $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 1]); $player1NewRating = $newRatings->getRating($player1); self::assertRating($testClass, 25.0, 6.4575196623173081, $player1NewRating); @@ -125,7 +128,7 @@ class TrueSkillCalculatorTests $team1 = new Team($player1, new Rating(1301.0007, 42.9232)); $team2 = new Team($player2, new Rating(1188.7560, 42.5570)); - $newRatings = $calculator->calculateNewRatings($gameInfo, Teams::concat($team1, $team2), array(1, 2)); + $newRatings = $calculator->calculateNewRatings($gameInfo, Teams::concat($team1, $team2), [1, 2]); $player1NewRating = $newRatings->getRating($player1); self::assertRating($testClass, 1304.7820836053318, 42.843513887848658, $player1NewRating); @@ -148,7 +151,7 @@ class TrueSkillCalculatorTests $teams = Teams::concat($team1, $team2); - $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 1)); + $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, [1, 1]); // Winners self::assertRating($testClass, 31.662, 7.137, $newRatingsWinLose->getRating($player1)); @@ -180,7 +183,7 @@ class TrueSkillCalculatorTests $team2->addPlayer($player3, $gameInfo->getDefaultRating()); $teams = Teams::concat($team1, $team2); - $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 2)); + $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]); // Winners self::assertRating($testClass, 33.730, 7.317, $newRatingsWinLose->getRating($player1)); @@ -215,7 +218,7 @@ class TrueSkillCalculatorTests $team2->addPlayer($player4, $gameInfo->getDefaultRating()); $teams = Teams::concat($team1, $team2); - $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 2)); + $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]); // Winners self::assertRating($testClass, 28.108, 7.774, $newRatingsWinLose->getRating($player1)); @@ -245,7 +248,7 @@ class TrueSkillCalculatorTests $team2->addPlayer($player3, new Rating(25, 8)); $teams = Teams::concat($team1, $team2); - $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 2)); + $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]); // Winners self::assertRating($testClass, 42.744, 5.602, $newRatingsWinLose->getRating($player1)); @@ -276,7 +279,7 @@ class TrueSkillCalculatorTests $team2->addPlayer($player4, $gameInfo->getDefaultRating()); $teams = Teams::concat($team1, $team2); - $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 2)); + $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]); // Winners self::assertRating($testClass, 36.337, 7.527, $newRatingsWinLose->getRating($player1)); @@ -296,7 +299,7 @@ class TrueSkillCalculatorTests $gameInfo = new GameInfo(); $team1 = new Team(); - $team1->addPlayer($player1, $gameInfo->getDefaultRating());; + $team1->addPlayer($player1, $gameInfo->getDefaultRating()); $player2 = new Player(2); $player3 = new Player(3); @@ -306,7 +309,7 @@ class TrueSkillCalculatorTests $team2->addPlayer($player3, $gameInfo->getDefaultRating()); $teams = Teams::concat($team1, $team2); - $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 1)); + $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, [1, 1]); // Winners self::assertRating($testClass, 31.660, 7.138, $newRatingsWinLose->getRating($player1)); @@ -337,7 +340,7 @@ class TrueSkillCalculatorTests $team2->addPlayer($player4, $gameInfo->getDefaultRating()); $teams = Teams::concat($team1, $team2); - $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 1)); + $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, [1, 1]); // Winners self::assertRating($testClass, 34.990, 7.455, $newRatingsWinLose->getRating($player1)); @@ -377,7 +380,7 @@ class TrueSkillCalculatorTests $team2->addPlayer($player8, $gameInfo->getDefaultRating()); $teams = Teams::concat($team1, $team2); - $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 2)); + $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]); // Winners self::assertRating($testClass, 40.582, 7.917, $newRatingsWinLose->getRating($player1)); @@ -405,7 +408,6 @@ class TrueSkillCalculatorTests $team1->addPlayer($player2, new Rating(27, 6)); $team1->addPlayer($player3, new Rating(26, 5)); - $player4 = new Player(4); $player5 = new Player(5); @@ -416,7 +418,7 @@ class TrueSkillCalculatorTests $gameInfo = new GameInfo(); $teams = Teams::concat($team1, $team2); - $newRatingsWinLoseExpected = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 2)); + $newRatingsWinLoseExpected = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]); // Winners self::assertRating($testClass, 28.658, 6.770, $newRatingsWinLoseExpected->getRating($player1)); @@ -427,7 +429,7 @@ class TrueSkillCalculatorTests self::assertRating($testClass, 29.785, 3.958, $newRatingsWinLoseExpected->getRating($player4)); self::assertRating($testClass, 30.879, 2.983, $newRatingsWinLoseExpected->getRating($player5)); - $newRatingsWinLoseUpset = $calculator->calculateNewRatings($gameInfo, Teams::concat($team1, $team2), array(2, 1)); + $newRatingsWinLoseUpset = $calculator->calculateNewRatings($gameInfo, Teams::concat($team1, $team2), [2, 1]); // Winners self::assertRating($testClass, 32.012, 3.877, $newRatingsWinLoseUpset->getRating($player4)); @@ -460,7 +462,7 @@ class TrueSkillCalculatorTests $team2->addPlayer($player4, new Rating(30, 3)); $teams = Teams::concat($team1, $team2); - $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 1)); + $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, [1, 1]); // Winners self::assertRating($testClass, 21.570, 6.556, $newRatingsWinLose->getRating($player1)); @@ -492,7 +494,7 @@ class TrueSkillCalculatorTests $team2->addPlayer($player4, new Rating(40, 5)); $teams = Teams::concat($team1, $team2); - $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 2)); + $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]); // Winners self::assertRating($testClass, 29.698, 7.008, $newRatingsWinLose->getRating($player1)); @@ -518,7 +520,7 @@ class TrueSkillCalculatorTests $team1->addPlayer($player1, $gameInfo->getDefaultRating()); $team1->addPlayer($player2, $gameInfo->getDefaultRating()); $team1->addPlayer($player3, $gameInfo->getDefaultRating()); - $team1->addPlayer($player4, $gameInfo->getDefaultRating());; + $team1->addPlayer($player4, $gameInfo->getDefaultRating()); $player5 = new Player(5); $player6 = new Player(6); @@ -533,7 +535,7 @@ class TrueSkillCalculatorTests $teams = Teams::concat($team1, $team2); - $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 2)); + $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]); // Winners self::assertRating($testClass, 27.198, 8.059, $newRatingsWinLose->getRating($player1)); @@ -569,7 +571,7 @@ class TrueSkillCalculatorTests $team2->addPlayer($player4, $gameInfo->getDefaultRating()); $teams = Teams::concat($team1, $team2); - $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 1)); + $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, [1, 1]); // Winners self::assertRating($testClass, 25, 7.455, $newRatingsWinLose->getRating($player1)); @@ -582,7 +584,6 @@ class TrueSkillCalculatorTests self::assertMatchQuality($testClass, 0.447, $calculator->calculateMatchQuality($gameInfo, $teams)); } - private static function threeTeamsOfOneNotDrawn($testClass, SkillCalculator $calculator) { $player1 = new Player(1); @@ -596,7 +597,7 @@ class TrueSkillCalculatorTests $team3 = new Team($player3, $gameInfo->getDefaultRating()); $teams = Teams::concat($team1, $team2, $team3); - $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 2, 3)); + $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2, 3]); $player1NewRating = $newRatings->getRating($player1); self::assertRating($testClass, 31.675352419172107, 6.6559853776206905, $player1NewRating); @@ -623,7 +624,7 @@ class TrueSkillCalculatorTests $team3 = new Team($player3, $gameInfo->getDefaultRating()); $teams = Teams::concat($team1, $team2, $team3); - $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 1, 1)); + $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 1, 1]); $player1NewRating = $newRatings->getRating($player1); self::assertRating($testClass, 25.000, 5.698, $player1NewRating); @@ -652,7 +653,7 @@ class TrueSkillCalculatorTests $teams = Teams::concat($team1, $team2, $team3, $team4); - $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 2, 3, 4)); + $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2, 3, 4]); $player1NewRating = $newRatings->getRating($player1); self::assertRating($testClass, 33.206680965631264, 6.3481091698077057, $player1NewRating); @@ -685,7 +686,7 @@ class TrueSkillCalculatorTests $team5 = new Team($player5, $gameInfo->getDefaultRating()); $teams = Teams::concat($team1, $team2, $team3, $team4, $team5); - $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 2, 3, 4, 5)); + $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2, 3, 4, 5]); $player1NewRating = $newRatings->getRating($player1); self::assertRating($testClass, 34.363135705841188, 6.1361528798112692, $player1NewRating); @@ -727,7 +728,7 @@ class TrueSkillCalculatorTests $team8 = new Team($player8, $gameInfo->getDefaultRating()); $teams = Teams::concat($team1, $team2, $team3, $team4, $team5, $team6, $team7, $team8); - $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 1, 1, 1, 1, 1, 1, 1)); + $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 1, 1, 1, 1, 1, 1, 1]); $player1NewRating = $newRatings->getRating($player1); self::assertRating($testClass, 25.000, 4.592, $player1NewRating); @@ -779,7 +780,7 @@ class TrueSkillCalculatorTests $team8 = new Team($player8, new Rating(45, 1)); $teams = Teams::concat($team1, $team2, $team3, $team4, $team5, $team6, $team7, $team8); - $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 2, 3, 4, 5, 6, 7, 8)); + $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2, 3, 4, 5, 6, 7, 8]); $player1NewRating = $newRatings->getRating($player1); self::assertRating($testClass, 35.135, 4.506, $player1NewRating); @@ -854,7 +855,7 @@ class TrueSkillCalculatorTests $newRatings = $calculator->calculateNewRatings( $gameInfo, $teams, - array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)); + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); $player1NewRating = $newRatings->getRating($player1); self::assertRating($testClass, 40.53945776946920, 5.27581643889050, $player1NewRating); @@ -935,7 +936,7 @@ class TrueSkillCalculatorTests $team3->addPlayer($player8, new Rating(30, 2)); $teams = Teams::concat($team1, $team2, $team3); - $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 2, 2)); + $newRatingsWinLose = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2, 2]); // Winners self::assertRating($testClass, 40.877, 3.840, $newRatingsWinLose->getRating($player1)); @@ -969,7 +970,7 @@ class TrueSkillCalculatorTests $team2->addPlayer($p3, $gameInfo->getDefaultRating()); $teams = Teams::concat($team1, $team2); - $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, array(1, 2)); + $newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]); $p1NewRating = $newRatings->getRating($p1); $p2NewRating = $newRatings->getRating($p2); @@ -994,4 +995,4 @@ class TrueSkillCalculatorTests { $testClass->assertEquals($expectedMatchQuality, $actualMatchQuality, '', self::ERROR_TOLERANCE_MATCH_QUALITY); } -} \ No newline at end of file +} diff --git a/tests/TrueSkill/TwoPlayerTrueSkillCalculatorTest.php b/tests/TrueSkill/TwoPlayerTrueSkillCalculatorTest.php index db5e336..5e858d7 100644 --- a/tests/TrueSkill/TwoPlayerTrueSkillCalculatorTest.php +++ b/tests/TrueSkill/TwoPlayerTrueSkillCalculatorTest.php @@ -1,4 +1,6 @@ -