public class Board extends Object implements Iterable<Field>
Field
elements.
+-------+-------+-------+-- ... --+-------+ | 1,1 | 1,2 | 1,3 | | 1,C | +-------+-------+-------+-- ... --+-------+ | 2,1 | 2,2 | 2,3 | | 2,C | +-------+-------+-------+-- ... --+-------+ ... ... ... ... +-------+-------+-------+-- ... --+-------+ | R,1 | R,2 | R,3 | | R,C | +-------+-------+-------+-- ... --+-------+with C=
countColumns()
and R=countRows()
.
Iteration and sequential indexing is done row-wise, from left to right and from top to bottom. The sequential index of the upper-left corner is 1.
Board ::= Rows ";" Columns ";" ( Field )+ Field ::= Direction ":" Constraint Rows,Columns ::= positive integer Constraint ::= non-negative integer Direction ::= "N" | "NE" | "E" | "SE" | "S" | "SW" | "W" | "NW"where exactly
height⋅width
many field declarations must be
given.Modifier and Type | Method and Description |
---|---|
void |
colorFields(int[] coloring) |
void |
colorFields(String coloring) |
boolean |
containsCoordinates(int row,
int column)
Check whether the coordinates refer to a field on the board.
|
int |
countColumns()
Get the number of columns on the board, i.e., its width.
|
int |
countRows()
Get the number of rows on the board, i.e., its height.
|
static Board |
fromFile(File file)
Extract a board from the contents of file.
|
static Board |
fromStringDescription(String descr)
Extract a board from a string description.
|
String |
getColoringString()
Gets a string representation of the coloured board.
|
Field |
getField(int row,
int column)
Gets a field on the board
|
List<Field> |
getRegionForField(int row,
int column)
Get the region an arrow points to.
|
int |
getSequentialIndex(Field field)
The sequential index of a field in the board, e.g. for usage as
propositional atom.
|
Iterator<Field> |
iterator()
Get an iterator going over all fields on the board.
|
static String |
readFileAsString(File file)
Read a file into a string.
|
String |
toDescriptionString()
Boards (i.e., signs and constraints, but not colors) can be written to a
file.
|
String |
toString() |
void |
visualise()
Open a new frame and visualize the current board in this frame.
|
public int countColumns()
public int countRows()
public boolean containsCoordinates(int row, int column)
row
- the row coordinatecolumn
- the column coordinaterow ∈ [1, getHeight()]
and col ∈ [1, getWidth()]
.public Field getField(int row, int column)
row
- a row coordinate between 1 and countRows()
column
- a column coordinate between 1 and countColumns()
null
field at (row, column) on this
boardIllegalArgumentException
- if parameters specify a coordinate not on board.public List<Field> getRegionForField(int row, int column)
The region is the list of Field
s to which the arrow in
field
points to. field itself is not included in the
result.
public int getSequentialIndex(Field field)
public Iterator<Field> iterator()
The fields are iterated in the order of sequential indexing: row-wise from left to right, top to bottom.
public void visualise()
public String getColoringString()
For the result the fields are iterated in the order of the fields' sequential index and their colour is represented by a character each: 1 for white, 0 for black and - for uncolored.
null
string representing the coloring of the
board.public void colorFields(String coloring)
public void colorFields(int[] coloring)
public static Board fromStringDescription(String descr) throws SpotlightException
Boards (i.e., signs and constraints, but not colours) can be read from a text description. The format is defined in the above grammar.
descr
- a String describing a board according to the grammardescr
.SpotlightException
- if descr
is not correctly formatted.public static Board fromFile(File file) throws SpotlightException, IOException
file
- the file to read the description fromfile
SpotlightException
- if file
is not correctly formatted.IOException
- if the file does not exist, cannot be opened or readpublic static String readFileAsString(File file) throws IOException
file
- the file to be read, must be readableIOException
- Signals that an I/O exception has occurred.public String toDescriptionString()