예제 #1
0
 /**
  * @param $teamsAmount
  * @param $matcheAmount
  *
  * @dataProvider tournamentTeamsProvider
  */
 public function testSuccessLeagueDrawWithDifferrentTeamsAmount($teamsAmount, $matchesAmount)
 {
     /**
      * @var $tournament Tournament
      */
     $tournament = Factory::create('App\\Models\\Tournament');
     /**
      * @var $tournament Tournament
      */
     $league = Factory::create('App\\Models\\League');
     Factory::times($teamsAmount)->create('App\\Models\\Team', ['leagueId' => $league->id])->each(function ($team, $key) use($tournament) {
         $tournament->tournamentTeams()->create(['teamId' => $team->id, 'tournamentId' => $tournament->id]);
     });
     $tournament->status = Tournament::STATUS_STARTED;
     $tournament->save();
     $this->assertTrue($tournament instanceof Tournament);
     // verify total matches amount
     $this->assertEquals($matchesAmount, $tournament->matches()->getResults()->count());
     /**
      * @var $matches Collection
      * @var $team TournamentTeam
      */
     $matches = Match::where(['tournamentId' => $tournament->id])->get();
     foreach ($tournament->tournamentTeams()->getResults() as $team) {
         // verify matches per team
         $this->assertEquals(($teamsAmount - 1) * 2, $matches->filter(function ($match) use($team) {
             return $match->homeTournamentTeamId == $team->id || $match->awayTournamentTeamId == $team->id;
         })->count());
     }
 }
예제 #2
0
파일: MatchTest.php 프로젝트: bashmach/ggf
 /**
  * @param $request
  * @param $response
  * @param $attributesToCheck
  *
  * @dataProvider matchUpdatesWithRequests
  */
 public function testUpdateMatchScore($request, $response, $attributesToCheck)
 {
     $member = Factory::create('App\\Models\\Member');
     Auth::login($member);
     /**
      * @var $tournament Tournament
      * @var $league League
      * @var $homeTeam Team
      * @var $awayTeam Team
      * @var $homeTournamentTeam TournamentTeam
      * @var $awayTournamentTeam TournamentTeam
      * @var $match Match
      */
     $tournament = Factory::create('App\\Models\\Tournament');
     $league = Factory::create('App\\Models\\League');
     $homeTeam = Factory::create('App\\Models\\Team', ['leagueId' => $league->id]);
     $awayTeam = Factory::create('App\\Models\\Team', ['leagueId' => $league->id]);
     $homeTournamentTeam = Factory::create('App\\Models\\TournamentTeam', ['teamId' => $homeTeam->id, 'tournamentId' => $tournament->id]);
     $awayTournamentTeam = Factory::create('App\\Models\\TournamentTeam', ['teamId' => $awayTeam->id, 'tournamentId' => $tournament->id]);
     $match = Factory::create('App\\Models\\Match', ['tournamentId' => $tournament->id, 'homeTournamentTeamId' => $homeTournamentTeam->id, 'awayTournamentTeamId' => $awayTournamentTeam->id]);
     $this->put('/api/v1/matches/' . $match->id, ['match' => $request], ['HTTP_X-Requested-With' => 'XMLHttpRequest', 'HTTP_CONTENT_TYPE' => 'application/json', 'HTTP_ACCEPT' => 'application/json']);
     $this->assertResponseStatus($response['status']);
     if (!empty($result)) {
         $updatedRow = Match::find($match->id);
         foreach ($result as $property => $value) {
             $this->assertEquals($value, $updatedRow->getAttribute($property));
         }
     }
 }
예제 #3
0
 public function update($matchId, MatchUpdate $request)
 {
     /**
      * @var $match Match
      */
     $match = Match::findOrFail($matchId);
     $match->update($request->get('match'));
     return $this->response->collection(Match::where(['id' => $matchId])->get(), new MatchTransformer(), 'matches');
 }
예제 #4
0
 public function updating(Match $model)
 {
     $dirtyStatus = array_get($model->getDirty(), 'status');
     $resultType = array_get($model->getOriginal(), 'resultType');
     // original score values
     $originalHomeScore = array_get($model->getOriginal(), 'homeScore');
     $originalAwayScore = array_get($model->getOriginal(), 'awayScore');
     // dirty score values
     $dirtyHomeScore = array_get($model->getDirty(), 'homeScore');
     $dirtyAwayScore = array_get($model->getDirty(), 'awayScore');
     if (Match::RESULT_TYPE_UNKNOWN === $resultType && Match::STATUS_FINISHED === $dirtyStatus || ($originalHomeScore !== $dirtyHomeScore || $originalAwayScore !== $dirtyAwayScore)) {
         event(new MatchWasFinished($model));
     }
 }
 public function up()
 {
     Schema::create('matches', function (Blueprint $table) {
         $table->increments('id');
         $table->integer('tournamentId')->unsigned();
         $table->integer('homeTournamentTeamId')->unsigned();
         $table->integer('awayTournamentTeamId')->unsigned();
         $table->tinyInteger('homeScore')->unsigned();
         $table->tinyInteger('awayScore')->unsigned();
         $table->tinyInteger('homePenaltyScore')->unsigned();
         $table->tinyInteger('awayPenaltyScore')->unsigned();
         $table->enum('gameType', Match::getAvailableGameTypes());
         $table->enum('resultType', Match::getAvailableResultTypes());
         $table->enum('status', Match::getAvailableStatuses())->default(Match::STATUS_NOT_STARTED);
         $table->timestamps();
     });
     Schema::table('matches', function (Blueprint $table) {
         $table->foreign('homeTournamentTeamId')->references('id')->on('tournament_teams')->onDelete('restrict')->onUpdate('restrict');
         $table->foreign('awayTournamentTeamId')->references('id')->on('tournament_teams')->onDelete('restrict')->onUpdate('restrict');
     });
 }
예제 #6
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']);
     }
 }
 /**
  * Tests if the remove match on the repo
  * works correclty.
  */
 public function testRemoveMatchRemovalSuccess()
 {
     $match = Factory::create('App\\Models\\Match');
     $result = $this->repository->removeMatch(Administrator::find($match->created_by), $match->id);
     $this->assertTrue($result);
     $this->assertNull(Match::find($match->id));
 }
예제 #8
0
 /**
  * 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";
 }
예제 #9
0
 public function standings()
 {
     $serializer = new StandingsSerializer();
     $collection = Match::with(['homeTournamentTeam.team', 'awayTournamentTeam.team'])->where(['tournamentId' => Input::get('tournamentId')]);
     return $this->response->collection($serializer->collection($collection->get()), new StandingsTransformer(), 'standing');
 }
예제 #10
0
파일: DrawLeague.php 프로젝트: bashmach/ggf
 /**
  * @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]);
         }
     }
 }
예제 #11
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     return ['match.homeScore' => 'required|integer', 'match.awayScore' => 'required|integer', 'match.status' => 'required|in:' . join(',', Match::getAvailableStatuses())];
 }
예제 #12
0
파일: Reset.php 프로젝트: bashmach/ggf
 protected function cleanupMatches()
 {
     Log::info('Clean up matches');
     return Match::where(['tournamentId' => $this->tournament->id])->delete();
 }
예제 #13
0
파일: draw.php 프로젝트: bashmach/ggf
<?php

require __DIR__ . '/../../bootstrap/autoload.php';
$app = (require_once __DIR__ . '/../../bootstrap/app.php');
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
use App;
$response = $kernel->handle($request = Illuminate\Http\Request::capture());
$tournament = App\Models\Tournament::find(1);
App\Models\Match::where(['tournamentId' => $tournament->id])->delete();
$event = new App\Events\TournamentWasStarted($tournament);
$handler = new App\Listeners\Tournament\DrawLeague();
$handler->handle($event);
 /**
  * Removes a match from the DB.
  *
  * @param Administrator $admin
  * @param int $matchID
  *
  * @throws ModelNotFoundException
  *
  * @return boolean
  */
 public function removeMatch(Administrator $admin, $matchID)
 {
     return Match::where('id', $matchID)->where('created_by', $admin->id)->firstOrFail()->delete();
 }
예제 #15
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     Match::create(Request::all());
     return redirect('match');
 }
예제 #16
0
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     Tournament::observe(new TournamentObserver());
     TournamentTeam::observe(new TournamentTeamObserver());
     Match::observe(new MatchObserver());
 }