|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jscience.computing.game.GameUtils
public final class GameUtils
The class GameUtils 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)
DOCUMENT ME! |
static boolean |
matchInArrays(int[] a,
int[] b)
DOCUMENT ME! |
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)
game - DOCUMENT ME!player - DOCUMENT ME!roles - DOCUMENT ME!descending - DOCUMENT ME!
public static double minMaxSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
Monitor monitor)
game - the GamePlay containing the game state information with the
ability to create its childrenmove - the move to be evaluatedplayer - used to call the Player's heuristic function if node is a
leafrole - 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 thread
Player,
Monitor
public static double minMaxSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
long time)
game - the GamePlay containing the game state information with the
ability to create its childrenmove - the move to be evaluatedplayer - used to call the Player's heuristic function if node is a
leafrole - 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)
game - the GamePlay containing the game state information with the
ability to create its childrenmove - the move to be evaluatedplayer - used to call the Player's heuristic function if node is a
leafrole - 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 search
Player
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)
game - DOCUMENT ME!move - DOCUMENT ME!player - DOCUMENT ME!role - DOCUMENT ME!level - DOCUMENT ME!time - DOCUMENT ME!orderMoves - DOCUMENT ME!
public static double alphaBetaSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
double alpha,
double beta,
long time,
boolean orderMoves)
game - DOCUMENT ME!move - DOCUMENT ME!player - DOCUMENT ME!role - DOCUMENT ME!level - DOCUMENT ME!alpha - DOCUMENT ME!beta - DOCUMENT ME!time - DOCUMENT ME!orderMoves - DOCUMENT ME!
public static double alphaBetaSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
boolean orderMoves)
game - DOCUMENT ME!move - DOCUMENT ME!player - DOCUMENT ME!role - DOCUMENT ME!level - DOCUMENT ME!orderMoves - DOCUMENT ME!
public static double alphaBetaSearch(GamePlay game,
GameMove move,
Player player,
int[] role,
int level,
double alpha,
double beta,
boolean orderMoves)
game - DOCUMENT ME!move - DOCUMENT ME!player - DOCUMENT ME!role - DOCUMENT ME!level - DOCUMENT ME!alpha - DOCUMENT ME!beta - DOCUMENT ME!orderMoves - DOCUMENT ME!
public static int checkForWin(GamePlay game,
int[] role)
game - DOCUMENT ME!role - DOCUMENT ME!
public static GamePlay depthFirstSearch(GamePlay game,
int[] roles,
int numberOfMoves,
Monitor monitor)
game - DOCUMENT ME!roles - DOCUMENT ME!numberOfMoves - DOCUMENT ME!monitor - DOCUMENT ME!
public static GamePlay depthFirstSearch(GamePlay game,
int[] roles,
int numberOfMoves,
Player player,
Monitor monitor)
game - DOCUMENT ME!roles - DOCUMENT ME!numberOfMoves - DOCUMENT ME!player - DOCUMENT ME!monitor - DOCUMENT ME!
public static GamePlay bestFirstSearch(GamePlay game,
int[] roles,
int maxNumberOfNodes,
Player player,
Monitor monitor)
throws java.lang.OutOfMemoryError
game - DOCUMENT ME!roles - DOCUMENT ME!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;player - DOCUMENT ME!monitor - DOCUMENT ME!
java.lang.OutOfMemoryError - DOCUMENT ME!
public static GamePlay breadthFirstSearch(GamePlay game,
int[] roles,
int numberOfMoves,
Monitor monitor)
throws java.lang.OutOfMemoryError
game - DOCUMENT ME!roles - DOCUMENT ME!numberOfMoves - DOCUMENT ME!monitor - DOCUMENT ME!
java.lang.OutOfMemoryError - if too many game positions are to be searched
public static boolean matchInArrays(int[] a,
int[] b)
a - DOCUMENT ME!b - DOCUMENT ME!
public static boolean isInArray(int[] array,
int element)
array - DOCUMENT ME!element - DOCUMENT ME!
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||