Package at.jku.ssw.fp.sect04_3.puzzle
Class Puzzle
- java.lang.Object
-
- at.jku.ssw.fp.sect04_3.puzzle.Puzzle
-
public final class Puzzle extends Object
State in a puzzle game.- Author:
- Herbert Praehofer
-
-
Field Summary
Fields Modifier and Type Field Description private int[][]
field
private List<Move>
moves
static int
N
Size of the puzzle board(package private) static int[]
NUMBERS
Array representing solution(package private) static Random
RAND
A random number generatorstatic Puzzle
SOLUTION
Solution stateprivate List<Puzzle>
states
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
assess()
Computes a difference of this state to the solution state.Puzzle
doMove(Move move)
Executes a next move.private boolean
equalFieds(int[][] f1, int[][] f2)
boolean
equals(Object obj)
static Puzzle
from(int... numbers)
Creates a puzzle state from sequence of numbers.private int
get(int i, int j)
int
get(Pos pos)
Gets the number at the current position.Pos
getEmptyPos()
Gets the position which is empty.List<Move>
getMoveHistory()
Gets the list of moves taken to get to this state.List<Move>
getNextMoves()
Gets the moves possible from this state.List<Puzzle>
getNextStates()
Returns a list of possible successor statesList<Integer>
getNumbers()
Returns the sequence of numbers in a list.List<Puzzle>
getStateHistory()
Gets the list of states to this state.int
hashCode()
boolean
isSolution()
Tests if this puzzle state represents the solution state.void
print(PrintStream out)
static Puzzle
shuffled()
Creates a random puzzle state.String
toString()
-
-
-
Field Detail
-
N
public static final int N
Size of the puzzle board- See Also:
- Constant Field Values
-
RAND
static final Random RAND
A random number generator
-
NUMBERS
static final int[] NUMBERS
Array representing solution
-
SOLUTION
public static final Puzzle SOLUTION
Solution state
-
field
private final int[][] field
-
-
Method Detail
-
shuffled
public static Puzzle shuffled()
Creates a random puzzle state.- Returns:
- a randomly set puzzle state
-
from
public static Puzzle from(int... numbers)
Creates a puzzle state from sequence of numbers.- Parameters:
numbers
- the sequence of numbers- Returns:
- the puzzle from the sequence of numbers
-
get
public int get(Pos pos)
Gets the number at the current position.- Parameters:
pos
- current position- Returns:
- the number for the current position
-
isSolution
public boolean isSolution()
Tests if this puzzle state represents the solution state.- Returns:
true
if this represents the solution state
-
getNextStates
public List<Puzzle> getNextStates()
Returns a list of possible successor states- Returns:
- the list of successor states
-
assess
public int assess()
Computes a difference of this state to the solution state.- Returns:
- the difference to the solution state
-
getEmptyPos
public Pos getEmptyPos()
Gets the position which is empty.- Returns:
- the empty position
-
getNumbers
public List<Integer> getNumbers()
Returns the sequence of numbers in a list.- Returns:
- the sequence of numbers
-
getMoveHistory
public List<Move> getMoveHistory()
Gets the list of moves taken to get to this state.- Returns:
- a list of moves taken to get to this state
-
getStateHistory
public List<Puzzle> getStateHistory()
Gets the list of states to this state.- Returns:
- a list of states to this state
-
getNextMoves
public List<Move> getNextMoves()
Gets the moves possible from this state.- Returns:
- the list of possible moves
-
doMove
public Puzzle doMove(Move move)
Executes a next move.- Parameters:
move
- the move- Returns:
- the next puzzle state
-
print
public void print(PrintStream out)
-
equalFieds
private boolean equalFieds(int[][] f1, int[][] f2)
-
get
private int get(int i, int j)
-
-