edu.rice.comp440.board
Class Board

java.lang.Object
  |
  +--edu.rice.comp440.board.Board

public class Board
extends java.lang.Object


Field Summary
static int BLACK
           
static int[] INITIAL_COLORS
           
static int[] INITIAL_LOCATIONS
           
static int[] INITIAL_NUMBERS
           
static int NEITHER
           
static int NUM_SPIKES
           
static int WHITE
           
 
Constructor Summary
  Board()
          Constructor, build an newly initialzed board
protected Board(Board other)
          Constructor, builds a copy of the given board
 
Method Summary
 boolean equals(java.lang.Object o)
          Public equals
 int getBar(int color)
          Returns the number of pieces on the bar of the given color.
static int getBase(int color)
          Returns the home location of the given color (the location where the color wants to move it's pieces).
 int getBlackBar()
          Returns the number of black pieces on the bar.
 int getBlackOff()
          Returns the number of black pieces beared off
 int getBlackPieces(int location)
          Returns the number of black pieces at the given location.
 int getBlackPips()
          Returns the number of black pips left
 int getColor(int location)
          Returns the color of the pieces at the given location
static int getDirection(int color)
          Returns the direction of the given color (the direction where the color wants to move it's pieces).
 int getOff(int color)
          Returns the number of pieces beared off of the given color.
static int getOtherPlayer(int color)
          Returns the other player
 int getPieces(int location)
          Returns the number of pieces at the given location
 int getPieces(int color, int location)
          Returns the number of pieces at the given location an of the given color.
 int getPips(int color)
          Returns the number of pips for the given color.
 Board getScratch()
          Returns a scratch copy of the board, which is a clone and can be changes without any problems.
 int getWhiteBar()
          Returns the number of white pieces on the bar.
 int getWhiteOff()
          Returns the number of white pieces beared off
 int getWhitePieces(int location)
          Returns the number of black pieces at the given location.
 int getWhitePips()
          Returns the number of white pips left
 int getWinner()
          If the game is over, this returns the winner
protected  int hash(int base, int[] array)
           
 int hashCode()
          Returns the hashCode of this move
static boolean inHomeQuadrant(int location, int color)
          Method which returns whether or not the given spike is in the given player's home square.
protected static boolean isBetween(int location, int a, int b)
          Method which checks to see if the location is between the other two locations.
static boolean isEqual(int[] a, int[] b)
          Utility function to detect equality
 boolean isGameOver()
          Returns whether or not the game is over
 void moveOff(int color)
          Moves a piece off of the given color
 void moveToBar(int color)
          Moves a piece to the bar of the given color
 void moveToLocation(int color, int location)
          Moves a piece to the given location of the given color
static boolean onBoard(int location)
          Internal method which returns whether or not the given location is on the board
 void print(java.io.PrintStream out)
          Prints out a gnubg-style text board.
protected  void print(java.io.PrintStream out, int location, int count)
          Internal method to print a piece and location
 void removeFromBar(int color)
          Removes a piece from the bar of the given color
 void removeFromLocation(int color, int location)
          Removes a piece from the given location of the given color
 void reset()
          Resets the pieces on the board to their initial configurations
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NUM_SPIKES

public static final int NUM_SPIKES

WHITE

public static final int WHITE

BLACK

public static final int BLACK

NEITHER

public static final int NEITHER

INITIAL_LOCATIONS

public static final int[] INITIAL_LOCATIONS

INITIAL_NUMBERS

public static final int[] INITIAL_NUMBERS

INITIAL_COLORS

public static final int[] INITIAL_COLORS
Constructor Detail

Board

public Board()
Constructor, build an newly initialzed board

Board

protected Board(Board other)
Constructor, builds a copy of the given board
Method Detail

equals

public boolean equals(java.lang.Object o)
Public equals
Overrides:
equals in class java.lang.Object
Parameters:
other - To compare to
Returns:
equality

isEqual

public static boolean isEqual(int[] a,
                              int[] b)
Utility function to detect equality
Parameters:
a - The frist array
b - The second array
Returns:
Wtheher they are equal

hashCode

public int hashCode()
Returns the hashCode of this move
Overrides:
hashCode in class java.lang.Object
Returns:
the hasCode of the final board

hash

protected int hash(int base,
                   int[] array)

getScratch

public Board getScratch()
Returns a scratch copy of the board, which is a clone and can be changes without any problems.
Returns:
a scratch copy of this board

getWinner

public int getWinner()
If the game is over, this returns the winner
Returns:
The winner of the game

isGameOver

public boolean isGameOver()
Returns whether or not the game is over
Returns:
Whether or not the game is over

reset

public void reset()
Resets the pieces on the board to their initial configurations

getColor

public int getColor(int location)
Returns the color of the pieces at the given location
Parameters:
location - The location
Returns:
The color of the pieces at the given location (WHITE, BLACK, or NEITHER)

getPieces

public int getPieces(int location)
Returns the number of pieces at the given location
Parameters:
location - The location
Returns:
the number of pieces at the location

getBlackPieces

public int getBlackPieces(int location)
Returns the number of black pieces at the given location. If there are white pieces at the location, returns 0.
Parameters:
location - The location
Returns:
the number of black pieces at the location

getWhitePieces

public int getWhitePieces(int location)
Returns the number of black pieces at the given location. If there are white pieces at the location, returns 0.
Parameters:
location - The location
Returns:
the number of black pieces at the location

getPieces

public int getPieces(int color,
                     int location)
Returns the number of pieces at the given location an of the given color. If there are other color pieces at the location, returns 0.
Parameters:
color - The color
location - The location
Returns:
the number of black pieces at the location

getBlackBar

public int getBlackBar()
Returns the number of black pieces on the bar.
Returns:
the number of black pieces on the bar

getWhiteBar

public int getWhiteBar()
Returns the number of white pieces on the bar.
Returns:
the number of white pieces on the bar

getBar

public int getBar(int color)
Returns the number of pieces on the bar of the given color.
Parameters:
color - The color
Returns:
the number of pieces on the bar

getBlackOff

public int getBlackOff()
Returns the number of black pieces beared off
Returns:
the number of black pieces beared off

getWhiteOff

public int getWhiteOff()
Returns the number of white pieces beared off
Returns:
the number of white pieces on the bar

getOff

public int getOff(int color)
Returns the number of pieces beared off of the given color.
Parameters:
color - The color
Returns:
the number of pieces beared off

getBlackPips

public int getBlackPips()
Returns the number of black pips left
Returns:
the number of black pips left

getWhitePips

public int getWhitePips()
Returns the number of white pips left
Returns:
the number of white pips left

getPips

public int getPips(int color)
Returns the number of pips for the given color.
Parameters:
color - The color
Returns:
the number of pieces beared off

getBase

public static int getBase(int color)
Returns the home location of the given color (the location where the color wants to move it's pieces).
Parameters:
color - The color
Returns:
The base, either 0 or 25

getDirection

public static int getDirection(int color)
Returns the direction of the given color (the direction where the color wants to move it's pieces).
Parameters:
color - The color
Returns:
The direction, either 1 or -1

getOtherPlayer

public static int getOtherPlayer(int color)
Returns the other player
Parameters:
color - The color
Returns:
The other color

onBoard

public static boolean onBoard(int location)
Internal method which returns whether or not the given location is on the board
Parameters:
location - The location to check for
Returns:
Whether or not the locaiton is on the board

moveToLocation

public void moveToLocation(int color,
                           int location)
                    throws IllegalMoveException
Moves a piece to the given location of the given color
Parameters:
color - The color to move
location - The location to move

removeFromLocation

public void removeFromLocation(int color,
                               int location)
                        throws IllegalMoveException
Removes a piece from the given location of the given color
Parameters:
color - The color to remove
location - The location to remove

moveToBar

public void moveToBar(int color)
Moves a piece to the bar of the given color
Parameters:
color - The color to move

removeFromBar

public void removeFromBar(int color)
                   throws IllegalMoveException
Removes a piece from the bar of the given color
Parameters:
color - The color to remove

moveOff

public void moveOff(int color)
Moves a piece off of the given color
Parameters:
color - The color to move

inHomeQuadrant

public static boolean inHomeQuadrant(int location,
                                     int color)
Method which returns whether or not the given spike is in the given player's home square.
Parameters:
location - Th elocation
color - The player
Returns:
Whether or not th elocation is in that player's home sequare

isBetween

protected static boolean isBetween(int location,
                                   int a,
                                   int b)
Method which checks to see if the location is between the other two locations.
Parameters:
location - The location to check
a - The first location
b - The second location

print

public void print(java.io.PrintStream out)
Prints out a gnubg-style text board.
Parameters:
out - The output stream to write the board to

print

protected void print(java.io.PrintStream out,
                     int location,
                     int count)
Internal method to print a piece and location
Parameters:
out - The stream
location - The location
count - The count number