public function hasAWinner(Game $game) { $teams = array(); $win = false; foreach ($game->getWorld()->find('headquarter') as $hq) { if (!in_array($hq->getTeam(), $teams)) { array_push($teams, $hq->getTeam()); } } if (count($teams) != $game->getWorld()->getTeamCount() - 1) { $win = true; } return $win; }
<?php require_once __DIR__ . '/../vendor/autoload.php'; use Forkwars\Game; use Forkwars\World\WorldFactory; use Forkwars\World\TerrainFactory; use Forkwars\General\InactiveBot; use Forkwars\General\NaiveBot; date_default_timezone_set('UTC'); // Init the factories $terrainFactory = new TerrainFactory(json_decode(file_get_contents(__DIR__ . '/../data/terrains.json'), true)); $worldFactory = new WorldFactory($terrainFactory); // Create world $world = $worldFactory->make(file_get_contents(__DIR__ . '/../data/island.map')); // New Game $game = new Game($world, new NaiveBot(), new InactiveBot(), new \Forkwars\WinCondition\MaxTurn(4)); $record = $game->run(); if (php_sapi_name() === 'cli') { echo $record->toJson(JSON_PRETTY_PRINT); die; } ?> <html> <head> <title>Forkwars viewer</title> <link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css"> <style> .actionList { height: 200px; overflow: scroll; }
public function hasAWinner(Game $game) { return $game->getRecord()->getTurnCount() >= $this->maxTurn; }