cs131test.tron
Class TronStateUtil

java.lang.Object
  extended by cs131test.tron.TronStateUtil

public class TronStateUtil
extends java.lang.Object

A sample solution of the state utilities. April 2010

Author:
Ben Bederson

Constructor Summary
TronStateUtil()
           
 
Method Summary
static java.lang.String dump(TronStateInterface state)
          Generates and returns a multi-line string representing a human-readable pretty version of the board.
static java.lang.String toString(TronStateInterface state)
          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, toString, wait, wait, wait
 

Constructor Detail

TronStateUtil

public TronStateUtil()
Method Detail

dump

public static java.lang.String dump(TronStateInterface state)
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() generates a single line in a format more easily understandable by computers, this string contains multiple lines designed to be readable by humans. In particular, the textual driver program uses this method to display the game state after each player's move.

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 displayed 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.

Returns:
the string that represents the board

toString

public static java.lang.String toString(TronStateInterface state)
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. The integers must represent the cells of the board in natural grid order, one row at a time starting at the top, with each row going from left to right. The values you should use in this string are as follow. Empty cells must converted into TronConstants.STATE_EMPTY, head cells must be converted into TronConstants.STATE_HEAD, obstacles must be converted into TronConstants.STATE_OBSTACLE, and other spaces must be converted into the player number in that cell.

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.)



Web Accessibility