|
Algorithm Development Kit 1.0 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectalgs.model.problems.fifteenpuzzle.FifteenPuzzleNode
public class FifteenPuzzleNode
Represents a node in the Fifteen-Puzzle space.
1 2 3 4 5 6 7 8 9101112 131415 *To experiment with some of the searching algorithms, this class implements the Comparable interface by simply comparing the char[][] boards.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface algs.debug.IGraphEntity |
---|
IGraphEntity.Formatter |
Field Summary | |
---|---|
static int |
EmptyMark
Empty Mark. |
static int |
MaxC
|
static int |
MaxR
Max constants |
Constructor Summary | |
---|---|
FifteenPuzzleNode(int[][] b)
Constructor for initiating and copying the state. |
Method Summary | |
---|---|
int |
cell(int r,
int c)
Return contents of cell[r][c]. |
int |
compareTo(FifteenPuzzleNode n)
Offer rudimentary compareTo method by comparing boards. |
INode |
copy()
Return a copy of the game state. |
boolean |
equals(java.lang.Object o)
Determine equals via equivalence of state. |
boolean |
equivalent(INode n)
Determine equivalence of state. |
int |
hashCode()
Define the hashcode to be based on the key() |
boolean |
isAdjacentAndEmpty(int fromR,
int fromC,
int toR,
int toC)
Ensure that the empty square is in [toR][toC] and that [fromR][fromC] is adjacent horizontally or vertical. |
boolean |
isEmpty(int r,
int c)
|
java.lang.Object |
key()
Return key that satisfies rotational symmetry. |
java.lang.String |
nodeLabel()
Return string label for this entity. |
int |
score()
Compute the score function on the board state. |
void |
score(int s)
External agent rates the board and stores the score here. |
java.lang.Object |
storedData()
Retrieve additional specific information stored with this search tree. |
java.lang.Object |
storedData(java.lang.Object o)
Store additional information with this search tree, returning the old information that had been stored (if at all). |
boolean |
swap(int fromR,
int fromC,
int toR,
int toC)
Swap contents of neighboring cells. |
java.lang.String |
toString()
Useful debugging method. |
DoubleLinkedList<IMove> |
validMoves()
Given the game state, return the set of valid moves. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int EmptyMark
public static int MaxR
public static int MaxC
Constructor Detail |
---|
public FifteenPuzzleNode(int[][] b) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
Method Detail |
---|
public INode copy()
copy
in interface INode
public java.lang.Object key()
key
in interface INode
public boolean equivalent(INode n)
equivalent
in interface INode
n
- State in questionpublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public int score()
If cached value is present, use it instead of evaluating the functino again.
score
in interface INode
public void score(int s)
score
in interface INode
public java.lang.Object storedData(java.lang.Object o)
INode
Returns the prior object that had been stored with the node.
storedData
in interface INode
o
- object to store with the INode object.public java.lang.Object storedData()
INode
storedData
in interface INode
public DoubleLinkedList<IMove> validMoves()
validMoves
in interface INode
public int cell(int r, int c)
public boolean isAdjacentAndEmpty(int fromR, int fromC, int toR, int toC)
fromR
- fromC
- toR
- toC
- public boolean swap(int fromR, int fromC, int toR, int toC)
public boolean isEmpty(int r, int c)
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String nodeLabel()
IGraphEntity
nodeLabel
in interface IGraphEntity
public int compareTo(FifteenPuzzleNode n)
based on String representation since we must be careful to ensure that a.compareTo(b) is the opposite of b.compareTo(a).
compareTo
in interface java.lang.Comparable<FifteenPuzzleNode>
|
Algorithm Development Kit 1.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |