Package org.swtpra1.alphabetaplayer
Class AlphaBetaPlayer
- java.lang.Object
-
- org.swtpra1.AIPlayer
-
- org.swtpra1.alphabetaplayer.AlphaBetaPlayer
-
- Direct Known Subclasses:
AlphaBetaWithTranspositionTablesPlayer
public class AlphaBetaPlayer extends AIPlayer
Implementation of player that uses negamax search with alpha beta pruning optimization.
-
-
Field Summary
Fields Modifier and Type Field Description protected AlphaBetaSearchTree
alphaBeta
Implementation of the Negamax tree with AlphaBetaSearchTree pruning.long
bufferTime
a buffer time in millisecond that is used to ensure there is enough time to interrupt any ongoing calculations and encode the response turn after the time for actual calculations has run out.int
depth
the depth of the game tree that should be searched.Evaluator
evaluator
the evaluator that is used to evaluate positions of the game.protected java.util.concurrent.ExecutorService
executor
Thread for turn calculation.boolean
iterativeDeepening
enables iterative deepening which uses all of the turn time to try and calculate evaluations for progressively deeper depths.protected OpeningBook
openingBook
opening book that is used for all games played by this instance.java.io.File
openingBookFile
path to the opening book that should be used; null if disabled.int
parallelism
target parallelism for the negamax algorithm.boolean
presort
-
Fields inherited from class org.swtpra1.AIPlayer
BUFFER_TIME, DEFAULT_MAX_TURN_TIME
-
-
Constructor Summary
Constructors Constructor Description AlphaBetaPlayer()
create an AlphaBetaPlayer with default values.AlphaBetaPlayer(Evaluator evaluator, int depth, boolean iterativeDeepening, long bufferTime, int parallelism, java.io.File openingBookFile, boolean presort)
Player instance that can can be fully customized.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull Turn
calculateTurn(int gameId, Board board, int playerId, @Nullable Turn enemyTurn)
Wrapper method to calculate the turn the player will take if turn time is unlimited.Turn
calculateTurn(int gameId, Board board, int playerId, Turn enemyTurn, long maxTurnTime)
Calculate the best possible turn for a board state in limited time.-
Methods inherited from class org.swtpra1.AIPlayer
generateQueensMoves, getAllPossibleTurns, newGame
-
-
-
-
Field Detail
-
evaluator
public final Evaluator evaluator
the evaluator that is used to evaluate positions of the game.
-
depth
public final int depth
the depth of the game tree that should be searched. this is considered a minimum depth if iterative deepening is enabled.
-
iterativeDeepening
public final boolean iterativeDeepening
enables iterative deepening which uses all of the turn time to try and calculate evaluations for progressively deeper depths.
-
bufferTime
public final long bufferTime
a buffer time in millisecond that is used to ensure there is enough time to interrupt any ongoing calculations and encode the response turn after the time for actual calculations has run out.
-
parallelism
public final int parallelism
target parallelism for the negamax algorithm.should not be set to be higher than the available logical processors. high parallelism can evaluate more positions but decreases the effectiveness of alpha-beta-pruning. value 0 uses the amount of logical processors available as the target parallelism. value 1 disables parallel execution and uses a sequential version of negamax.
-
openingBookFile
public final java.io.File openingBookFile
path to the opening book that should be used; null if disabled.
-
presort
public final boolean presort
-
openingBook
protected final OpeningBook openingBook
opening book that is used for all games played by this instance.
-
executor
protected final java.util.concurrent.ExecutorService executor
Thread for turn calculation.
-
alphaBeta
protected AlphaBetaSearchTree alphaBeta
Implementation of the Negamax tree with AlphaBetaSearchTree pruning.
-
-
Constructor Detail
-
AlphaBetaPlayer
public AlphaBetaPlayer()
create an AlphaBetaPlayer with default values.
-
AlphaBetaPlayer
public AlphaBetaPlayer(Evaluator evaluator, int depth, boolean iterativeDeepening, long bufferTime, int parallelism, java.io.File openingBookFile, boolean presort)
Player instance that can can be fully customized.- Parameters:
evaluator
- seeevaluator
depth
- seedepth
iterativeDeepening
- seeiterativeDeepening
bufferTime
- seebufferTime
parallelism
- seeparallelism
openingBookFile
- seeopeningBookFile
presort
- seepresort
-
-
Method Detail
-
calculateTurn
@NotNull public @NotNull Turn calculateTurn(int gameId, Board board, int playerId, @Nullable @Nullable Turn enemyTurn)
Wrapper method to calculate the turn the player will take if turn time is unlimited.- Specified by:
calculateTurn
in classAIPlayer
- Parameters:
gameId
- the running gameboard
- the current board stateplayerId
- the id (0 or 1) of the player who we playenemyTurn
- what the enemy did in his last turn- Returns:
- the turn we will play
-
calculateTurn
public Turn calculateTurn(int gameId, Board board, int playerId, Turn enemyTurn, long maxTurnTime)
Calculate the best possible turn for a board state in limited time.- Specified by:
calculateTurn
in classAIPlayer
- Parameters:
gameId
- the running gameboard
- the current board stateplayerId
- the id (0 or 1) of the player who we playenemyTurn
- what the enemy did in his last turnmaxTurnTime
- the time we have to find our turn- Returns:
- the turn we will play
-
-