Class AlphaBetaSearchTree
- java.lang.Object
-
- org.swtpra1.alphabetaplayer.alphabeta.AlphaBetaSearchTree
-
- Direct Known Subclasses:
AlphaBetaSearchTreeWithTranspositionTables
public class AlphaBetaSearchTree extends java.lang.Object
Implements the Negamax search algorithm with alpha beta pruning optimization based on a given Evaluation function.
-
-
Field Summary
Fields Modifier and Type Field Description protected Evaluator
evaluator
protected java.util.concurrent.ExecutorService
executor
protected int
parallelism
-
Constructor Summary
Constructors Constructor Description AlphaBetaSearchTree(Evaluator evaluator, int parallelism)
Creates a search tree instance with a given evaluation function.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<Turn>
chooseMostPromisingTurns(Board board, java.util.List<Turn> turns, int player, Evaluator eval, int limit)
Given a board and a list of candidate turns, we evaluate each one statically, sort them accordingly and take as many of the best turns as possible up to a limit.ValuedTurn
negamax(Board board, int player, int depth, boolean presort)
Wrapper function to start negamax search with alpha-beta pruning optimization.protected ValuedTurn
negamax(Board board, int player, int depth, boolean presort, float alpha, float beta)
Recursive implementation of negamax algorithm with alpha beta pruning optimization.protected ValuedTurn
negamax(Board board, int player, int depth, boolean presort, float alpha, float beta, java.util.List<Turn> blacklist)
Recursive implementation of negamax algorithm with alpha beta pruning optimization.ValuedTurn
negamax(Board board, int player, int depth, boolean presort, java.util.List<Turn> blacklist)
Wrapper function to start negamax search with alpha-beta pruning optimization with a list of undesirable moves.protected ValuedTurn
parallelNegamax(Board board, int player, int depth, boolean presort, java.util.List<Turn> blacklist)
Multithreaded recursive implementation of negamax algorithm with alpha beta pruning optimization.
-
-
-
Field Detail
-
evaluator
protected final Evaluator evaluator
-
parallelism
protected final int parallelism
-
executor
protected final java.util.concurrent.ExecutorService executor
-
-
Constructor Detail
-
AlphaBetaSearchTree
public AlphaBetaSearchTree(Evaluator evaluator, int parallelism)
Creates a search tree instance with a given evaluation function.- Parameters:
evaluator
- the evaluator to use to evaluate board positionsparallelism
- seeAlphaBetaPlayer.parallelism
-
-
Method Detail
-
negamax
public ValuedTurn negamax(Board board, int player, int depth, boolean presort)
Wrapper function to start negamax search with alpha-beta pruning optimization.- Parameters:
board
- the current state of the boardplayer
- the id (0 or 1) of the player on this layerdepth
- the maximum depth to be consideredpresort
- whether to presort the moves and cut off- Returns:
- the pairing of the best possible move and its evaluation
-
parallelNegamax
protected ValuedTurn parallelNegamax(Board board, int player, int depth, boolean presort, java.util.List<Turn> blacklist)
Multithreaded recursive implementation of negamax algorithm with alpha beta pruning optimization. Uses the number of threads given.- Parameters:
board
- the current state of the boardplayer
- the id (0 or 1) of the player on this layerdepth
- the maximum depth to be consideredpresort
- whether to presort the moves and cut offblacklist
- moves that should never be considered- Returns:
- the pairing of the best possible move and its evaluation
-
negamax
public ValuedTurn negamax(Board board, int player, int depth, boolean presort, java.util.List<Turn> blacklist)
Wrapper function to start negamax search with alpha-beta pruning optimization with a list of undesirable moves.- Parameters:
board
- the current state of the boardplayer
- the id (0 or 1) of the player on this layerdepth
- the maximum depth to be consideredpresort
- whether to presort the moves and cut offblacklist
- moves that should never be considered- Returns:
- the pairing of the best possible move and its evaluation
-
negamax
protected ValuedTurn negamax(Board board, int player, int depth, boolean presort, float alpha, float beta)
Recursive implementation of negamax algorithm with alpha beta pruning optimization.- Parameters:
board
- the current boardplayer
- the id (0 or 1) of the player on this layerdepth
- the maximum depth we searchpresort
- whether to presort the turns and cut offalpha
- to determine whether better moves can be foundbeta
- to determine whether better moves can be found- Returns:
- the pairing of the best possible move and its evaluation
-
negamax
protected ValuedTurn negamax(Board board, int player, int depth, boolean presort, float alpha, float beta, java.util.List<Turn> blacklist)
Recursive implementation of negamax algorithm with alpha beta pruning optimization.- Parameters:
board
- the current boardplayer
- the id (0 or 1) of the player on this layerdepth
- the maximum depth we searchpresort
- whether to presort the turns and cut offalpha
- to determine whether better moves can be foundbeta
- to determine whether better moves can be foundblacklist
- moves that should never be considered- Returns:
- the pairing of the best possible move and its evaluation
-
chooseMostPromisingTurns
public java.util.List<Turn> chooseMostPromisingTurns(Board board, java.util.List<Turn> turns, int player, Evaluator eval, int limit)
Given a board and a list of candidate turns, we evaluate each one statically, sort them accordingly and take as many of the best turns as possible up to a limit.- Parameters:
board
- the board we are currently onturns
- list of candidate turnsplayer
- the relative player id (0 or 1)eval
- the function used to evaluate the boardslimit
- how many turns we want at most- Returns:
- the list of most promising turns
-
-