|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.ObjectTronState
public class TronState
This represents the state of the Tron board. April 2010
| Constructor Summary | |
|---|---|
TronState(int dim)
Constructor that initializes the board of size (dim x dim) to being unplayed (i.e., each cell should be empty.) |
|
TronState(TronState otherState)
Copy Constructor - does deep copy. |
|
| Method Summary | |
|---|---|
java.lang.Object |
clone()
Returns a duplicate of this state |
java.lang.String |
dump()
Generates and returns a multi-line string representing a human-readable pretty version of the board. |
boolean |
equals(TronStateInterface otherState)
Determines if the specified instance TronState has the same contents as this instance. |
int[][] |
getBoard()
Returns a copy of the array representing the board of the game. |
Cell |
getHead(int playerNum)
Returns the head for the specified player |
java.util.ArrayList<TronObstacle> |
getObstacles()
Returns the obstacles in this board. |
boolean |
rectContainsPoint(int x,
int y,
int width,
int height,
Cell pt)
|
void |
setCell(int row,
int col,
int value)
Sets the specified cell of the board to the specified value. |
void |
setHead(int playerNum,
Cell head)
Sets the head for the specified player |
java.lang.String |
toString()
Generates and returns a single line string that must contain exactly (dim*dim) string representations of integers separated by commas (with no spaces), where dim is the dimension of the board. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public TronState(int dim)
dim - the dimensions of each side of the square boardpublic TronState(TronState otherState)
otherState - the state to copy| Method Detail |
|---|
public java.lang.Object clone()
clone in interface game.GameStateclone in class java.lang.Objectpublic boolean equals(TronStateInterface otherState)
otherState - The other instance to check equality with
public int[][] getBoard()
Note that the board contains only an indication of where players have been. It does not contain the head position of the players, nor does it contain the obstacles. Your program will have to use all three elements of the state to create a correct solution.
getBoard in interface TronStateInterfacegetHead,
getObstacles
public void setCell(int row,
int col,
int value)
setCell in interface TronStateInterfacerow - is row of the cell to setcol - is column of the cell to setvalue - is new value of the cellpublic Cell getHead(int playerNum)
getHead in interface TronStateInterfaceplayerNum - the player number to get the head row of (always 0 or 1)
public void setHead(int playerNum,
Cell head)
setHead in interface TronStateInterfaceplayerNum - the player number to get the head column of (always 0 or 1)head - the position of the headpublic java.util.ArrayList<TronObstacle> getObstacles()
getObstacles in interface TronStateInterfaceTronObstacle
public boolean rectContainsPoint(int x,
int y,
int width,
int height,
Cell pt)
public java.lang.String dump()
The string must have multiple lines separated by '\n'. There must be one line per row of the board, and each line must have exactly the same number characters as the width of the board. In other words, the string should be display as a grid of characters, one per cell in the board. The characters should be:
Unlike in the previous project, you do not have any flexibility in what this method generates - it must create a string exactly as described above.
dump in interface game.GameStatepublic java.lang.String toString()
A simple example would be as follows for a 4x4 board with one obstacle in the lower-left, and two short traces ending in heads in the upper-left and upper-right corners, respectively: "-2,-1,-1,-2,0,-1,-1,1,0,-1,-1,1,-3,-1,-1,-1".
Note that toString() is used by the tournament engine, so it won't have any impact anywhere except there (and in the release tests.)
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||