public class OwareBoard extends java.lang.Object implements Board
Constructor and Description |
---|
OwareBoard()
Instantiates a new
OwareBoard object with the default
position and turn for an oware game. |
OwareBoard(byte[] position,
int turn)
Instantiates a new
OwareBoard object containing the specified
position and turn. |
OwareBoard(long hash)
Instantiates a new
OwareBoard object containing the specified
position and turn identified by a hash code. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj)
Compares this
OwareBoard to the specified object. |
long |
hash()
Returns an unique hash identifier for the current board.
|
int |
hashCode()
Returns a hash code for this board.
|
byte[] |
position()
Returns a copy of the position array stored on the current object
|
static long |
rankPosition(byte[] position)
Given a valid position representation array returns an unique
43 bits identifier for the position.
|
java.lang.String |
toAlgebraic(int move)
Converts a byte representation of a move to its algebraic
representation.
|
java.lang.String |
toAlgebraic(int[] moves)
Converts a byte representation of one or more moves to their
algebraic representation.
|
OwareBoard |
toBoard(Game game)
Converts the current state of an oware game object to a board
representation.
|
OwareBoard |
toBoard(java.lang.String notation)
Converts a board notation to a board object.
|
int |
toMove(java.lang.String notation)
Converts a move form its algebraic notation to a numeric
representation.
|
int[] |
toMoves(java.lang.String notation)
Converts an alphabetic move notation to its byte array moves
representation.
|
java.lang.String |
toNotation()
Converts this board object to its equivalent notation.
|
java.lang.String |
toString()
Returns an human readable string representation of this object.
|
int |
turn()
Returns which player is to move for the board position
|
static byte[] |
unrankPosition(long rank)
Returns a position array parsed from the unique binomial rank
number of the position.
|
public OwareBoard()
OwareBoard
object with the default
position and turn for an oware game.public OwareBoard(long hash)
OwareBoard
object containing the specified
position and turn identified by a hash code. The unique hash
identifier for a board object can be obtained with the method
uniqueHash()
.java.lang.IllegalArgumentException
- if the hash code does not
represent a valid position and turnpublic OwareBoard(byte[] position, int turn)
OwareBoard
object containing the specified
position and turn.
Turn must be either Game.SOUTH
or Game.NORTH
.
A position is represented by a byte array where the array indices
0 to 5 represent the number of seeds on each of the south player
pits, indices 6 to 11 the number of seeds on north player's pits
and indices 12 and 13 are the number of seed captured by each
player.
position
- The position of the boardturn
- The player that is to movejava.lang.IllegalArgumentException
- if the postion
or
turn
parameters are not validpublic byte[] position()
public int turn()
public static long rankPosition(byte[] position)
position
- An array representation of a positionjava.lang.IllegalArgumentException
- if postion is not validpublic static byte[] unrankPosition(long rank)
rankPosition
.public OwareBoard toBoard(Game game)
public OwareBoard toBoard(java.lang.String notation)
A board notation is composed of 14 decimal numbers in the range [0-48] and a letter in the range (S|N) separated by minus signs. The first twelve bytes represent south and north houses from the left most house on south to the right most house on north. The next two bytes represent south and north stores respectively and the letter represents the player to move on the position.
public java.lang.String toNotation()
toNotation
in interface Board
public java.lang.String toAlgebraic(int[] moves)
toAlgebraic
in interface Board
moves
- Moves arrayjava.lang.IllegalArgumentException
- if a move is not validpublic java.lang.String toAlgebraic(int move)
toAlgebraic
in interface Board
move
- A move representationjava.lang.IllegalArgumentException
- if the move is not validpublic int[] toMoves(java.lang.String notation)
public int toMove(java.lang.String notation)
public long hash()
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
OwareBoard
to the specified object. The result
is true
if the argument is not null
and is a
OwareBoard
object that represents the same position and turn
as this object.equals
in class java.lang.Object
obj
- The object to compare with this OwareBoard
null
if the object represents the same board
as this OwareBoard
object. false
otherwise