|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.game.GameUtilities
public final class GameUtilities
The class GameUtilities provides several algorithms for operating on GamePlay objects. These algorithms include several game tree searches such as MinMax or AlphaBeta, depth-first-search, breadth-first-search and best-first-search with GamePlay objects as nodes. These algorithms are commonly used by AutoPlay or Player objects. In addition, there are also some other convenience functions that ease standard operations GamePlay objects.
GamePlay,
AutoPlay,
Player| Method Summary | |
|---|---|
static double |
alphaBetaSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
boolean orderMoves)
This function implements Alpha-Beta Search algorithm (intelligently pruned MinMax algorithm) and returns the evaluation given by the player's heuristic functions at the leaves; limited only by deepening level. |
static double |
alphaBetaSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
double alpha,
double beta,
boolean orderMoves)
This function is usually just called by the other corresponding alphaBetaSearch function. |
static double |
alphaBetaSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
double alpha,
double beta,
long time,
boolean orderMoves)
This function is usually just called by the other timed alphaBetaSearch function. |
static double |
alphaBetaSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
double alpha,
double beta,
Monitor monitor,
boolean orderMoves)
This function is usually just called by the other corresponding monitored alphaBetaSearch function. |
static double |
alphaBetaSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
long time,
boolean orderMoves)
This function implements Alpha-Beta Search algorithm (intelligently pruned MinMax algorithm) and returns the evaluation given by the player's heuristic functions at the leaves - timed version (search cut off at given time). |
static double |
alphaBetaSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
Monitor monitor,
boolean orderMoves)
This function implements Alpha-Beta Search algorithm and returns the evaluation given by the player's heuristic functions at the leaves (intelligently pruned MinMax algorithm) - monitor version (search is cut off when monitor disabled). |
static GamePlay |
bestFirstSearch(GamePlay game,
int[] roles,
int maxNumberOfNodes,
Player player,
Monitor monitor)
A 'best-first-search' algorithm that looks for a path to win the game according to the given roles. |
static GamePlay |
breadthFirstSearch(GamePlay game,
int[] roles,
int numberOfMoves,
Monitor monitor)
breadthFirstSearch() is a 'breadth-first-search' puzzle-solver. |
static int |
checkForWin(GamePlay game,
int[] role)
This convenience function checks whether there is a winner in the game corresponding to one of the given roles in the array; if so, it returns 1 in case the Player is among the winners, and -1 if that's not the case; a zero is returned if there are no winners or if GamePlay.getWinner() returns null. |
static GamePlay |
depthFirstSearch(GamePlay game,
int[] roles,
int numberOfMoves,
Monitor monitor)
depthFirstSearch() is a 'dfs puzzle-solver' that tries to find a path to a winning game position defined by the given roles within the given number of moves. |
static GamePlay |
depthFirstSearch(GamePlay game,
int[] roles,
int numberOfMoves,
Player player,
Monitor monitor)
This depthFirstSearch() variant sorts the moves according to their heuristics provided by the given player before performing its otherwise 'depth-first-search' algorithm. |
static GameMove[] |
getLegalMovesSorted(GamePlay game,
Player player,
int[] roles,
boolean descending)
getLegalMovesSorted() sorts the legal moves of the given game descending or ascending by their heuristic calculated by the given player based on the roles. |
static boolean |
isInArray(int[] array,
int element)
|
static boolean |
matchInArrays(int[] a,
int[] b)
|
static double |
minMaxSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level)
implements MinMax Search algorithm and returns the evaluation given by the player's heuristic functions at the leaves; limited only by a deepening level |
static double |
minMaxSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
long time)
implements MinMax Search algorithm and returns the evaluation given by the player's heuristic functions at the leaves; will only run as deep as given by the level and only as long as given time is less than System.currentTimeMillis(). |
static double |
minMaxSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
Monitor monitor)
implements MinMax Search algorithm and returns the evaluation given by the player's heuristic functions at the leaves; tracking is enabled tracking through a Monitor object. |
static JGamePlay |
selectJGamePlay()
returns a JGamePlay based on a GUI-popup selection |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static JGamePlay selectJGamePlay()
public static GameMove[] getLegalMovesSorted(GamePlay game,
Player player,
int[] roles,
boolean descending)
public static double minMaxSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
Monitor monitor)
player - used to call the Player's heuristic function if node is a leafmove - the move to be evaluatedgame - the GamePlay containing the game state information with the ability
to create its childrenrole - an int[] containing the roles the given Player plays in the game;
this is used to determine whether it's the Player's or the opponent's movelevel - the game level used to limit the tree searchmonitor - used to cut off search externally and provide running feedback to
a listening threadPlayer,
Monitor
public static double minMaxSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
long time)
move - the move to be evaluatedplayer - used to call the Player's heuristic function if node is a leafgame - the GamePlay containing the game state information with the ability
to create its childrenrole - an int[] containing the roles the given Player plays in the game;
this is used to determine whether it's the Player's or the opponent's movelevel - the game level used to limit the tree searchtime - used to cut off search when the given time is before System.currentTimeMillis()Player
public static double minMaxSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level)
move - the move to be evaluatedplayer - used to call the Player's heuristic function if node is a leafgame - the GamePlay containing the game state information with the ability
to create its childrenrole - an int[] containing the roles the given Player plays in the game;
this is used to determine whether it's the Player's or the opponent's movelevel - the game level used to limit the tree searchPlayer
public static double alphaBetaSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
Monitor monitor,
boolean orderMoves)
Monitor
public static double alphaBetaSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
double alpha,
double beta,
Monitor monitor,
boolean orderMoves)
Monitor
public static double alphaBetaSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
long time,
boolean orderMoves)
public static double alphaBetaSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
double alpha,
double beta,
long time,
boolean orderMoves)
public static double alphaBetaSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
boolean orderMoves)
public static double alphaBetaSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
double alpha,
double beta,
boolean orderMoves)
public static int checkForWin(GamePlay game,
int[] role)
public static GamePlay depthFirstSearch(GamePlay game,
int[] roles,
int numberOfMoves,
Monitor monitor)
public static GamePlay depthFirstSearch(GamePlay game,
int[] roles,
int numberOfMoves,
Player player,
Monitor monitor)
public static GamePlay bestFirstSearch(GamePlay game,
int[] roles,
int maxNumberOfNodes,
Player player,
Monitor monitor)
throws OutOfMemoryError
maxNumberOfNodes - the maximum number of nodes to be examined; since
this function does not go strictly breadth or
depth first, this number does not correlate with
the number of moves away from the initial game status;
OutOfMemoryError
public static GamePlay breadthFirstSearch(GamePlay game,
int[] roles,
int numberOfMoves,
Monitor monitor)
throws OutOfMemoryError
OutOfMemoryError - if too many game positions are to be searched
public static boolean matchInArrays(int[] a,
int[] b)
public static boolean isInArray(int[] array,
int element)
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||