示例#1
0
        $this->whereToPrint = $whereToPrint;
    }
    public function solve($theProblem)
    {
        $this->gatherPlayersForProblem($theProblem);
        $this->play();
    }
    private function gatherPlayersForProblem($theProblem)
    {
        $this->players = PlayerBuilder::buildPlayers($theProblem, $this->whereToPrint);
    }
    private function play()
    {
        $this->whereToPrint->startProblemOutput();
        $this->makePlayersPlay();
        $this->whereToPrint->endProblemOutput();
    }
    private function makePlayersPlay()
    {
        foreach ($this->players as $player) {
            $player->tellUs($this->whereToPrint);
        }
    }
}
$theFile = $argv[1];
$theReader = new ProblemReader($theFile);
$theInput = $theReader->getProblems();
$theSolver = new ProblemSolver(new OutputFormatter(new Console()));
foreach ($theInput as $aProblem) {
    $theSolver->solve($aProblem);
}
示例#2
0
        $bestNode = Node::selectBestNode($graph->nodes);
        foreach ($bestNode->getBestWay() as $step) {
            echo $step->letter;
        }
        echo "\n";
    }
    private function buildGraph()
    {
        $matches = $this->problem->getPairsOfMatchingPositions();
        $graph = new Graph();
        foreach ($matches as $match1) {
            foreach ($matches as $match2) {
                if ($match1 != $match2) {
                    $di = $match2->pos1 - $match1->pos1;
                    $dj = $match2->pos2 - $match1->pos2;
                    if ($di > 0 && $dj > 0) {
                        $graph->newLink($match1, $match2);
                    }
                }
            }
        }
        return $graph;
    }
}
foreach (file($argv[1]) as $line) {
    $inputLine = trim($line);
    if ($inputLine != "") {
        $solver = new ProblemSolver(ProblemBuilder::buildProblem($inputLine));
        $solver->solve();
    }
}