/** * @param Game $game * @return array */ public function getMove(Game $game) { $maximizingPlayerMark = $game->getCurrentPlayerMark(); $minimizingPlayerMark = $game->getOtherPlayerMark(); /* * Initial revenue has to be worse than in the worse case game scenario */ $currentRevenue = -self::MAX_REVENUE * 2; $currentColumn = null; $currentRow = null; $boardState = $game->getBoard(); $emptyFields = $boardState->getEmptyFields(); foreach ($emptyFields as $column => $rows) { foreach ($rows as $row => $emptyValue) { $boardState->markField($column, $row, $maximizingPlayerMark); $newRevenue = $this->calculateMiniMaxRevenue($boardState, $maximizingPlayerMark, true, $minimizingPlayerMark); $boardState->clearField($column, $row); if ($newRevenue > $currentRevenue) { $currentRevenue = $newRevenue; $currentColumn = $column; $currentRow = $row; } } } return [$currentColumn, $currentRow]; }
/** * @param Game $game * @throws GameServiceException */ private function checkPlayerGameMarks(Game $game) { if (null === $game->getCurrentPlayerMark() || null === $game->getOtherPlayerMark()) { throw new GameServiceException("Player doesn't have a game mark specified"); } }
public function test_it_returns_opposing_player_mark_for_new_game_when_retrieving_other_player_mark() { $this->assertEquals(self::OPPOSING_MARK, $this->game->getOtherPlayerMark()); }