|
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.eightpuzzle.EightPuzzleNode
public class EightPuzzleNode
Represents a node in the Eight-Puzzle space.
1 2 3
4 5 6
7 8 x
To experiment with some of the searching algorithms, this class implements the
Comparable interface by simply comparing the char[][] boards.
Note there is a static global variable debug which controls the
way that nodeLabel() computes its string value.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface algs.debug.IGraphEntity |
|---|
IGraphEntity.Formatter |
| Field Summary | |
|---|---|
static boolean |
debug
Since this node is responsible for its formatted output in debugging, we place that localized control here. |
static int |
EmptyMark
Empty Mark. |
static int |
MaxC
Max constant for number of columns. |
static int |
MaxR
Max constant for number of rows. |
| Constructor Summary | |
|---|---|
EightPuzzleNode(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(EightPuzzleNode 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)
Determine is the given (r,c) in the board is empty. |
java.lang.Object |
key()
Return key that satisfies rotational symmetry. |
java.lang.String |
nodeLabel()
Return label to appear within the debugger output. |
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()
Return the data stored with the node. |
java.lang.Object |
storedData(java.lang.Object o)
Store the given piece of information with the node and return the last piece of information which had been stored with the node. |
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
public static boolean debug
| Constructor Detail |
|---|
public EightPuzzleNode(int[][] b)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException| Method Detail |
|---|
public INode copy()
copy in interface INodepublic java.lang.Object key()
Considering the four corners of the board, select the lowest digit and then read off the remaining eight positions in a fixed order as an integer. Return that value.
key in interface INodepublic boolean equivalent(INode n)
equivalent in interface INoden - the state being compared against.public boolean equals(java.lang.Object o)
equals in class java.lang.Objecto - object being compared against.public int hashCode()
hashCode in class java.lang.Objectpublic int score()
If cached value is present, use it instead of evaluating the function again.
score in interface INodepublic void score(int s)
score in interface INodes - designated score for this node.public java.lang.Object storedData(java.lang.Object o)
If null is returned, then no prior information was stored.
storedData in interface INodeo - object to be stored with the node.public java.lang.Object storedData()
storedData in interface INodepublic DoubleLinkedList<IMove> validMoves()
validMoves in interface INode
public int cell(int r,
int c)
r - source location rowc - source location column
public boolean isAdjacentAndEmpty(int fromR,
int fromC,
int toR,
int toC)
fromR - source location rowfromC - source location columntoR - destination location rowtoC - destination location column
public boolean swap(int fromR,
int fromC,
int toR,
int toC)
fromR - source location rowfromC - source location columntoR - destination location rowtoC - destination location column
public boolean isEmpty(int r,
int c)
r - row to be checked.c - column to be checked.public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String nodeLabel()
nodeLabel in interface IGraphEntitypublic int compareTo(EightPuzzleNode n)
based on String representation since we must be careful to ensure that a.compareTo(b) is the opposite of b.compareTo(a).
Needed if, for example, node is ever to appear in a data structure that stores information by comparisons.
compareTo in interface java.lang.Comparable<EightPuzzleNode>n - node with which to compare.
|
Algorithm Development Kit 1.0 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||