mirror of
				https://github.com/furyfire/trueskill.git
				synced 2025-11-04 02:02:29 +01:00 
			
		
		
		
	Cleanup in src/, adding namespaces, removing php closing tag and general code cleanup
This commit is contained in:
		@@ -1,13 +1,4 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace Moserware\Skills\TrueSkill\Layers;
 | 
			
		||||
 | 
			
		||||
require_once(dirname(__FILE__) . "/../../PartialPlay.php");
 | 
			
		||||
require_once(dirname(__FILE__) . "/../../FactorGraphs/Schedule.php");
 | 
			
		||||
require_once(dirname(__FILE__) . "/../Factors/GaussianWeightedSumFactor.php");
 | 
			
		||||
require_once(dirname(__FILE__) . "/../TrueSkillFactorGraph.php");
 | 
			
		||||
require_once(dirname(__FILE__) . "/TrueSkillFactorGraphLayer.php");
 | 
			
		||||
require_once(dirname(__FILE__) . "/TeamPerformancesToTeamPerformanceDifferencesLayer.php");
 | 
			
		||||
require_once(dirname(__FILE__) . "/TeamDifferencesComparisonLayer.php");
 | 
			
		||||
<?php namespace Moserware\Skills\TrueSkill\Layers;
 | 
			
		||||
 | 
			
		||||
use Moserware\Skills\PartialPlay;
 | 
			
		||||
use Moserware\Skills\FactorGraphs\ScheduleLoop;
 | 
			
		||||
@@ -26,18 +17,17 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
 | 
			
		||||
    public function buildLayer()
 | 
			
		||||
    {
 | 
			
		||||
        $inputVariablesGroups = &$this->getInputVariablesGroups();
 | 
			
		||||
        foreach ($inputVariablesGroups as &$currentTeam)
 | 
			
		||||
        {
 | 
			
		||||
        foreach ($inputVariablesGroups as &$currentTeam) {
 | 
			
		||||
            $localCurrentTeam = &$currentTeam;
 | 
			
		||||
            $teamPerformance = &$this->createOutputVariable($localCurrentTeam);
 | 
			
		||||
            $newSumFactor = $this->createPlayerToTeamSumFactor($localCurrentTeam, $teamPerformance);
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
            $this->addLayerFactor($newSumFactor);
 | 
			
		||||
 | 
			
		||||
            // REVIEW: Does it make sense to have groups of one?
 | 
			
		||||
            $outputVariablesGroups = &$this->getOutputVariablesGroups();
 | 
			
		||||
            $outputVariablesGroups[] = array($teamPerformance);
 | 
			
		||||
        }        
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function createPriorSchedule()
 | 
			
		||||
@@ -45,45 +35,41 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
 | 
			
		||||
        $localFactors = &$this->getLocalFactors();
 | 
			
		||||
 | 
			
		||||
        $sequence = &$this->scheduleSequence(
 | 
			
		||||
                                            array_map(
 | 
			
		||||
                                                    function($weightedSumFactor)
 | 
			
		||||
                                                    {
 | 
			
		||||
                                                        return new ScheduleStep("Perf to Team Perf Step", $weightedSumFactor, 0);
 | 
			
		||||
                                                    },
 | 
			
		||||
                                                    $localFactors),
 | 
			
		||||
                                            "all player perf to team perf schedule");
 | 
			
		||||
            array_map(
 | 
			
		||||
                function ($weightedSumFactor) {
 | 
			
		||||
                    return new ScheduleStep("Perf to Team Perf Step", $weightedSumFactor, 0);
 | 
			
		||||
                },
 | 
			
		||||
                $localFactors),
 | 
			
		||||
            "all player perf to team perf schedule");
 | 
			
		||||
        return $sequence;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function createPlayerToTeamSumFactor(&$teamMembers, &$sumVariable)
 | 
			
		||||
    {
 | 
			
		||||
        $weights = array_map(
 | 
			
		||||
                        function($v)
 | 
			
		||||
                        {
 | 
			
		||||
                            $player = &$v->getKey();
 | 
			
		||||
                            return PartialPlay::getPartialPlayPercentage($player);
 | 
			
		||||
                        },
 | 
			
		||||
                        $teamMembers);
 | 
			
		||||
            function ($v) {
 | 
			
		||||
                $player = &$v->getKey();
 | 
			
		||||
                return PartialPlay::getPartialPlayPercentage($player);
 | 
			
		||||
            },
 | 
			
		||||
            $teamMembers);
 | 
			
		||||
 | 
			
		||||
        return new GaussianWeightedSumFactor(
 | 
			
		||||
                $sumVariable,
 | 
			
		||||
                $teamMembers,
 | 
			
		||||
                $weights);
 | 
			
		||||
                                                 
 | 
			
		||||
            $sumVariable,
 | 
			
		||||
            $teamMembers,
 | 
			
		||||
            $weights);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function createPosteriorSchedule()
 | 
			
		||||
    {        
 | 
			
		||||
    {
 | 
			
		||||
        $allFactors = array();
 | 
			
		||||
        $localFactors = &$this->getLocalFactors();
 | 
			
		||||
        foreach($localFactors as &$currentFactor)
 | 
			
		||||
        {
 | 
			
		||||
        foreach ($localFactors as &$currentFactor) {
 | 
			
		||||
            $localCurrentFactor = &$currentFactor;
 | 
			
		||||
            $numberOfMessages = $localCurrentFactor->getNumberOfMessages();
 | 
			
		||||
            for($currentIteration = 1; $currentIteration < $numberOfMessages; $currentIteration++)
 | 
			
		||||
            {
 | 
			
		||||
            for ($currentIteration = 1; $currentIteration < $numberOfMessages; $currentIteration++) {
 | 
			
		||||
                $allFactors[] = new ScheduleStep("team sum perf @" . $currentIteration,
 | 
			
		||||
                                                 $localCurrentFactor, $currentIteration);
 | 
			
		||||
                    $localCurrentFactor, $currentIteration);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return $this->scheduleSequence($allFactors, "all of the team's sum iterations");
 | 
			
		||||
@@ -91,16 +77,13 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
 | 
			
		||||
 | 
			
		||||
    private function &createOutputVariable(&$team)
 | 
			
		||||
    {
 | 
			
		||||
        $memberNames = \array_map(function ($currentPlayer)
 | 
			
		||||
                                  {
 | 
			
		||||
                                        return (string)($currentPlayer->getKey());
 | 
			
		||||
                                  },
 | 
			
		||||
                                  $team);
 | 
			
		||||
        $memberNames = \array_map(function ($currentPlayer) {
 | 
			
		||||
            return (string)($currentPlayer->getKey());
 | 
			
		||||
        },
 | 
			
		||||
            $team);
 | 
			
		||||
 | 
			
		||||
        $teamMemberNames = \join(", ", $memberNames);
 | 
			
		||||
        $outputVariable = &$this->getParentFactorGraph()->getVariableFactory()->createBasicVariable("Team[" . $teamMemberNames . "]'s performance");
 | 
			
		||||
        return $outputVariable;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user