public abstract class MancalaNode extends GameNode
fairStateIndex
, a FairKalah (fair Mancala) initial game
node is created where perfect play leads to a draw.Modifier and Type | Field and Description |
---|---|
protected static int |
INIT_PIECES_PER_PIT
Initial pieces per pit for standard Mancala play.
|
protected static int |
MAX_SCORE_PIT
Score pit index for maximizing player.
|
protected static int |
MIN_SCORE_PIT
Score pit index for minimizing player.
|
protected static int |
NUM_PIECES |
protected static int |
PLAY_PITS
Total number of play pits per player
|
protected int[] |
state
How to interpret the Mancala state variable:
Let the mancala pits be notated thus:
_ _ _ _ _ _
_ 1 2 3 4 5 6
s s
6 5 4 3 2 1
where
6-1 are the first player's (MAX's) pits,
s1 is the first player's (MAX's) scoring pit,
_ _
6-1 are the second player's (MIN's) pits, and
_
s is the second player's (MIN's) scoring pit.
|
protected static int |
TOTAL_PITS
Total number of play and score pits.
|
Constructor and Description |
---|
MancalaNode()
Create a standard Mancala (a.k.a.
|
MancalaNode(int fairStateIndex)
Create an initial FairKalah (fair Mancala) state where two perfect players
will draw.
|
MancalaNode(int[] state)
Initialize Mancala node with given state piece distribution with MAX to play.
|
MancalaNode(MancalaNode node)
Mancala copy constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
clone - return a deep clone of the
MancalaNode. |
java.util.ArrayList<GameNode> |
expand()
expand - return an ArrayList of all possible next
game states |
boolean |
gameOver()
gameOver - return true if no pieces left in
play pits. |
java.util.ArrayList<java.lang.Integer> |
getLegalMoves()
Return an
ArrayList of integers, each designating a legal
pit index to play from. |
void |
makeMove(int move)
Make the designated move, redistributing pieces from the indicated position and
updating player accordingly.
|
static java.lang.String |
moveToString(int move)
Translates move integer to a String.
|
java.lang.String |
toString()
String representation of current game state.
|
abstract double |
utility()
Return an estimation of game node utility, unless game is
over.
|
childClone, getPlayer
protected static final int PLAY_PITS
protected static final int MAX_SCORE_PIT
protected static final int MIN_SCORE_PIT
protected static final int TOTAL_PITS
protected static final int INIT_PIECES_PER_PIT
protected static final int NUM_PIECES
protected int[] state
How to interpret the Mancala state variable: Let the mancala pits be notated thus: _ _ _ _ _ _ _ 1 2 3 4 5 6 s s 6 5 4 3 2 1 where 6-1 are the first player's (MAX's) pits, s1 is the first player's (MAX's) scoring pit, _ _ 6-1 are the second player's (MIN's) pits, and _ s is the second player's (MIN's) scoring pit. The numbers of pieces in each pit are stored in an array as follows: state[0] ... state[6] store the number of pieces in 6, 5, 4, 3, 2, 1, and s. _ _ _ _ _ _ _ state[7] ... state[13] store the number of pieces in 6, 5, 4, 3, 2, 1, and s. Each player's goal is to end the game with more pieces in one's own _ scoring pit. Thus a simple measure of utility would be (s - s).
public MancalaNode()
public MancalaNode(int[] state)
state
- given state piece distribution.public MancalaNode(int fairStateIndex)
fairStateIndex
- either a valid state index 1-254 or an implicit request (0) for a
random FairKalah initial state, or -1 indicating a standard (unfair)
Mancala initial state.public MancalaNode(MancalaNode node)
node
- other node to copypublic java.lang.Object clone()
clone
- return a deep clone of the
MancalaNode.public boolean gameOver()
gameOver
- return true if no pieces left in
play pits.public java.util.ArrayList<GameNode> expand()
expand
- return an ArrayList of all possible next
game statespublic java.util.ArrayList<java.lang.Integer> getLegalMoves()
ArrayList
of integers, each designating a legal
pit index to play from.ArrayList
of integers, each designating a legal
pit index to play frompublic void makeMove(int move)
move
- int value of play pit from which pieces are being moved from.public static java.lang.String moveToString(int move)
move
- pit index for current statepublic java.lang.String toString()
_ _ _ _ _ _ 1 2 3 4 5 6 ------------------------- | | 4| 4| 4| 4| 4| 4| | | 0|-----------------| 0| | | 4| 4| 4| 4| 4| 4| | <-- ------------------------- 6 5 4 3 2 1
toString
in class java.lang.Object
public abstract double utility()