|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.pesullivan.game.mill.engine.MillBoard
public final class MillBoard
A Nine Men's Morris implementation of Board
.
Field Summary | |
---|---|
static int |
AXIS_A
Identifies axis A of a coordinate system that locates spots on the board. |
static int |
AXIS_B
Identifies axis B of a coordinate system that locates spots on the board. |
static int |
MAX_SPOT_COORDINATE
Bounds of a square cartesian coordinate system that locates spots on the board. |
static int |
N_MAX_MEN_OUT
Maximum number of men that can be taken from one side. |
static int |
N_MEN_PER_SIDE
Number of men per side. |
static int |
N_ROWS
Number of Mill board row lines. |
static int |
N_SPOTS
Number of Mill board row intersecions. |
static int |
N_SPOTS_PER_ROW
Number of spots in a mill row. |
static int |
NO_SIDE
Value signifying the absence of a player side. |
static int |
NO_SPOT
Value signifying the absence of a playing spot. |
static int |
ROW_SPOT_0
Identifies the first of 3 spots in a row. |
static int |
ROW_SPOT_1
Identifies the middle of 3 spots in a row. |
static int |
ROW_SPOT_2
Identifies the last of 3 spots in a row. |
Method Summary | |
---|---|
Board |
copy()
Return a copy (ignoring move iterator state). |
int |
getActiveSide()
Get an index identifying the active side (whose turn it is). |
int |
getAlteredLevelOfPlay(int level)
Return the number of turns the Game engine should look ahead. |
int |
getEmptyNeighborCount(int spot)
|
Move |
getFirstMove()
Reset the board's move iterator and return the first move. |
int |
getGoodEnoughScore(int plannedScore,
int levelOfPlay)
Return a score which is good enough that a player need look no farther to see how much better it gets. |
Move |
getLastMoveExecuted()
Return the last move that was executed. |
int |
getMenLeft()
Return the number of men left to be placed by the active side. |
int |
getMenLeft(int side)
Return the number of men left to be placed by the given side. |
int |
getMenOut(int side)
Return the number of men taken from the given side. |
static MillMove |
getMove(java.lang.String positionText)
Return the move described by positionText. |
Board |
getNewBoard()
Return a new board ready for a new game. |
Move |
getNextMove()
Return the next move based on the board's move iterator. |
static java.lang.String |
getPositionText(int spot)
Return text notation for the given move spot. |
int |
getProgress()
Return a measure of progress towards the game conclusion. |
int |
getRepetitionPenalty(int nRepeats)
Get a score penalty for repeating a position so many times. |
int |
getScore()
Express the position's merits as a scalar relative score. |
static int |
getSpot(int coordinateA,
int coordinateB)
Return the intersection spot index at coordinate a,b. |
static int |
getSpot(java.lang.String positionText)
Get the spot indicated by the given textPosition. |
static int |
getSpotCoordinate(int spot,
int axis)
Return an a or b cartesian coordinate for the given board spot. |
static int |
getSpotCoordinate(int row,
int spot,
int axis)
Return an a or b cartesian coordinate for the given row spot. |
int |
getSpotSide(int spot)
Get the side of the piece currently occupying the given spot. |
int |
getSpotSide(java.lang.String positionText)
Get the side of the piece currently occupying the given spot. |
Move |
getUndefinedMove()
Return a new move which has not yet been defined. |
void |
go(Move mv)
Execute the given move. |
boolean |
isFlying()
Return true if the current move is a flying move. |
boolean |
isGameOver()
Return true if the active side has no move. |
boolean |
isPlacing()
Return true if the current move is a placing move. |
boolean |
isSame(Board board)
Compare board states (ignoring move iterator state). |
boolean |
isSliding()
Return true if the current move is a sliding move. |
boolean |
isTaking()
Return true if the current move is a taking move. |
boolean |
isTakingAny()
Return true if the player can take even from a mill. |
boolean |
isTranslating()
Return true if the current move is a sliding or flying move. |
boolean |
isValidMove(MillMove move)
Return true if the given move is valid given the board state. |
boolean |
isWon()
Return true if either side has won. |
boolean |
isWon(int score)
Return true if the given score means that either side won. |
void |
setFrom(Board board)
Set the board state to that of board ,
(ignoring move iterator state). |
void |
setFromJSON(org.json.simple.JSONObject jsonBoard)
Set this board based on the parameter. |
org.json.simple.JSONObject |
toJSONObject()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int NO_SPOT
public static final int NO_SIDE
public static final int MAX_SPOT_COORDINATE
public static final int AXIS_A
public static final int AXIS_B
public static final int ROW_SPOT_0
public static final int ROW_SPOT_1
public static final int ROW_SPOT_2
public static final int N_ROWS
public static final int N_SPOTS
public static final int N_SPOTS_PER_ROW
public static final int N_MEN_PER_SIDE
public static final int N_MAX_MEN_OUT
Method Detail |
---|
public void setFromJSON(org.json.simple.JSONObject jsonBoard)
Board
setFromJSON
in interface Board
public org.json.simple.JSONObject toJSONObject()
toJSONObject
in interface Board
public Board getNewBoard()
Board
getNewBoard
in interface Board
public Move getUndefinedMove()
Board
getUndefinedMove
in interface Board
public Board copy()
Board
copy
in interface Board
public void setFrom(Board board)
Board
board
,
(ignoring move iterator state).
setFrom
in interface Board
board
- the original board to copy.public boolean isSame(Board board)
Board
isSame
in interface Board
public int getActiveSide()
Board
getActiveSide
in interface Board
public int getScore()
Board
Board
's play by finding optimal
weights (as with genetic algorithms) for getScore's criteria.
Humans surpass computers in performance of this method.
getScore
in interface Board
public int getGoodEnoughScore(int plannedScore, int levelOfPlay)
Board
Game
engine optimizes by pruning move search tree
branches using this score. The returned score should be just above
what is probable based on plannedScore
for optimal performance. Towards the end game
the returned score should be far higher than what is probable.
levelOfPlay
is optionally
used to set expectations for what is good enough.
getGoodEnoughScore
in interface Board
plannedScore
- expectations based on a previous search.levelOfPlay
- level of play requested by the Game engine.
plannedScore
.public int getRepetitionPenalty(int nRepeats)
Board
nRepeats
times. This encourages
variety of play and draw avoidance at the expense of good
judgment.
getRepetitionPenalty
in interface Board
nRepeats
- the number of times this position has
already occurred during this game.
public Move getFirstMove()
Board
getFirstMove
in interface Board
public Move getNextMove()
Board
getNextMove
in interface Board
public Move getLastMoveExecuted()
Board
getLastMoveExecuted
in interface Board
public void go(Move mv)
Board
go
in interface Board
Board.getFirstMove()
,
Board.getNextMove()
public int getAlteredLevelOfPlay(int level)
Board
Game
engine should look ahead.
Each turn has one move and possibly several "go again" moves,
so the number of moves looked ahead may exceed the level of play.
Even though the game engine may request a certain level
of play, getAlteredLevelOfPlay()
may arbitrarily override
it at various stages of the game for performance reasons.
getAlteredLevelOfPlay
in interface Board
level
- the level of play requested.
public boolean isWon(int score)
Board
isWon
in interface Board
public int getProgress()
Board
getGoodEnoughScore
may subvert this method by pruning (and thus ignoring)
moves which conclude the game sooner.
getProgress
in interface Board
public int getEmptyNeighborCount(int spot)
public static java.lang.String getPositionText(int spot)
getMove(String positionText)
public static MillMove getMove(java.lang.String positionText)
positionText
- text notation describing a move.
Position text is of the form {square}{point}[{square}{point}] where:
{square} is X, Y or Z starting with the outermost square and
{point} is 1,2...8 starting at the upper left and going clockwise.
public boolean isGameOver()
public boolean isWon()
public int getMenLeft()
public int getMenLeft(int side)
public int getSpotSide(int spot)
spot
- 0 based index of the given board spot.
N_SPOTS
public int getSpotSide(java.lang.String positionText)
positionText
- text notation describing a spot.
getMove(String positionText)
public static int getSpot(java.lang.String positionText)
positionText
- text notation describing a spot.
positionText
is invalid.getMove(String positionText)
public static int getSpotCoordinate(int spot, int axis)
spot
- 0 based index identifying a spot on the board.axis
- AXIS_A
or AXIS_B
.
N_SPOTS
,
AXIS_A
,
AXIS_B
public static int getSpotCoordinate(int row, int spot, int axis)
row
- 0 based index identifying a row of 3 spots.spot
- one of ROW_SPOT_0
,
ROW_SPOT_1
,
ROW_SPOT_2
.axis
- AXIS_A
or AXIS_B
.
getSpotCoordinate(int spot, int axis)
,
N_ROWS
,
ROW_SPOT_0
,
ROW_SPOT_1
,
ROW_SPOT_2
,
AXIS_A
,
AXIS_B
public static int getSpot(int coordinateA, int coordinateB)
coordinateA
- coordinate on the board A axis.coordinateB
- coordinate on the board B axis.
public boolean isValidMove(MillMove move)
public boolean isTaking()
public boolean isTakingAny()
public boolean isTranslating()
public boolean isPlacing()
public boolean isSliding()
public boolean isFlying()
public int getMenOut(int side)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |