Package a5.ai
Class Minimax<GameState,Move>
java.lang.Object
a5.ai.Minimax<GameState,Move>
Implementation of minimax search with alpha-beta pruning.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
An exception signifying that the search algorithm ran out of time. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
When to flush the table and start over -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Effect: Turn on the use of a transposition table.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.int
Returns: the optimal minimax value of the current game state, within the range from min to max.void
setAlphaBetaPruning
(boolean value) Effect: Set whether alpha-beta pruning is used.void
setShowSearchInfo
(boolean value) Effect: Set whether search info is printed.
-
Field Details
-
MAX_TRANSPOSITION_TABLE_SIZE
public static final int MAX_TRANSPOSITION_TABLE_SIZEWhen to flush the table and start over- See Also:
-
-
Constructor Details
-
Minimax
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
Returns: the best move from the given state that can be found by searching for up to a given amount of time. ReturnsMaybe.none()
if there is no legal move.- Parameters:
state
- the state to search fromsearchTime
- the maximum time to search, in milliseconds
-
search
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
-