public function __invoke() { $hitPoints = 103; $damagePoints = 9; $armourPoints = 2; $boss = new Boss($hitPoints, $damagePoints, $armourPoints); $game = new Game(new TurnTaker()); $weapons = $this->getWeaponCollection(); $armours = $this->getArmourCollection(); $rings = $this->getRingCollection(); $lowestCost = null; foreach ($weapons as $w => $weapon) { foreach ($armours as $a => $armour) { $permutations = $this->getRingPermutations(array_keys($rings)); foreach ($permutations as $permutation) { $boss->resurrect($hitPoints); $r1 = $permutation[0]; $r2 = $permutation[1]; $player = new Player($weapon, $armour, $rings[$r1], $rings[$r2], 100); /** * @var $winner PlayerInterface */ $winner = $game->play($player, $boss); if (!$winner->isBoss()) { $cost = $weapon->getCost() + $armour->getCost() + $rings[$r1]->getCost() + $rings[$r2]->getCost(); if (!$lowestCost || $cost < $lowestCost) { $lowestCost = $cost; } } } } } $this->write("Lowest amount of gold to win: " . $lowestCost); }
} //check if there is a winner private function winner($token) { for ($row = 0; $row < 3; $row++) { if ($this->position[3 * $row] == $token && $this->position[3 * $row + 1] == $token && $this->position[3 * $row + 2] == $token) { return true; } } for ($col = 0; $col < 3; $col++) { if ($this->position[$col] == $token && $this->position[$col + 3] == $token && $this->position[$col + 6] == $token) { return true; } } if ($this->position[0] == $token && $this->position[4] == $token && $this->position[8] == $token) { return true; } else { if ($this->position[2] == $token && $this->position[4] == $token && $this->position[6] == $token) { return true; } } return false; } } // Initialize the board if there is no previous state from the url $position = isset($_GET['board']) ? $_GET['board'] : null; $game = new Game($position); $game->play(); ?> </body> </html>
public function testInvalidInputSource() { $game = new Game(new Board()); $this->setExpectedException('RuntimeException'); $game->play(__DIR__ . '/resources/file_not_found.txt'); }
//put the computer's hand into session array Session::put('result', $result); //put the result of the match into session array $game->setscore($user->data()->id, $user->data()->hiscore); //set the score for the user, and pass in id and hiscore in case of id Redirect::to('index.php'); //redirect to index (refresh) } } else { require_once 'includes/templates/landing.php'; //require landing page template if (Input::exists()) { //if input exists $game = new Game(); //instantiate hand $game->randomHand(); //generate computer's random hand $game->play(Input::get('hand')); //play the player's hand from input $computerHand = $game->computerHand(); //set the computer's hand $result = $game->result(); //set the result Session::put('computerHand', $computerHand); //put the computer's hand into session array Session::put('result', $result); //put the result of the match into session array Redirect::to('index.php'); //redirect to index (refresh) } }
<?php require_once "Game.php"; require_once "Deck.php"; $numGames = 100000; $results = array(); $winningStates = array(); for ($i = 0; $i < $numGames; ++$i) { if ($i % 10000 == 0) { echo "{$i}..."; } $d = new Deck(); $d->shuffle(); $g = new Game($d); $turns = $g->play(); $results[] = $turns; if ($turns == 1) { echo "YOU WON!\n"; $winningStates[] = $g->boardToString(); } } echo "Final results:\n"; foreach ($results as $result) { echo "{$result},"; } echo "\n"; echo "Average: " . array_sum($results) / count($results) . "\n"; var_dump($winningStates);
<?php require 'Card.php'; require 'Deck.php'; require 'Player.php'; require 'Game.php'; $players = array('John', 'Kaley', 'Delan', 'Sam'); $game = new Game($players, 5); echo $game->play();