GeneThello Home

net.sf.genethello.applet
Class Board

java.lang.Object
  extended by net.sf.genethello.applet.Board
All Implemented Interfaces:
Board, IBoard

public class Board
extends java.lang.Object
implements Board, IBoard

Implementation of gametheory's Board to simulate an othello board.

Board's index (8x8)

abcdefgh
101234567
289...
...
856......63

Author:
praz

Constructor Summary
Board(boolean network)
          Creates a new instance of Board.
 
Method Summary
 void addMovesUndoDepth(int undogendep)
          Increments depth of undo of valid moves.
 void addSquaresUndoDepth(int undodep)
          Increments depth of undo of board simulation.
 java.lang.String bottomCornerPattern()
          Constructs bottom corner pattern from current board.
 int bottomCornerValue()
          Calculates value of bottom corner pattern for BLACK disc.
 java.lang.String bottomSidePattern()
          Constructs bottom side pattern from current board.
 int bottomSideValue()
          Calculates value of bottom side pattern for BLACK disc.
 int calcPatternValue(int turn)
          Calculates sum of all pattern values for certain color of disc.
 int countCorners(int turn)
          Calculates number of discs in corners for certain color.
static int countEmpty(java.lang.String pat)
          Counts number of empty squares in a pattern.
 int countMobility(int turn)
          Counts mobility for current player.
 int countXsquares(int turn)
          Calculates number of discs in x-squares for certain color.
 int doPut(int idx, int turn)
          Puts new disc and flip opponent's discs if possible.
 int doPut(int col, int row, int turn)
          Puts new disc and flip opponent's discs if possible.
 boolean equals(Board other)
          Checks equality of two boards.
 void generate(int turn)
          Generates valid moves for current player.
 int[] getDiscs()
          Gets number of discs of both colors.
 int getDiscs(int i)
          Gets number of discs.
 int getFlips()
          Gets the last number of flipped discs.
 int[] getMoves()
          Gets array of valid moves.
 int getMoves(int index)
          Gets index'th move from array of valid moves.
 int getMovesUndoDepth()
          Gets depth of undo of valid moves.
 int getSquares(int index)
          Gets value of a square in board.
 int getSquaresUndoDepth()
          Gets depth of undo of board simulation.
 int getTotalDiscs()
          Gets total number of discs.
 long getZobristKey()
          Get Zobrist key, a long number reflecting a board position to be used for faster and more space efficient transposition tables and opening books.
 boolean isUnquiet()
          Unimplemented.
 java.lang.String leftCornerPattern()
          Constructs left corner pattern from current board.
 int leftCornerValue()
          Calculates value of left corner pattern for BLACK disc.
 java.lang.String leftSidePattern()
          Constructs left side pattern from current board.
 int leftSideValue()
          Calculates value of left side pattern for BLACK disc.
 java.lang.String rightCornerPattern()
          Constructs right corner pattern from current board.
 int rightCornerValue()
          Calculates value of right corner pattern for BLACK disc.
 java.lang.String rightSidePattern()
          Constructs right side pattern from current board.
 int rightSideValue()
          Calculates value of right side pattern for BLACK disc.
 void setSquares(int index, int disc)
          Sets value of a square in board.
 void setSquaresUndoDepth(int undodep)
          Sets depth of undo of board simulation.
 int[] toIntArray()
          Integer array representation of board.
 java.lang.String topCornerPattern()
          Constructs top corner pattern from current board.
 int topCornerValue()
          Calculates value of top corner pattern for BLACK disc.
 java.lang.String topSidePattern()
          Constructs top side pattern from current board.
 int topSideValue()
          Calculates value of top side pattern for BLACK disc.
 java.lang.String toString()
          String representation of board.
 void undoGenerate()
          Undoes the last Generate().
 void undoPut()
          Undoes the last doPut().
 void updateZobristKeyOnTurn(int turn)
          Updates zobrist key when turn changes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Board

public Board(boolean network)
Creates a new instance of Board.

Parameters:
network - true if using network, or not otherwise
Method Detail

getZobristKey

public long getZobristKey()
Get Zobrist key, a long number reflecting a board position to be used for faster and more space efficient transposition tables and opening books.

Specified by:
getZobristKey in interface Board
Returns:
Zobrist key

isUnquiet

public boolean isUnquiet()
Unimplemented.

Specified by:
isUnquiet in interface Board
Returns:
false

getSquares

public int getSquares(int index)
Gets value of a square in board.

Specified by:
getSquares in interface IBoard
Parameters:
index - board index
Returns:
value

setSquares

public void setSquares(int index,
                       int disc)
Sets value of a square in board.

Parameters:
index - board index
disc - value

doPut

public int doPut(int col,
                 int row,
                 int turn)
Puts new disc and flip opponent's discs if possible. Flips in 8 directions: Up, UpRight, Right, DownRight, Down, DownLeft, Left and UpLeft. Starting from new disc it checks for opponent discs until own disc is found, then go back flipping those opponent discs. Doesn't put new disc if there is no opponent disc can be flipped.

Parameters:
col - New disc's column (0- 7).
row - New disc's row (0 - 7).
turn - New disc's turn (BLACK or WHITE).
Returns:
Number of flipped discs.

doPut

public int doPut(int idx,
                 int turn)
Puts new disc and flip opponent's discs if possible. Flips in 8 directions: Up, UpRight, Right, DownRight, Down, DownLeft, Left and UpLeft. Starting from new disc it checks for opponent discs until own disc is found, then go back flipping those opponent discs. Doesn't put new disc if there is no opponent disc can be flipped.

Specified by:
doPut in interface IBoard
Parameters:
idx - New disc's index (0- 63).
turn - New disc's turn (BLACK or WHITE).
Returns:
Number of flipped discs.

undoPut

public void undoPut()
Undoes the last doPut().

Specified by:
undoPut in interface IBoard

generate

public void generate(int turn)
Generates valid moves for current player. Checks all empty squares each to 8 directions: Up, UpRight, Right, DownRight, Down, DownLeft, Left and UpLeft. Starting from current square it checks for opponent disc until own disc is found. Generated moves could be retrieved using getMoves().

Specified by:
generate in interface IBoard
Parameters:
turn - Current player to generate moves.

undoGenerate

public void undoGenerate()
Undoes the last Generate().

Specified by:
undoGenerate in interface IBoard

getMoves

public int getMoves(int index)
Gets index'th move from array of valid moves.

Specified by:
getMoves in interface IBoard
Parameters:
index - index of move
Returns:
move

getMoves

public int[] getMoves()
Gets array of valid moves.

Returns:
array of valid moves

toString

public java.lang.String toString()
String representation of board.

Overrides:
toString in class java.lang.Object
Returns:
string representation of board

toIntArray

public int[] toIntArray()
Integer array representation of board.

Specified by:
toIntArray in interface IBoard
Returns:
array of integer representing board

getFlips

public int getFlips()
Gets the last number of flipped discs.

Specified by:
getFlips in interface IBoard
Returns:
number of flipped discs

getSquaresUndoDepth

public int getSquaresUndoDepth()
Gets depth of undo of board simulation.

Returns:
undo depth

setSquaresUndoDepth

public void setSquaresUndoDepth(int undodep)
Sets depth of undo of board simulation.

Parameters:
undodep - undo depth

addSquaresUndoDepth

public void addSquaresUndoDepth(int undodep)
Increments depth of undo of board simulation.

Specified by:
addSquaresUndoDepth in interface IBoard
Parameters:
undodep - undo depth to increment

addMovesUndoDepth

public void addMovesUndoDepth(int undogendep)
Increments depth of undo of valid moves.

Specified by:
addMovesUndoDepth in interface IBoard
Parameters:
undogendep - undo depth to increment

getDiscs

public int getDiscs(int i)
Gets number of discs.

Specified by:
getDiscs in interface IBoard
Parameters:
i - color of disc: Constants.BLACK, Constants.WHITE
Returns:
number of discs

getTotalDiscs

public int getTotalDiscs()
Gets total number of discs.

Specified by:
getTotalDiscs in interface IBoard
Returns:
number of discs

getDiscs

public int[] getDiscs()
Gets number of discs of both colors.

Specified by:
getDiscs in interface IBoard
Returns:
number of discs

getMovesUndoDepth

public int getMovesUndoDepth()
Gets depth of undo of valid moves.

Returns:
undo depth

topSidePattern

public java.lang.String topSidePattern()
Constructs top side pattern from current board. Squares: 9:0:1:2:3:4:5:6

Returns:
top side pattern

rightSidePattern

public java.lang.String rightSidePattern()
Constructs right side pattern from current board. Squares: 14:7:15:23:31:39:47:55

Returns:
right side pattern

bottomSidePattern

public java.lang.String bottomSidePattern()
Constructs bottom side pattern from current board. Squares: 54:63:62:61:60:59:58:57

Returns:
bottom side pattern

leftSidePattern

public java.lang.String leftSidePattern()
Constructs left side pattern from current board. Squares: 49:56:48:40:32:24:16:8

Returns:
left side pattern

topCornerPattern

public java.lang.String topCornerPattern()
Constructs top corner pattern from current board. Squares: 0:1:2:8:9:10:16:17

Returns:
top corner pattern

rightCornerPattern

public java.lang.String rightCornerPattern()
Constructs right corner pattern from current board. Squares: 7:15:23:6:14:22:5:13

Returns:
right corner pattern

bottomCornerPattern

public java.lang.String bottomCornerPattern()
Constructs bottom corner pattern from current board. Squares: 63:62:61:55:54:53:47:46

Returns:
bottom corner pattern

leftCornerPattern

public java.lang.String leftCornerPattern()
Constructs left corner pattern from current board. Squares: 56:48:40:57:49:41:58:50

Returns:
left corner pattern

topSideValue

public int topSideValue()
Calculates value of top side pattern for BLACK disc. For WHITE disc the value should be negated.

Returns:
value of top side pattern

rightSideValue

public int rightSideValue()
Calculates value of right side pattern for BLACK disc. For WHITE disc the value should be negated.

Returns:
value of right side pattern

bottomSideValue

public int bottomSideValue()
Calculates value of bottom side pattern for BLACK disc. For WHITE disc the value should be negated.

Returns:
value of bottom side pattern

leftSideValue

public int leftSideValue()
Calculates value of left side pattern for BLACK disc. For WHITE disc the value should be negated.

Returns:
value of left side pattern

topCornerValue

public int topCornerValue()
Calculates value of top corner pattern for BLACK disc. For WHITE disc the value should be negated.

Returns:
value of top corner pattern

rightCornerValue

public int rightCornerValue()
Calculates value of right corner pattern for BLACK disc. For WHITE disc the value should be negated.

Returns:
value of right corner pattern

bottomCornerValue

public int bottomCornerValue()
Calculates value of bottom corner pattern for BLACK disc. For WHITE disc the value should be negated.

Returns:
value of bottom corner pattern

leftCornerValue

public int leftCornerValue()
Calculates value of left corner pattern for BLACK disc. For WHITE disc the value should be negated.

Returns:
value of left corner pattern

countEmpty

public static int countEmpty(java.lang.String pat)
Counts number of empty squares in a pattern.

Parameters:
pat - pattern to count
Returns:
number of empty squares

equals

public boolean equals(Board other)
Checks equality of two boards.

Specified by:
equals in interface Board
Parameters:
other - other board to compare
Returns:
true if equal, or false otherwise

countMobility

public int countMobility(int turn)
Counts mobility for current player. Similar to generate() function except doesn't store found moves. Checks all empty squares each to 8 directions: Up, UpRight, Right, DownRight, Down, DownLeft, Left and UpLeft. Starting from current square it checks for opponent disc until own disc is found.

Specified by:
countMobility in interface IBoard
Parameters:
turn - Current player to count.

countCorners

public int countCorners(int turn)
Calculates number of discs in corners for certain color.

Specified by:
countCorners in interface IBoard
Parameters:
turn - color of disc: Constants.BLACK, Constants.WHITE
Returns:
number of discs in corners

countXsquares

public int countXsquares(int turn)
Calculates number of discs in x-squares for certain color.

Specified by:
countXsquares in interface IBoard
Parameters:
turn - color of disc: Constants.BLACK, Constants.WHITE
Returns:
number of discs in x-squares

calcPatternValue

public int calcPatternValue(int turn)
Calculates sum of all pattern values for certain color of disc.

Specified by:
calcPatternValue in interface IBoard
Parameters:
turn - color of disc: Constants.BLACK, Constants.WHITE
Returns:
total pattern value

updateZobristKeyOnTurn

public void updateZobristKeyOnTurn(int turn)
Updates zobrist key when turn changes.

Specified by:
updateZobristKeyOnTurn in interface Board
Parameters:
turn -

GeneThello Home

Get GeneThello: Genetic Othello at SourceForge.net. Fast, secure and Free Open Source software downloads