示例#1
0
 /**
  * @param $teams
  * @param $matches
  * @param $result
  *
  * @dataProvider matchesProvider
  */
 public function testSerializerWithMatchesList($teams, $matches, $result)
 {
     /**
      * @var $tournament Tournament
      */
     $tournament = Factory::create(Tournament::class);
     $league = Factory::create(League::class);
     for ($i = 1; $i <= $teams; $i++) {
         TournamentTeam::forceCreate(['id' => $i, 'tournamentId' => $tournament->id, 'teamId' => array_get(Factory::create(Team::class, ['leagueId' => $league->id]), 'id')]);
     }
     foreach ($matches as $key => $match) {
         Match::create(['tournamentId' => $tournament->id, 'homeTournamentTeamId' => $match['homeTeamId'], 'awayTournamentTeamId' => $match['awayTeamId'], 'homeScore' => $match['homeScore'], 'awayScore' => $match['awayScore'], 'homePenaltyScore' => 0, 'awayPenaltyScore' => 0, 'resultType' => $match['resultType'], 'gameType' => Match::GAME_TYPE_GROUP_STAGE, 'status' => Match::STATUS_FINISHED, 'round' => $key]);
     }
     $serializer = new StandingsSerializer();
     $collection = $serializer->collection(Match::where(['tournamentId' => $tournament->id])->get());
     foreach ($result as $teamScore) {
         $item = $collection->first(function ($key, $item) use($teamScore) {
             return $item['teamId'] == $teamScore['team'];
         });
         $this->assertEquals($item['position'], $teamScore['position']);
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Clear the DB first
     $con = Propel::getWriteConnection(GameTableMap::DATABASE_NAME);
     //$sql = "DELETE FROM game WHERE name<>'test'";
     $queries = array('DELETE FROM game');
     $tables = array('game_match', 'match_state', 'turn', 'empire_order', 'empire', 'territory_template');
     foreach ($tables as $t) {
         $queries[] = "ALTER TABLE {$t} AUTO_INCREMENT = 1";
     }
     foreach ($queries as $q) {
         $stmt = $con->prepare($q);
         $stmt->execute();
     }
     //$config->system->db->useDebug(true);
     // Create or use
     $game = null;
     $games = GameQuery::create()->filterByName('test%', Criteria::LIKE);
     $game_base_name = 'test';
     $game_name = $game_base_name . '_' . $games->count();
     $p_objs = json_decode(file_get_contents(Config::get('paths.games') . "/{$game_base_name}/empires.json"), false);
     $t_objs = json_decode(file_get_contents(Config::get('paths.games') . "/{$game_base_name}/territories.json"), false);
     $game = Game::create($game_name, 1861, 'spring');
     $game->loadEmpires($p_objs);
     $game->loadTerritories($t_objs);
     $game->save();
     // $texas   = Territory::findTerritoryByName($territories, 'Texas');
     // $sequoia = Territory::findTerritoryByName($territories, 'Sequoia');
     // $ohio    = Territory::findTerritoryByName($territories, 'Ohio');
     // print "Texas-Sequoia? " . ($texas->isNeighbour($sequoia) ? 'PASS':'******') . "\n";
     // print "Sequoia-Texas? " . ($sequoia->isNeighbour($texas) ? 'PASS':'******') . "\n";
     // print "Texas-Ohio? "    . ($texas->isNeighbour($ohio) ? 'FAIL':'PASS') . "\n";
     // Empires
     $red = EmpireQuery::create()->filterByGame($game)->filterByAbbr('RED')->findOne();
     $blue = EmpireQuery::create()->filterByGame($game)->filterByAbbr('BLU')->findOne();
     $green = EmpireQuery::create()->filterByGame($game)->filterByAbbr('GRN')->findOne();
     $match = Match::create($game, "Matt Test");
     $turn = $match->getCurrentTurn();
     print "\n" . $match . "\n";
     // Territories
     // Crate the $t_<territory> magic variables.
     $t_names = array('A', 'B', 'C', 'D', 'E');
     foreach ($t_names as $n) {
         $c = new Criteria();
         $c->add(TerritoryTemplateTableMap::COL_NAME, $n);
         $tt = $game->getGameTerritories($c);
         $varname = "t_" . strtolower($n);
         ${$varname} = StateQuery::create()->filterByTerritory($tt)->findOne();
     }
     print "{$t_a} neighbours:\n";
     $neighbours = $t_a->getTerritory()->getNeighbours();
     foreach ($neighbours as $n) {
         print "{$n}\n";
     }
     print "\n" . Unit::printUnitTable($match->getCurrentTurn());
     $case = 3;
     switch ($case) {
         case 1:
             // Test move conflict
             $turn->addOrder(Move::createNS($red, $t_a, $t_b));
             $turn->addOrder(Move::createNS($red, $t_a, $t_c));
             $turn->addOrder(Move::createNS($blue, $t_a, $t_b));
             $turn->addOrder(Move::createNS($green, $t_e, $t_d));
             $turn->save();
             break;
         case 2:
             // Test support
             $turn->addOrder(Move::createNS($red, $t_a, $t_b));
             $turn->addOrder(Move::createNS($blue, $t_b, $t_c));
             $turn->addOrder(Support::createNS($green, $t_a, $t_e, $t_b));
             $turn->save();
             break;
         case 3:
             //$config->system->db->useDebug(true);
             try {
                 $turn->addOrder(Order::interpretText('MOVE "A" "B"', $match, $red));
             } catch (\DiplomacyOrm\InvalidOrderException $e) {
                 print "[" . Config::get('ansi.red') . "Error" . Config::get('ansi.clear') . "]: Red cannot MOVE A-B: " . $e->getMessage() . "\n";
                 exit;
             } catch (DiplomacyOrm\TurnClosedToOrdersException $e) {
                 print "[" . Config::get('ansi.red') . "Error" . Config::get('ansi.clear') . "]: Some how the turn state is empty again: " . $e->getMessage() . "\n";
                 exit;
             }
             $turn->addOrder(Order::interpretText('SUPPORT "E" "A" "B"', $match, $green));
             $turn->save();
             break;
         case 4:
             // Test the case with multiple contendors stalemat. standoff.svg
             $turn->addOrder(Order::interpretText('MOVE "A" "B"', $match, $red));
             $turn->addOrder(Order::interpretText('SUPPORT "A" "F" "B"', $match, $red));
             $turn->addOrder(Order::interpretText('MOVE "I" "B"', $match, $green));
             $turn->addOrder(Order::interpretText('SUPPORT "E" "H" "B"', $match, $green));
             $turn->save();
             // RED and GREEN should loose in statemates, B should belong to BLUE
             break;
         case 5:
             $turn->addOrder(Order::interpretText('MOVE "E" "C"', $match, $green));
             break;
         case 6:
             // No orders
             $result = $match->getCurrentTurn()->processOrders();
             print $match . "\n";
             $result = $match->getCurrentTurn()->processOrders();
             $result = $match->getCurrentTurn()->processOrders();
             $result = $match->getCurrentTurn()->processOrders();
             break;
     }
     $match->getCurrentTurn()->printOrders();
     $result = $match->getCurrentTurn()->processOrders();
     //print "\n" . Unit::printUnitTable($match->getCurrentTurn());
     //$match->getCurrentTurn()->printOrders();
     //print_r($result->__toArray());
     //print json_encode($result->__toArray());
     if ($result->retreatsRequired()) {
         //print $result;
         $retreat = Retreat::createNS($blue, $t_b, $t_c);
         print "Adding retreat order: {$retreat}\n";
         $match->getCurrentTurn()->addOrder($retreat);
         print "----------------------------------------\n";
         print "After adding retreat order..\n";
         $match->getCurrentTurn()->printOrders();
         $result = $match->getCurrentTurn()->processOrders();
         print $result;
     }
     // Show which orders have failed, etc
     print "\n" . $match . "\n";
 }
示例#3
0
 /**
  * @name saveRounds
  */
 protected function saveRounds($table)
 {
     foreach ($table as $key => $round) {
         foreach ($round as $match) {
             Match::create(['tournamentId' => $this->tournament->id, 'homeTournamentTeamId' => $this->teams[$match[0] - 1]['id'], 'awayTournamentTeamId' => $this->teams[$match[1] - 1]['id'], 'homeScore' => 0, 'awayScore' => 0, 'homePenaltyScore' => 0, 'awayPenaltyScore' => 0, 'round' => $key + 1, 'gameType' => Match::GAME_TYPE_GROUP_STAGE, 'resultType' => Match::RESULT_TYPE_UNKNOWN, 'status' => Match::STATUS_NOT_STARTED]);
         }
     }
 }
示例#4
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     Match::create(Request::all());
     return redirect('match');
 }