Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

antichess
Class Board  view Board download Board.java

java.lang.Object
  extended byantichess.Board

public class Board
extends java.lang.Object

Board represents an antichess board. Board is mutable.

The topology of the board could vary and is supplied as an argument


Field Summary
private  int[][] aliveCount
           
private  int boardType
           
private  boolean[] checked
           
static int CYLINDER
          Constant indicating a cylinder board
static int FOURPLAYERS
          Constant indicate a four player board
private  Piece[][] gameBoard
           
private  Piece[][] lastPieceMoved
           
static int MAXCOL
          Constant which holds the biggest possible row
(package private) static int maxLastPieceMoved
           
static int MAXROW
          Constant which holds the biggest possible row
static int MINCOL
          Constant which holds the smallest possible row
static int MINROW
          Constant which holds the smallest possible row
static int NUMCOLS
          Constant which holds the number of columns on the board = MAXCOL-MINCOL+1
private  Piece[][][] pieceArray
           
private  int[][] pieceCount
           
static int REGULAR
          Constant indicating a regular board (default)
private  boolean[] special
           
private  int[][] topology
           
private  Zobrist zobrist
           
 
Constructor Summary
Board(Board b)
          Creates a copy of a given board, deep copying every piece
Board(int[][] topology)
          Creates an MAXCOLxMAXROW antichess board.
 
Method Summary
 boolean equals(Board other)
          Checks for equality.
 boolean equals(java.lang.Object o)
          Checks for equality.
 int getAliveCount(int side, int piece)
          Gets the weighted count of alive pieces on the board during any time in the game for a particular side.
 int getBoardType()
          Gets the board type
 boolean getChecked(int side)
          Checks if a side is in check
 int getDifference(int side)
          Gets the weighted difference of number of alive pieces on the board during any time in the game for a particular side.
 Piece getKing(int color)
          Gets the king Piece of a particular side
 Piece getLastPieceMoved(int color)
          Gets the last piece move to a piece
 Piece getLastPieceMoved(int color, int index)
          Gets the last piece move to a piece at an index
 Piece getPieceAt(int col, int row)
          Gets a piece at a particular row and column.
 int getPieceCount(int side, int piece)
          Gets the number of maximum available pieces on the board during any time in the game for a particular side.
 Piece[][] getPiecesOnBoard(int side)
          Gets an array of Piece that are present on the board.
 boolean getSpecial(int side)
          Checks if a side has used special move
 int getTotalAliveCount(int side)
          Gets the weighted count of alive pieces on the board during any time in the game for a particular side.
 boolean getUsable(int col, int row)
          Gets whether given location is usable
 Zobrist getZobrist()
          Returns the zobrist
 int[] hashStr()
          SPECIFIC TO 8x8 Boards.
 void initZobrist()
          Initializes the zobrist matrix for this board CALL THIS ONLY AFTER YOU PUT ALL THE PIECES INTO THE BOARD
 boolean isLastPieceMoved(Piece p)
          Checks if a piece is the last piece moved
 void registerPiece(int col, int row, Piece piece)
          Registers a piece to the board at (col,row)
 void setBoardType(int type)
          Sets the board type
 void setChecked(int side, boolean inCheck)
          Sets a side to be in check or not to be in check
 void setLastPieceMoved(Piece p)
          Sets the last piece moved
 void setLastPieceMoved(Piece p, int color)
          Sets the last piece move to a piece
 void setLastPieceMoved(Piece p, int color, int index)
          Sets the last piece move to a piece
 void setLastPieceMoved(Piece p1, Piece p2, int color)
          Sets the last pieces moved
 void setPieceAt(int col, int row, Piece p)
          Modify a Piece at a location
 void setSpecial(int side, boolean usedSpecial)
          Sets whether a side has used special move
 java.lang.String toString()
          Returns a string representation of the board
 long zobristCode(int nextTurn)
          Returns a hashCode for this board Currently uses Zobrist.getKey()
 long zobristCode(java.lang.String boardStr, int nextTurn)
          Returns a hashCode for this board Currently uses Zobrist.getKey()
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

gameBoard

private Piece[][] gameBoard

pieceArray

private Piece[][][] pieceArray

lastPieceMoved

private Piece[][] lastPieceMoved

maxLastPieceMoved

static int maxLastPieceMoved

pieceCount

private int[][] pieceCount

aliveCount

private int[][] aliveCount

checked

private boolean[] checked

special

private boolean[] special

topology

private int[][] topology

boardType

private int boardType

zobrist

private Zobrist zobrist

REGULAR

public static int REGULAR
Constant indicating a regular board (default)


CYLINDER

public static int CYLINDER
Constant indicating a cylinder board


FOURPLAYERS

public static int FOURPLAYERS
Constant indicate a four player board


NUMCOLS

public static int NUMCOLS
Constant which holds the number of columns on the board = MAXCOL-MINCOL+1


MINROW

public static int MINROW
Constant which holds the smallest possible row


MAXROW

public static int MAXROW
Constant which holds the biggest possible row


MINCOL

public static int MINCOL
Constant which holds the smallest possible row


MAXCOL

public static int MAXCOL
Constant which holds the biggest possible row

Constructor Detail

Board

public Board(int[][] topology)
Creates an MAXCOLxMAXROW antichess board. The topology of the board is supplied as an argument of two dimensional integer array.if topology[i][j]!=0 then, that square is unusable. For topology[i][j]==1, the square is a usable one.

The constructor initialized checked and special to false. pieceCount and aliveCount is initialized to 0 for all peices for both sides.


Board

public Board(Board b)
Creates a copy of a given board, deep copying every piece

Method Detail

hashStr

public int[] hashStr()
SPECIFIC TO 8x8 Boards. Returns a int[] representation of the board to be used in a hashtable very specific to 8x8 board, starting from row0 and col0 It allocates 5bits per square, HasMoved[1bit]+Color[1bit]+PieceType[3bits] It gives an array of 12 ints. 5*6=30, so puts 6 pieces at most into an integer and does not use the first 2 bits of 32bits.

There are 64 squares, so we need 11 integers, the 12th integer keeps track of the last piece moved. Col[3bits] + Row[3bits] (starting from low order bits)

The structure is so

 integer [1]:  2 bits:empty + 5 bits: square6  + 5 bits: square5  + 5 bits: square4  + .. + 5 bits: square1  
integer [2]: 2 bits:empty + 5 bits: square12 + 5 bits: square11 + 5 bits: square10 + .. + 5 bits: square7
...
integer[11]: 2 bits:empty + 5 bits: empty + 5 bits: empty + 5 bits: square64 + .. + 5 bits: square61
integer[12]: 20bits:empty + 3 bits: blackCol + 3 bits: blackRow + 3 bits: whiteCol + 3bits: whiteRow


zobristCode

public long zobristCode(int nextTurn)
Returns a hashCode for this board Currently uses Zobrist.getKey()


zobristCode

public long zobristCode(java.lang.String boardStr,
                        int nextTurn)
Returns a hashCode for this board Currently uses Zobrist.getKey()


getBoardType

public int getBoardType()
Gets the board type


getPieceCount

public int getPieceCount(int side,
                         int piece)
Gets the number of maximum available pieces on the board during any time in the game for a particular side.


getDifference

public int getDifference(int side)
Gets the weighted difference of number of alive pieces on the board during any time in the game for a particular side.


getAliveCount

public int getAliveCount(int side,
                         int piece)
Gets the weighted count of alive pieces on the board during any time in the game for a particular side.


getTotalAliveCount

public int getTotalAliveCount(int side)
Gets the weighted count of alive pieces on the board during any time in the game for a particular side.


getChecked

public boolean getChecked(int side)
Checks if a side is in check


getKing

public Piece getKing(int color)
Gets the king Piece of a particular side


getSpecial

public boolean getSpecial(int side)
Checks if a side has used special move


getPieceAt

public Piece getPieceAt(int col,
                        int row)
Gets a piece at a particular row and column.


getPiecesOnBoard

public Piece[][] getPiecesOnBoard(int side)
Gets an array of Piece that are present on the board. This array contains only Pieces that are on the board.


getLastPieceMoved

public Piece getLastPieceMoved(int color)
Gets the last piece move to a piece


getLastPieceMoved

public Piece getLastPieceMoved(int color,
                               int index)
Gets the last piece move to a piece at an index


isLastPieceMoved

public boolean isLastPieceMoved(Piece p)
Checks if a piece is the last piece moved


getUsable

public boolean getUsable(int col,
                         int row)
Gets whether given location is usable


toString

public java.lang.String toString()
Returns a string representation of the board


getZobrist

public Zobrist getZobrist()
Returns the zobrist


setBoardType

public void setBoardType(int type)
Sets the board type


setChecked

public void setChecked(int side,
                       boolean inCheck)
Sets a side to be in check or not to be in check


setSpecial

public void setSpecial(int side,
                       boolean usedSpecial)
Sets whether a side has used special move


setPieceAt

public void setPieceAt(int col,
                       int row,
                       Piece p)
Modify a Piece at a location


setLastPieceMoved

public void setLastPieceMoved(Piece p)
Sets the last piece moved


setLastPieceMoved

public void setLastPieceMoved(Piece p1,
                              Piece p2,
                              int color)
Sets the last pieces moved


setLastPieceMoved

public void setLastPieceMoved(Piece p,
                              int color)
Sets the last piece move to a piece


setLastPieceMoved

public void setLastPieceMoved(Piece p,
                              int color,
                              int index)
Sets the last piece move to a piece


equals

public boolean equals(java.lang.Object o)
Checks for equality.
Overrides Object.equals


equals

public boolean equals(Board other)
Checks for equality.
//HALF IMPLEMENTED// Overrides Object.equals


registerPiece

public void registerPiece(int col,
                          int row,
                          Piece piece)
Registers a piece to the board at (col,row)


initZobrist

public void initZobrist()
Initializes the zobrist matrix for this board CALL THIS ONLY AFTER YOU PUT ALL THE PIECES INTO THE BOARD