|
GeneThello Home | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.genethello.gametheory.GameTheory
public abstract class GameTheory
A framework for running algorithms of game theory (minimax type) to search best move for a two players zero-sum game. It contains several famous minimax type algorithms.
| Field Summary | |
|---|---|
protected Move |
bestmove
Best move found so far. |
protected Board |
board
Board used in the game. |
protected int |
depth
Thinking depth. |
protected int[] |
historyTable
Array of integer to hold history table. To use this feature, the following should be done: Declares historyTable to be size of 2 * possible valid moves. |
protected int |
moveLength
Number of valid moves. |
protected int |
step
Current step of game. |
protected boolean |
timesUp
Terminates searching process if time's up is true. |
protected long |
transpositionMaxIndex
Maximum index of transposition table, should be (power of two) - 1, so that the size is power of two. |
protected TranspositionTable[] |
transpositionTable
Array of TranspositionTable to hold transposition table. To use this feature, the following should be done: Declares transpositionMaxIndex to be (power of two) - 1 somewhere in program initialization. e.g. |
protected boolean |
unquiet
Does quiescence search if true. |
| Constructor Summary | |
|---|---|
GameTheory()
Creates a new instance of GameTheory |
|
| Method Summary | |
|---|---|
int |
_AlphaBetaFailHard(int d,
int alpha,
int beta)
Recursive portion of original AlphaBetaFailSoft algorithm. |
int |
_AlphaBetaFailHardHistory(int d,
int alpha,
int beta)
Recursive portion of original AlphaBetaFailSoft algorithm. |
int |
_AlphaBetaFailHardTransposition(int d,
int alpha,
int beta)
Recursive portion of original AlphaBetaFailSoft algorithm. |
protected int |
_AlphaBetaFailSoft(int d,
int alpha,
int beta)
Recursive portion of AlphaBetaFailSoft algorithm. |
protected int |
_AlphaBetaFailSoftHistory(int d,
int alpha,
int beta)
Recursive portion of AlphaBetaFailSoftHistory algorithm. |
protected int |
_AlphaBetaFailSoftHistoryTransposition(int d,
int alpha,
int beta)
Recursive portion of AlphaBetaFailSoftHistoryTransposition algorithm. |
protected int |
_AlphaBetaFailSoftTransposition(int d,
int alpha,
int beta)
Recursive portion of AlphaBetaFailSoftTransposition algorithm. |
int |
_NegaMax(int d)
Recursive portion of original NegaMax algorithm. |
int |
_NegaScoutFailHard(int d,
int alpha,
int beta)
Recursive portion of original NegaScoutFailSoft algorithm. |
int |
_NegaScoutFailHardTransposition(int d,
int alpha,
int beta)
Recursive portion of original NegaScoutFailSoft algorithm. |
protected int |
_NegaScoutFailSoft(int d,
int alpha,
int beta)
Recursive portion of NegaScoutFailSoft algorithm. |
protected int |
_NegaScoutFailSoftHistory(int d,
int alpha,
int beta)
Recursive portion of NegaScoutFailSoftHistory algorithm. |
protected int |
_NegaScoutFailSoftHistoryTransposition(int d,
int alpha,
int beta)
Recursive portion of NegaScoutFailSoftHistoryTransposition algorithm. |
protected int |
_NegaScoutFailSoftTransposition(int d,
int alpha,
int beta)
Recursive portion of NegaScoutFailSoftTransposition algorithm. |
int |
AlphaBetaFailHard(int d,
int alpha,
int beta)
Searches game tree using original AlphaBetaFailSoft algorithm. |
int |
AlphaBetaFailHardHistory(int d,
int alpha,
int beta)
Searches game tree using original AlphaBetaFailSoft algorithm. |
int |
AlphaBetaFailHardTransposition(int d,
int alpha,
int beta)
Searches game tree using original AlphaBetaFailSoft algorithm. |
int |
AlphaBetaFailSoft(int d,
int alpha,
int beta)
Searches game tree using AlphaBetaFailSoft algorithm. |
int |
AlphaBetaFailSoftHistory(int d,
int alpha,
int beta)
Searches game tree using AlphaBetaFailSoft algorithm and history table. |
int |
AlphaBetaFailSoftHistoryTransposition(int d,
int alpha,
int beta)
Searches game tree using AlphaBetaFailSoft algorithm, history table and transposition table. |
int |
AlphaBetaFailSoftTransposition(int d,
int alpha,
int beta)
Searches game tree using AlphaBetaFailSoft algorithm and transposition table. |
abstract void |
DoMove(int i)
Does i-th move from valid moves. |
protected abstract void |
DoMove(Move mv)
Does move mv. |
abstract int |
Eval()
Evaluates leaf position from current player's standpoint. |
abstract void |
Generate()
Generates valid moves of next board position. |
Move |
getBestmove()
Gets best move. |
abstract Move |
getMove(int i)
Gets i-th move from valid moves. |
abstract int |
HistoryIndex(int i)
Searches index of an i-th move from array of history table. |
abstract int |
HistoryIndex(Move mv)
Searches index of a move from array of history table. |
int |
IterativeMTD()
Searches game tree using Memory-enhanced Test Driver algorithm and transposition table with iterative deepening. |
int |
IterativeNegascout()
Searches game tree using NegaScoutFailSoft algorithm and transposition table with iterative deepening. |
int |
MTD(int d,
int f)
Searches game tree using Memory-enhanced Test Driver algorithm and transposition table. |
int |
NegaMax(int d)
Searches game tree using original NegaMax algorithm. |
int |
NegaScoutFailHard(int d,
int alpha,
int beta)
Searches game tree using original NegaScoutFailSoft algorithm. |
int |
NegaScoutFailHardTransposition(int d,
int alpha,
int beta)
Searches game tree using original NegaScoutFailSoft algorithm. |
int |
NegaScoutFailSoft(int d,
int alpha,
int beta)
Searches game tree using NegaScoutFailSoft algorithm. |
int |
NegaScoutFailSoftHistory(int d,
int alpha,
int beta)
Searches game tree using NegaScoutFailSoft algorithm and history table. |
int |
NegaScoutFailSoftHistoryTransposition(int d,
int alpha,
int beta)
Searches game tree using NegaScoutFailSoft algorithm, history table and transposition table. |
int |
NegaScoutFailSoftTransposition(int d,
int alpha,
int beta)
Searches game tree using NegaScoutFailSoft algorithm and transposition table. |
protected abstract void |
PrintBoard()
Prints board position to standard output. |
protected abstract void |
PrintMove(Move mv)
Prints move to standard output. |
void |
setDepth(int depth)
Sets the depth. |
void |
setStep(int step)
Sets current step of game simulation. |
abstract void |
UndoGenerate()
Retracts generated valid moves and puts board back to previous position. |
abstract void |
UndoMove()
Undo last move. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected int[] historyTable
historyTable= new int[2 * Constants.SQNUM];
protected TranspositionTable[] transpositionTable
transpositionMaxIndex = (long) (Math.pow(2, 20) - 1);
transpositionTable = new TranspositionTable[(int) transpositionMaxIndex + 1];
private long zobristKey = 0;
private long[][] zsquares = new long[Constants.SQNUM][2];
Random rnd = new Random();
for (int i = 0; i < Constants.SQNUM; i++) {
for (int j = 0; j < 2; j++) {
zsquares[i][j] = rnd.nextLong();
}
}
zobrist values for each color having turn to moveprivate long[] zturn = new long[2];
zturn[0] = rnd.nextLong(); zturn[1] = rnd.nextLong(); zobristKey = 0;
zobristKey ^= zsquares[index][turn];
zobristKey ^= zturn[turn];
return zobristKey;
protected long transpositionMaxIndex
protected int depth
protected Board board
protected Move bestmove
protected int moveLength
protected int step
protected boolean unquiet
protected boolean timesUp
| Constructor Detail |
|---|
public GameTheory()
| Method Detail |
|---|
public int NegaMax(int d)
function negamax(node, depth, color)
if node is a terminal node or depth = 0
return color * the heuristic value of node
else
foreach child of node
α := max(α, -negamax(child, depth-1, -color))
return α
(* Initial call *)
NegaMax(depth)
d - depth
public int _NegaMax(int d)
d - depth
public int AlphaBetaFailHard(int d,
int alpha,
int beta)
function alphabeta(node, depth, α, β, Player)
if depth = 0 or node is a terminal node
return the heuristic value of node
if Player = MaxPlayer
for each child of node
α := max(α, alphabeta(child, depth-1, α, β, not(Player) ))
if β≤α
break (* Beta cut-off *)
return α
else
for each child of node
β := min(β, alphabeta(child, depth-1, α, β, not(Player) ))
if β≤α
break (* Alpha cut-off *)
return β
(* Initial call *)
AlphaBetaFailHard(depth, -infinity, +infinity)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int _AlphaBetaFailHard(int d,
int alpha,
int beta)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int AlphaBetaFailHardHistory(int d,
int alpha,
int beta)
function alphabeta(node, depth, α, β, Player)
if depth = 0 or node is a terminal node
return the heuristic value of node
if Player = MaxPlayer
for each child of node
α := max(α, alphabeta(child, depth-1, α, β, not(Player) ))
if β≤α
break (* Beta cut-off *)
return α
else
for each child of node
β := min(β, alphabeta(child, depth-1, α, β, not(Player) ))
if β≤α
break (* Alpha cut-off *)
return β
(* Initial call *)
AlphaBetaFailHardHistory(depth, -infinity, +infinity)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int _AlphaBetaFailHardHistory(int d,
int alpha,
int beta)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int AlphaBetaFailHardTransposition(int d,
int alpha,
int beta)
function alphabeta(node, depth, α, β, Player)
if depth = 0 or node is a terminal node
return the heuristic value of node
if Player = MaxPlayer
for each child of node
α := max(α, alphabeta(child, depth-1, α, β, not(Player) ))
if β≤α
break (* Beta cut-off *)
return α
else
for each child of node
β := min(β, alphabeta(child, depth-1, α, β, not(Player) ))
if β≤α
break (* Alpha cut-off *)
return β
(* Initial call *)
AlphaBetaFailHardTransposition(depth, -infinity, +infinity)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int _AlphaBetaFailHardTransposition(int d,
int alpha,
int beta)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int NegaScoutFailHard(int d,
int alpha,
int beta)
function negascout(node, depth, α, β)
if node is a terminal node or depth = 0
return the heuristic value of node
b := β (* initial window is (-β, -α) *)
foreach child of node
a := -negascout (child, depth - 1, -b, -α)
if α < a < β and child is not first child (* check if null-window failed high *)
a := -negascout(child, depth - 1, -β, -α) (* full re-search *)
α := max(α, a)
if α ≥ β
return α (* Beta cut-off *)
b := α + 1 (* set new null window *)
return α
(* Initial call *)
NegaScoutFailHard(depth, -infinity, +infinity)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int _NegaScoutFailHard(int d,
int alpha,
int beta)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int NegaScoutFailHardTransposition(int d,
int alpha,
int beta)
function negascout(node, depth, α, β)
if node is a terminal node or depth = 0
return the heuristic value of node
b := β (* initial window is (-β, -α) *)
foreach child of node
a := -negascout (child, depth - 1, -b, -α)
if α < a < β and child is not first child (* check if null-window failed high *)
a := -negascout(child, depth - 1, -β, -α) (* full re-search *)
α := max(α, a)
if α ≥ β
return α (* Beta cut-off *)
b := α + 1 (* set new null window *)
return α
(* Initial call *)
NegaScoutFailHardTransposition(depth, -infinity, +infinity)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int _NegaScoutFailHardTransposition(int d,
int alpha,
int beta)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int AlphaBetaFailSoft(int d,
int alpha,
int beta)
(* Initial call *) AlphaBetaFailSoft(depth, -infinity, +infinity)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
protected int _AlphaBetaFailSoft(int d,
int alpha,
int beta)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int AlphaBetaFailSoftHistory(int d,
int alpha,
int beta)
(* Initial call *) AlphaBetaFailSoftHistory(depth, -infinity, +infinity)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
protected int _AlphaBetaFailSoftHistory(int d,
int alpha,
int beta)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int AlphaBetaFailSoftTransposition(int d,
int alpha,
int beta)
(* Initial call *) AlphaBetaFailSoftTransposition(depth, -infinity, +infinity)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
protected int _AlphaBetaFailSoftTransposition(int d,
int alpha,
int beta)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int AlphaBetaFailSoftHistoryTransposition(int d,
int alpha,
int beta)
(* Initial call *) AlphaBetaFailSoftHistoryTransposition(depth, -infinity, +infinity)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
protected int _AlphaBetaFailSoftHistoryTransposition(int d,
int alpha,
int beta)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int NegaScoutFailSoft(int d,
int alpha,
int beta)
(* Initial call *) NegaScoutFailSoft(depth, -infinity, +infinity)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
protected int _NegaScoutFailSoft(int d,
int alpha,
int beta)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int NegaScoutFailSoftHistory(int d,
int alpha,
int beta)
(* Initial call *) NegaScoutFailSoftHistory(depth, -infinity, +infinity)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
protected int _NegaScoutFailSoftHistory(int d,
int alpha,
int beta)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int NegaScoutFailSoftTransposition(int d,
int alpha,
int beta)
(* Initial call *) NegaScoutFailSoftTransposition(depth, -infinity, +infinity)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
protected int _NegaScoutFailSoftTransposition(int d,
int alpha,
int beta)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int NegaScoutFailSoftHistoryTransposition(int d,
int alpha,
int beta)
(* Initial call *) NegaScoutFailSoftHistoryTransposition(depth, -infinity, +infinity)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
protected int _NegaScoutFailSoftHistoryTransposition(int d,
int alpha,
int beta)
d - depthalpha - lower bound of expected value of the treebeta - upper bound of expected value of the tree
public int MTD(int d,
int f)
(* Initial call *) MTD(depth, 0)
d - depthf - first guess of expected value of the tree
public int IterativeMTD()
(* Initial call *) IterativeMTD()
public int IterativeNegascout()
(* Initial call *) IterativeNegascout()
public abstract int Eval()
public abstract void Generate()
public abstract void UndoGenerate()
public abstract void DoMove(int i)
i - move indexprotected abstract void DoMove(Move mv)
mv - movepublic abstract void UndoMove()
public abstract Move getMove(int i)
i - move index
public void setDepth(int depth)
depth - depthpublic Move getBestmove()
public abstract int HistoryIndex(int i)
i - move index in array of valid moves
public abstract int HistoryIndex(Move mv)
mv - move
public void setStep(int step)
step - current stepprotected abstract void PrintBoard()
protected abstract void PrintMove(Move mv)
|
GeneThello Home | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||