コード例 #1
0
 /**
  * @param Game $game
  * @return array (column, row)
  */
 public function getMove(Game $game)
 {
     if ($game->hasEmptyBoard()) {
         /*
          * If the board is empty, instead of calculating the field to mark,
          * we select it by random.
          *
          * We can do this, because it never worsens this game's result for
          * the player: a computer player will still draw with another computer
          * player, and not lose with a human player.
          *
          * We want to do this, because it's quicker than calculating the move.
          */
         list($column, $row) = $game->getRandomBoardCoordinates();
     } else {
         list($column, $row) = $this->getMiniMaxMove($game);
     }
     $this->ioService->printMessage(sprintf("%s %s\n", $column, $row));
     return [$column, $row];
 }
コード例 #2
0
 public function test_it_returns_false_for_game_with_not_empty_board_when_checking_if_board_is_empty()
 {
     $this->board->shouldReceive("isEmpty")->andReturn(false);
     $this->assertFalse($this->game->hasEmptyBoard());
 }