|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.AbstractSequentialList<E>
java.util.LinkedList
PuzzleState
public class PuzzleState
Yuriy Kozlov
PuzzleState.java -- Final Project
This class represents one state of the puzzle.
There is a virtual environment where the chain of cubes is.
The chain is represented by a linked list of the coordinates [x,y,z] of
the cubes.
| Field Summary |
|---|
| Fields inherited from class java.util.AbstractList |
|---|
modCount |
| Constructor Summary | |
|---|---|
PuzzleState()
Default constructor. |
|
PuzzleState(java.util.Collection c,
short s)
Constructor that takes a puzzle size and an existing set of elements. |
|
PuzzleState(java.util.Collection c,
short s,
PuzzleState prev)
Constructor that takes a puzzle size and an existing set of elements. |
|
PuzzleState(short s)
Constructor that takes a puzzle size. |
|
| Method Summary | |
|---|---|
java.lang.Object |
clone()
Overrides the clone method so that it returns a new state with the same instance fields as "this" state, but whose values can be changed without affecting the parent state. |
short |
depth()
Returns the z-distance between the furthest apart cubes on the z-axis. |
boolean |
equals(java.lang.Object x)
Precondition: x is a PuzzleState Returns true if x is a State object representing the same game state (i.e. |
static PuzzleState |
generateRandom(short s)
Generates a random state of the given size. |
static PuzzleState |
generateSolved(short s)
Generates a (not the, there are different possibilities) solved state of the given size |
PuzzleState |
getPrevious()
Returns the previous state. |
int |
hashCode()
Returns a hash number for the State object, usually obtained by combining the Hash code values of the instance fields in some complicated way (e.g. |
short |
height()
Returns the y-distance between the furthest apart cubes on the y-axis. |
boolean |
isSolution()
Returns true if "this" state is a solution to the puzzle. |
short[] |
minXY()
Returns the lowest [x,y] coordinates in the state. |
short[] |
minXYZ()
Returns the lowest [x,y,z] coordinates in the state. |
short[] |
minXZ()
Returns the lowest [x,z] coordinates in the state. |
static boolean |
myContains(java.util.List lst,
short[] pos)
For SOME reason contains() wouldn't work because short[].equals(short[]) would return false when it should be true, so it is reimplemented here using Arrays.equals |
java.util.LinkedList |
nextMoves()
Returns a LinkedList of the States you can get to in one step from "this" state. |
java.util.LinkedList |
nextMoves2()
Returns a LinkedList of the States you can get to in one step from "this" state. |
short |
puzzleSize()
Returns the puzzle size. |
boolean |
rotate(short angle,
short index,
char dir)
Rotates a cube, returns false if it cannot be rotated to that angle. |
static short |
safeSize()
Returns the SAFESIZE, an extreme limit on the size of the environment. |
void |
setPrevious(PuzzleState prev)
Sets the previous field. |
short[][][] |
to3dArray()
Creates a 3-dimensional array, where the "empty" slots are filled with SAFESIZE and the coordinates where the state is located are labeled by the number of the cube. |
short |
width()
Returns the x-distance between the furthest apart cubes on the x-axis. |
| Methods inherited from class java.util.LinkedList |
|---|
add, add, addAll, addAll, addFirst, addLast, clear, contains, element, get, getFirst, getLast, indexOf, lastIndexOf, listIterator, offer, peek, poll, remove, remove, remove, removeFirst, removeLast, set, size, toArray, toArray |
| Methods inherited from class java.util.AbstractSequentialList |
|---|
iterator |
| Methods inherited from class java.util.AbstractList |
|---|
listIterator, removeRange, subList |
| Methods inherited from class java.util.AbstractCollection |
|---|
containsAll, isEmpty, removeAll, retainAll, toString |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.List |
|---|
containsAll, isEmpty, iterator, listIterator, removeAll, retainAll, subList |
| Constructor Detail |
|---|
public PuzzleState()
public PuzzleState(short s)
s - The size of the puzzle.
public PuzzleState(java.util.Collection c,
short s)
c - A set of elements, each element being an array [x,y,z].s - The size of the puzzle.
public PuzzleState(java.util.Collection c,
short s,
PuzzleState prev)
c - A set of elements, each element being an array [x,y,z].s - The size of the puzzle.prev - The state this state was made from.| Method Detail |
|---|
public short puzzleSize()
public static short safeSize()
public void setPrevious(PuzzleState prev)
prev - The state this state was made from.public PuzzleState getPrevious()
public short[] minXY()
public short[] minXZ()
public short[] minXYZ()
public boolean isSolution()
public short depth()
public short height()
public short width()
public java.lang.Object clone()
clone in class java.util.LinkedListpublic java.util.LinkedList nextMoves()
public java.util.LinkedList nextMoves2()
public boolean rotate(short angle,
short index,
char dir)
angle - The angle to rotate, must be 90, 180, or 270.index - The index at which to start rotating.
This cube is physically rotated, but is virtually
unaffected as it stays in place.dir - The axis of rotation.
public boolean equals(java.lang.Object x)
equals in interface java.util.Collectionequals in interface java.util.Listequals in class java.util.AbstractListx - A state to compare with.
public int hashCode()
hashCode in interface java.util.CollectionhashCode in interface java.util.ListhashCode in class java.util.AbstractListpublic short[][][] to3dArray()
public static PuzzleState generateRandom(short s)
s - A puzzle size.
public static PuzzleState generateSolved(short s)
s - A puzzle size.
public static boolean myContains(java.util.List lst,
short[] pos)
lst - A list to check if pos is in it.pos - An array to search for.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||