Package a5.ai

Class Minimax<GameState,Move>

java.lang.Object
a5.ai.Minimax<GameState,Move>

public class Minimax<GameState,Move> extends Object
Implementation of minimax search with alpha-beta pruning.
  • Field Details

    • MAX_TRANSPOSITION_TABLE_SIZE

      public static final int MAX_TRANSPOSITION_TABLE_SIZE
      When to flush the table and start over
      See Also:
  • Constructor Details

    • Minimax

      public Minimax(GameModel<GameState,Move> model)
      Create a new minimax AI search engine.
      Parameters:
      model - The model of the game
  • Method Details

    • activateTranspositionTable

      public void activateTranspositionTable()
      Effect: Turn on the use of a transposition table.
    • setAlphaBetaPruning

      public void setAlphaBetaPruning(boolean value)
      Effect: Set whether alpha-beta pruning is used. It is turned on by default.
    • setShowSearchInfo

      public void setShowSearchInfo(boolean value)
      Effect: Set whether search info is printed. It is turned on by default.
    • findBestMove

      public Maybe<Move> findBestMove(GameState state, int searchTime)
      Returns: the best move from the given state that can be found by searching for up to a given amount of time. Returns Maybe.none() if there is no legal move.
      Parameters:
      state - the state to search from
      searchTime - the maximum time to search, in milliseconds
    • search

      public int search(GameState state, int depth, int min, int max) throws Minimax.OutOfTime
      Returns: the optimal minimax value of the current game state, within the range from min to max. The minimax value is computed with a specified search depth, with game states reached when depth is 0 evaluated heuristically. It may search deeper than the specified depth. Checks: min < max Requires: depth >= 0, -WIN <= min, max <= WIN. Throws OutOfTime if the search has run out of time.
      Throws:
      Minimax.OutOfTime