/** * @see GameInitiationResponse::addBattlefield() * @test */ public function addBattlefield() { $game = MockFactory::getGameMock(); $game->getBattlefields()[0]->setPlayer(MockFactory::getAIPlayerMock(''))->getCellByCoordinate('A1')->setFlags(CellModel::FLAG_SHIP); $request = new GameInitiationResponse($game->getBattlefields()); foreach ($request->getBattlefields() as $battlefield) { foreach ($battlefield->getCells() as $cell) { if (PlayerModel::isAIControlled($battlefield->getPlayer())) { $this->assertEquals(CellModel::FLAG_NONE, $cell->getFlags()); } } } }
/** * invoke game processing method to Win Game * * @see GameProcessor::processTurn * @test * * @depends processTurnToNotWin */ public function processTurnToWin() { $game = MockFactory::getGameMock(); /** to make sure CPU will never win from one turn. */ $game->getBattlefields()[0]->getCellByCoordinate('A1')->addFlag(CellModel::FLAG_SHIP); $game->getBattlefields()[0]->getCellByCoordinate('A2')->addFlag(CellModel::FLAG_SHIP); $game->getBattlefields()[1]->setPlayer(MockFactory::getAIPlayerMock('')); $game->getBattlefields()[1]->getCellByCoordinate('A1')->addFlag(CellModel::FLAG_SHIP); $game = static::$gameProcessor->processTurn($game->getBattlefields()[1]->getCellByCoordinate('A1')); $this->assertNotNull($game->getResult()); $this->assertInstanceOf(GameResult::class, $game->getResult()); }
/** * should return true if player marked by @see PlayerModel::FLAG_AI_CONTROLLED flag * * @see PlayerModel::isAIControlled * @test */ public function isAIControlledOnFlagAIControlled() { $this->assertTrue(PlayerModel::isAIControlled(MockFactory::getAIPlayerMock(''))); }