/** * @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 */ private function showBoard(Game $game) { $view = $this->boardViewFactory->create($game->getBoard()); $this->ioService->printMessageLine($view->render()); }
public function test_it_returns_game_board() { $this->assertEquals($this->board, $this->game->getBoard()); }