Class BoardState

java.lang.Object
rushhour.model.BoardState

public class BoardState
extends Object
Model of one state of the Rushhour board.
  • Field Details

  • 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

      public PlacedCar placement​(int i)
      Returns the placement of a particular car.
      Parameters:
      i - The index of the car, from 0 up to but not including placed()
      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

      public Iterable<Move> getValidMoves()
      Returns a container from which the valid moves at this position may be iterated.
    • checkSolution

      public boolean checkSolution​(ArrayList<Move> moves)
      Check whether a particular series of moves is a correct solution from this position.
      Parameters:
      moves - The sequence of Moves 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 MoveExceptions. Of course, other exceptions will propagate out.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString​(String indentation)
      Returns the string representation, with a given indentation.
    • toString

      public void toString​(StringBuilder sb)
      Helper method for toString() using a threaded StringBuilder. Just relays to the all-parameters call.
    • toString

      public void toString​(StringBuilder sb, String ind)
      Full helper method for toString(). Since output goes to a StringBuilder, there is no need for a result.
      Parameters:
      sb - The StringBuilder to which output should be written.
      ind - The current indentation
    • equals

      public boolean equals​(Object o)
      Checks that two boards have the same cars in the same places.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Output representations are unique enough, so just build and return its hash code.
      Overrides:
      hashCode in class Object
    • boardString

      public String boardString()
      Return a string with the states of the board squares, for lazy hashing of boards.