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