Package rushhour.model
Class BoardState
java.lang.Object
rushhour.model.BoardState
public class BoardState extends Object
Model of one state of the Rushhour board.
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_BOARD_SIZE
The default size of the board, for when we do not specify it otherwise.static int
DEFAULT_OUR_DEFAULT_LENGTH
The default length of the family car.static int
DEFAULT_OUR_ROW
The default row one which the family car should live. -
Method Summary
Modifier and Type Method Description String
boardString()
Return a string with the states of the board squares, for lazy hashing of boards.boolean
checkSolution(ArrayList<Move> moves)
Check whether a particular series of moves is a correct solution from this position.boolean
equals(Object o)
Checks that two boards have the same cars in the same places.boolean
filledAt(int row, int col)
Returns whether the board has a filled space at a particular row or columnint
getBoardSize()
Returns the size of this (square) board.Iterable<Move>
getValidMoves()
Returns a container from which the valid moves at this position may be iterated.int
hashCode()
Output representations are unique enough, so just build and return its hash code.boolean
isGoalState()
Checks whether this state solves the puzzle by allowing the family car to escape.int
placed()
Returns the number of cars placed on the board.PlacedCar
placement(int i)
Returns the placement of a particular car.String
toString()
String
toString(String indentation)
Returns the string representation, with a given indentation.void
toString(StringBuilder sb)
Helper method fortoString()
using a threadedStringBuilder
.void
toString(StringBuilder sb, String ind)
Full helper method fortoString()
.
-
Field Details
-
DEFAULT_BOARD_SIZE
public static final int DEFAULT_BOARD_SIZEThe default size of the board, for when we do not specify it otherwise.- See Also:
- Constant Field Values
-
DEFAULT_OUR_ROW
public static final int DEFAULT_OUR_ROWThe default row one which the family car should live.- See Also:
- Constant Field Values
-
DEFAULT_OUR_DEFAULT_LENGTH
public static final int DEFAULT_OUR_DEFAULT_LENGTHThe default length of the family car.- See Also:
- Constant Field Values
-
-
Method Details
-
isGoalState
public boolean isGoalState()Checks whether this state solves the puzzle by allowing the family car to escape. -
getBoardSize
public int getBoardSize()Returns the size of this (square) board. -
placed
public int placed()Returns the number of cars placed on the board. -
placement
Returns the placement of a particular car.- Parameters:
i
- The index of the car, from 0 up to but not includingplaced()
- Returns:
- The placement record for that car index
-
filledAt
public boolean filledAt(int row, int col)Returns whether the board has a filled space at a particular row or column- Parameters:
row
- The row number of the position. Valid values are from 0 up to (but including)getBoardSize()
.col
- The column number of the position. Valid values are from 0 up to (but including)getBoardSize()
.
-
getValidMoves
Returns a container from which the valid moves at this position may be iterated. -
checkSolution
Check whether a particular series of moves is a correct solution from this position.- Parameters:
moves
- The sequence ofMove
s to check- Returns:
- true for a correct series of moves. There is no
distinction between a series of moves which leads to a
non-solution, and a sequence containing an illegal move, in this
method result; the body of this method catches
MoveException
s. Of course, other exceptions will propagate out.
-
toString
-
toString
Returns the string representation, with a given indentation. -
toString
Helper method fortoString()
using a threadedStringBuilder
. Just relays to the all-parameters call. -
toString
Full helper method fortoString()
. Since output goes to aStringBuilder
, there is no need for a result.- Parameters:
sb
- TheStringBuilder
to which output should be written.ind
- The current indentation
-
equals
Checks that two boards have the same cars in the same places. -
hashCode
public int hashCode()Output representations are unique enough, so just build and return its hash code. -
boardString
Return a string with the states of the board squares, for lazy hashing of boards.
-