mirror of
				https://github.com/furyfire/trueskill.git
				synced 2025-11-04 10:12:28 +01:00 
			
		
		
		
	More type stuff and unused code removed.
This commit is contained in:
		@@ -1,24 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\FactorGraphs;
 | 
			
		||||
 | 
			
		||||
use Exception;
 | 
			
		||||
 | 
			
		||||
// XXX: This class is not used anywhere
 | 
			
		||||
class DefaultVariable extends Variable
 | 
			
		||||
{
 | 
			
		||||
    public function __construct()
 | 
			
		||||
    {
 | 
			
		||||
        parent::__construct('Default', null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getValue()
 | 
			
		||||
    {
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setValue($value): never
 | 
			
		||||
    {
 | 
			
		||||
        throw new Exception();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -102,7 +102,7 @@ abstract class Factor implements \Stringable
 | 
			
		||||
 | 
			
		||||
    abstract public function createVariableToMessageBinding(Variable $variable);
 | 
			
		||||
 | 
			
		||||
    protected function createVariableToMessageBindingWithMessage(Variable $variable, Message $message)
 | 
			
		||||
    protected function createVariableToMessageBindingWithMessage(Variable $variable, Message $message): Message
 | 
			
		||||
    {
 | 
			
		||||
        $this->_messageToVariableBinding->setValue($message, $variable);
 | 
			
		||||
        $this->_messages[] = $message;
 | 
			
		||||
 
 | 
			
		||||
@@ -4,12 +4,12 @@ namespace DNW\Skills\FactorGraphs;
 | 
			
		||||
 | 
			
		||||
class KeyedVariable extends Variable
 | 
			
		||||
{
 | 
			
		||||
    public function __construct(private $_key, $name, $prior)
 | 
			
		||||
    public function __construct(private mixed $_key, string $name, mixed $prior)
 | 
			
		||||
    {
 | 
			
		||||
        parent::__construct($name, $prior);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getKey()
 | 
			
		||||
    public function getKey(): mixed
 | 
			
		||||
    {
 | 
			
		||||
        return $this->_key;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,7 @@ class Variable implements \Stringable
 | 
			
		||||
        $this->_value = $value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function resetToPrior()
 | 
			
		||||
    public function resetToPrior(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->_value = $this->_prior;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -8,14 +8,14 @@ class VariableFactory
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function createBasicVariable($name)
 | 
			
		||||
    public function createBasicVariable(string $name): Variable
 | 
			
		||||
    {
 | 
			
		||||
        $initializer = $this->_variablePriorInitializer;
 | 
			
		||||
 | 
			
		||||
        return new Variable($name, $initializer());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function createKeyedVariable($key, $name)
 | 
			
		||||
    public function createKeyedVariable(mixed $key, string $name): KeyedVariable
 | 
			
		||||
    {
 | 
			
		||||
        $initializer = $this->_variablePriorInitializer;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -11,14 +11,14 @@ class HashMap
 | 
			
		||||
 | 
			
		||||
    private array $_hashToKey = [];
 | 
			
		||||
 | 
			
		||||
    public function getValue($key)
 | 
			
		||||
    public function getValue(string|object $key): mixed
 | 
			
		||||
    {
 | 
			
		||||
        $hash = self::getHash($key);
 | 
			
		||||
 | 
			
		||||
        return $this->_hashToValue[$hash];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setValue($key, $value)
 | 
			
		||||
    public function setValue(string|object $key, mixed $value): self
 | 
			
		||||
    {
 | 
			
		||||
        $hash = self::getHash($key);
 | 
			
		||||
        $this->_hashToKey[$hash] = $key;
 | 
			
		||||
@@ -27,22 +27,22 @@ class HashMap
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getAllKeys()
 | 
			
		||||
    public function getAllKeys(): array
 | 
			
		||||
    {
 | 
			
		||||
        return array_values($this->_hashToKey);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getAllValues()
 | 
			
		||||
    public function getAllValues(): array
 | 
			
		||||
    {
 | 
			
		||||
        return array_values($this->_hashToValue);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function count()
 | 
			
		||||
    public function count(): int
 | 
			
		||||
    {
 | 
			
		||||
        return count($this->_hashToKey);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static function getHash($key)
 | 
			
		||||
    private static function getHash(string|Object $key): string
 | 
			
		||||
    {
 | 
			
		||||
        if (is_object($key)) {
 | 
			
		||||
            return spl_object_hash($key);
 | 
			
		||||
 
 | 
			
		||||
@@ -4,34 +4,34 @@ namespace DNW\Skills;
 | 
			
		||||
 | 
			
		||||
class RatingContainer
 | 
			
		||||
{
 | 
			
		||||
    private $_playerToRating;
 | 
			
		||||
    private HashMap $_playerToRating;
 | 
			
		||||
 | 
			
		||||
    public function __construct()
 | 
			
		||||
    {
 | 
			
		||||
        $this->_playerToRating = new HashMap();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getRating(Player $player)
 | 
			
		||||
    public function getRating(Player $player): mixed
 | 
			
		||||
    {
 | 
			
		||||
        return $this->_playerToRating->getValue($player);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setRating(Player $player, Rating $rating)
 | 
			
		||||
    public function setRating(Player $player, Rating $rating): HashMap
 | 
			
		||||
    {
 | 
			
		||||
        return $this->_playerToRating->setValue($player, $rating);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getAllPlayers()
 | 
			
		||||
    public function getAllPlayers(): array
 | 
			
		||||
    {
 | 
			
		||||
        return $this->_playerToRating->getAllKeys();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getAllRatings()
 | 
			
		||||
    public function getAllRatings(): array
 | 
			
		||||
    {
 | 
			
		||||
        return $this->_playerToRating->getAllValues();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function count()
 | 
			
		||||
    public function count(): int
 | 
			
		||||
    {
 | 
			
		||||
        return $this->_playerToRating->count();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ use DNW\Skills\Numerics\GaussianDistribution;
 | 
			
		||||
 | 
			
		||||
final class DrawMargin
 | 
			
		||||
{
 | 
			
		||||
    public static function getDrawMarginFromDrawProbability($drawProbability, $beta)
 | 
			
		||||
    public static function getDrawMarginFromDrawProbability(float $drawProbability, float $beta): float
 | 
			
		||||
    {
 | 
			
		||||
        // Derived from TrueSkill technical report (MSR-TR-2006-80), page 6
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,7 @@ abstract class GaussianFactor extends Factor
 | 
			
		||||
        return $logZ;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function createVariableToMessageBinding(Variable $variable)
 | 
			
		||||
    public function createVariableToMessageBinding(Variable $variable): Message
 | 
			
		||||
    {
 | 
			
		||||
        $newDistribution = GaussianDistribution::fromPrecisionMean(0, 0);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user