mirror of
https://github.com/furyfire/trueskill.git
synced 2025-01-15 17:37:39 +00:00
Pint applied
This commit is contained in:
@ -3,13 +3,13 @@
|
||||
"description": "Trueskill implementation by Moserware updated for PHP 8.1",
|
||||
"keywords": ["trueskill", "matchmaking", "ranking", "skill", "elo"],
|
||||
"require": {
|
||||
"php": "^8.1",
|
||||
"laravel/pint": "^0.2.3"
|
||||
"php": "^8.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.0",
|
||||
"rector/rector": "^0.13.7",
|
||||
"phpstan/phpstan": "^1.8"
|
||||
"phpstan/phpstan": "^1.8",
|
||||
"laravel/pint": "^0.2.3"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
137
composer.lock
generated
137
composer.lock
generated
@ -4,75 +4,8 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "6b092682644fef66d759ad40475e1f2e",
|
||||
"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"
|
||||
}
|
||||
],
|
||||
"content-hash": "ac8b97bff674024ae19ad228626b465d",
|
||||
"packages": [],
|
||||
"packages-dev": [
|
||||
{
|
||||
"name": "doctrine/instantiator",
|
||||
@ -144,6 +77,72 @@
|
||||
],
|
||||
"time": "2022-03-03T08:28:38+00:00"
|
||||
},
|
||||
{
|
||||
"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"
|
||||
},
|
||||
{
|
||||
"name": "myclabs/deep-copy",
|
||||
"version": "1.11.0",
|
||||
|
12
rector.php
12
rector.php
@ -9,16 +9,16 @@ use Rector\Set\ValueObject\SetList;
|
||||
|
||||
return static function (RectorConfig $rectorConfig): void {
|
||||
$rectorConfig->paths([
|
||||
__DIR__ . '/src'
|
||||
__DIR__.'/src',
|
||||
]);
|
||||
|
||||
// register a single rule
|
||||
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
|
||||
|
||||
// define sets of rules
|
||||
$rectorConfig->sets([
|
||||
LevelSetList::UP_TO_PHP_81,
|
||||
SetList::CODE_QUALITY,
|
||||
SetList::DEAD_CODE,
|
||||
]);
|
||||
$rectorConfig->sets([
|
||||
LevelSetList::UP_TO_PHP_81,
|
||||
SetList::CODE_QUALITY,
|
||||
SetList::DEAD_CODE,
|
||||
]);
|
||||
};
|
||||
|
@ -18,7 +18,7 @@ class Player implements ISupportPartialPlay, ISupportPartialUpdate, \Stringable
|
||||
/**
|
||||
* Constructs a player.
|
||||
*
|
||||
* @param mixed $_Id The identifier for the player, such as a name.
|
||||
* @param mixed $_Id The identifier for the player, such as a name.
|
||||
* @param number $partialPlayPercentage The weight percentage to give this player when calculating a new rank.
|
||||
* @param number $partialUpdatePercentage Indicated how much of a skill update a player should receive where 0 represents no update and 1.0 represents 100% of the update.
|
||||
*/
|
||||
|
@ -12,9 +12,9 @@ class Rating implements \Stringable
|
||||
/**
|
||||
* Constructs a rating.
|
||||
*
|
||||
* @param float $_mean The statistical mean value of the rating (also known as mu).
|
||||
* @param float $_standardDeviation The standard deviation of the rating (also known as s).
|
||||
* @param float|int $_conservativeStandardDeviationMultiplier optional The number of standardDeviations to subtract from the mean to achieve a conservative rating.
|
||||
* @param float $_mean The statistical mean value of the rating (also known as mu).
|
||||
* @param float $_standardDeviation The standard deviation of the rating (also known as s).
|
||||
* @param float|int $_conservativeStandardDeviationMultiplier optional The number of standardDeviations to subtract from the mean to achieve a conservative rating.
|
||||
*/
|
||||
public function __construct(private $_mean, private $_standardDeviation, private $_conservativeStandardDeviationMultiplier = self::CONSERVATIVE_STANDARD_DEVIATION_MULTIPLIER)
|
||||
{
|
||||
|
@ -47,6 +47,7 @@ abstract class SkillCalculator
|
||||
/**
|
||||
* @param array<\DNW\Skills\Team> $teams
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function validateTeamCountAndPlayersCountPerTeamWithRanges(array $teams, TeamsRange $totalTeams, PlayersRange $playersPerTeam)
|
||||
|
@ -88,7 +88,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
|
||||
{
|
||||
// A simple vector of all the player means.
|
||||
return new Vector(self::getPlayerRatingValues($teamAssignmentsList,
|
||||
fn($rating) => $rating->getMean()));
|
||||
fn ($rating) => $rating->getMean()));
|
||||
}
|
||||
|
||||
private static function getPlayerCovarianceMatrix(array $teamAssignmentsList)
|
||||
@ -97,7 +97,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
|
||||
// players.
|
||||
return new DiagonalMatrix(
|
||||
self::getPlayerRatingValues($teamAssignmentsList,
|
||||
fn($rating) => BasicMath::square($rating->getStandardDeviation())));
|
||||
fn ($rating) => BasicMath::square($rating->getStandardDeviation())));
|
||||
}
|
||||
|
||||
// Helper function that gets a list of values for all player ratings
|
||||
|
@ -38,6 +38,5 @@ class GaussianPriorFactor extends GaussianFactor
|
||||
$message->setValue($this->_newMessage);
|
||||
|
||||
return GaussianDistribution::subtract($oldMarginal, $newMarginal);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ namespace DNW\Skills\TrueSkill\Layers;
|
||||
use DNW\Skills\FactorGraphs\ScheduleStep;
|
||||
use DNW\Skills\PartialPlay;
|
||||
use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
|
||||
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
|
||||
class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLayer
|
||||
{
|
||||
@ -31,7 +30,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
||||
|
||||
return $this->scheduleSequence(
|
||||
array_map(
|
||||
fn($weightedSumFactor) => new ScheduleStep('Perf to Team Perf Step', $weightedSumFactor, 0),
|
||||
fn ($weightedSumFactor) => new ScheduleStep('Perf to Team Perf Step', $weightedSumFactor, 0),
|
||||
$localFactors),
|
||||
'all player perf to team perf schedule');
|
||||
}
|
||||
@ -70,7 +69,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
||||
|
||||
private function createOutputVariable($team)
|
||||
{
|
||||
$memberNames = array_map(fn($currentPlayer) => (string) ($currentPlayer->getKey()), $team);
|
||||
$memberNames = array_map(fn ($currentPlayer) => (string) ($currentPlayer->getKey()), $team);
|
||||
|
||||
$teamMemberNames = \implode(', ', $memberNames);
|
||||
|
||||
|
@ -46,7 +46,7 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
|
||||
|
||||
return $this->scheduleSequence(
|
||||
array_map(
|
||||
fn($prior) => new ScheduleStep('Prior to Skill Step', $prior, 0),
|
||||
fn ($prior) => new ScheduleStep('Prior to Skill Step', $prior, 0),
|
||||
$localFactors),
|
||||
'All priors');
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ use DNW\Skills\FactorGraphs\KeyedVariable;
|
||||
use DNW\Skills\FactorGraphs\ScheduleStep;
|
||||
use DNW\Skills\Numerics\BasicMath;
|
||||
use DNW\Skills\TrueSkill\Factors\GaussianLikelihoodFactor;
|
||||
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
|
||||
class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
|
||||
{
|
||||
@ -51,7 +50,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
|
||||
|
||||
return $this->scheduleSequence(
|
||||
array_map(
|
||||
fn($likelihood) => new ScheduleStep('Skill to Perf step', $likelihood, 0),
|
||||
fn ($likelihood) => new ScheduleStep('Skill to Perf step', $likelihood, 0),
|
||||
$localFactors),
|
||||
'All skill to performance sending');
|
||||
}
|
||||
@ -62,7 +61,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
|
||||
|
||||
return $this->scheduleSequence(
|
||||
array_map(
|
||||
fn($likelihood) => new ScheduleStep('name', $likelihood, 1),
|
||||
fn ($likelihood) => new ScheduleStep('name', $likelihood, 1),
|
||||
$localFactors),
|
||||
'All skill to performance sending');
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ namespace DNW\Skills\TrueSkill\Layers;
|
||||
|
||||
use DNW\Skills\FactorGraphs\Variable;
|
||||
use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
|
||||
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
|
||||
class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorGraphLayer
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ class TrueSkillFactorGraph extends FactorGraph
|
||||
{
|
||||
$this->_priorLayer = new PlayerPriorValuesToSkillsLayer($this, $teams);
|
||||
$newFactory = new VariableFactory(
|
||||
fn() => GaussianDistribution::fromPrecisionMean(0, 0));
|
||||
fn () => GaussianDistribution::fromPrecisionMean(0, 0));
|
||||
|
||||
$this->setVariableFactory($newFactory);
|
||||
$this->_layers = [
|
||||
|
@ -72,12 +72,12 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
|
||||
|
||||
$totalPlayers = $selfTeam->count() + $otherTeam->count();
|
||||
|
||||
$meanGetter = fn($currentRating) => $currentRating->getMean();
|
||||
$meanGetter = fn ($currentRating) => $currentRating->getMean();
|
||||
|
||||
$selfMeanSum = BasicMath::sum($selfTeam->getAllRatings(), $meanGetter);
|
||||
$otherTeamMeanSum = BasicMath::sum($otherTeam->getAllRatings(), $meanGetter);
|
||||
|
||||
$varianceGetter = fn($currentRating) => BasicMath::square($currentRating->getStandardDeviation());
|
||||
$varianceGetter = fn ($currentRating) => BasicMath::square($currentRating->getStandardDeviation());
|
||||
|
||||
$c = sqrt(
|
||||
BasicMath::sum($selfTeam->getAllRatings(), $varianceGetter)
|
||||
@ -153,9 +153,9 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
|
||||
|
||||
$betaSquared = BasicMath::square($gameInfo->getBeta());
|
||||
|
||||
$meanGetter = fn($currentRating) => $currentRating->getMean();
|
||||
$meanGetter = fn ($currentRating) => $currentRating->getMean();
|
||||
|
||||
$varianceGetter = fn($currentRating) => BasicMath::square($currentRating->getStandardDeviation());
|
||||
$varianceGetter = fn ($currentRating) => BasicMath::square($currentRating->getStandardDeviation());
|
||||
|
||||
$team1MeanSum = BasicMath::sum($team1Ratings, $meanGetter);
|
||||
$team1StdDevSquared = BasicMath::sum($team1Ratings, $varianceGetter);
|
||||
|
@ -989,7 +989,7 @@ class TrueSkillCalculatorTests
|
||||
private static function assertRating(TestCase $testClass, $expectedMean, $expectedStandardDeviation, $actual)
|
||||
{
|
||||
$testClass->assertEqualsWithDelta($expectedMean, $actual->getMean(), self::ERROR_TOLERANCE_TRUESKILL);
|
||||
$testClass->assertEqualsWithDelta($expectedStandardDeviation, $actual->getStandardDeviation(),self::ERROR_TOLERANCE_TRUESKILL);
|
||||
$testClass->assertEqualsWithDelta($expectedStandardDeviation, $actual->getStandardDeviation(), self::ERROR_TOLERANCE_TRUESKILL);
|
||||
}
|
||||
|
||||
private static function assertMatchQuality(TestCase $testClass, $expectedMatchQuality, $actualMatchQuality)
|
||||
|
Reference in New Issue
Block a user