studentacct.mancala
Class MancalaState

java.lang.Object
  extended by studentacct.mancala.MancalaState
All Implemented Interfaces:
game.GameState, MancalaStateInterface

public class MancalaState
extends java.lang.Object
implements game.GameState, MancalaStateInterface

This represents the state of the Mancala board and this class is written by the student.

Author:

Constructor Summary
MancalaState()
          Default constructor.
MancalaState(int[] board)
          Constructor that sets the state of the board to a copy of the specified board.
 
Method Summary
 java.lang.Object clone()
          Returns a new MancalaState object whose contents is exactly the same as this instance.
 java.lang.String dump()
          Generates and returns a multi-line string representing a human-readable pretty version of the board.
 boolean equals(java.lang.Object state)
          Determines if the specified instance MancalaState has the same contents as this instance.
 int[] getBoard()
          Returns a reference to the array storing the board state.
 java.lang.String toString()
          Generates and returns a single line string that must contain exactly 14 integers separated by commas (with no spaces).
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MancalaState

public MancalaState()
Default constructor. This should initialize the entire board to being unplayed (i.e., each cell should hold no pieces.)


MancalaState

public MancalaState(int[] board)
Constructor that sets the state of the board to a copy of the specified board. Note that you must not store a reference to the board that is passed in. Instead, you must allocate a new array and copy the contents from the parameter.

Parameters:
board - the board to copy
Method Detail

clone

public java.lang.Object clone()
Returns a new MancalaState object whose contents is exactly the same as this instance. Do not use Java's clone() method in the implementation of this method. Rather, just use your existing constructors and copy whatever state needs to be copied.

Specified by:
clone in interface game.GameState
Overrides:
clone in class java.lang.Object
Returns:
the new instance of MancalaState

equals

public boolean equals(java.lang.Object state)
Determines if the specified instance MancalaState has the same contents as this instance.

Overrides:
equals in class java.lang.Object
Parameters:
state - The other instance to check equality with
Returns:
true if the specified parameter is equal to this, or false otherwise

getBoard

public int[] getBoard()
Returns a reference to the array storing the board state.

Specified by:
getBoard in interface MancalaStateInterface
Returns:
the board

dump

public java.lang.String dump()
Generates and returns a multi-line string representing a human-readable pretty version of the board. This is like toString() in that it should return a String that represents the board. But while toString() has a very specific pre-defined single-line format, dump() can return a multi-line String in any format you wish. When you run the driver to test your game, this dump() method will be called to display the state of the game after each move, and so you should generate a string that will make it easy for you to understand the state of the game.

Specified by:
dump in interface game.GameState
Returns:
the string that represents the board

toString

public java.lang.String toString()
Generates and returns a single line string that must contain exactly 14 integers separated by commas (with no spaces). The integers must represent the number of pieces in each pit following the order of the array representing the board's state.

Overrides:
toString in class java.lang.Object


Web Accessibility