|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.game.AbstractGame
com.antelmann.game.puzzle.TilePuzzle
public class TilePuzzle
implements a very flexible tile puzzle game with various options
TilePuzzleSamples,
TilePuzzlePlayer,
Serialized Form| Constructor Summary | |
|---|---|
TilePuzzle()
uses TilePuzzleSamples.getNumberPuzzle(3) to initialize the puzzle |
|
TilePuzzle(String name,
Object[][] puzzle)
When constructed, the puzzle's current state equals its solution. |
|
TilePuzzle(String name,
Object[][] scrampledPuzzle,
Object[][] destinationPuzzle)
If you want to set the initial state different from the solution puzzle by hand, this is the constructor to do it; be careful that the conventions (see TilePuzzle (String name, Object[][] puzzle)) for the puzzle are maintained for both given object arrays; also, both arrays must have the same dimensions and should contain the same objects. |
|
| Method Summary | |
|---|---|
Object |
clone()
Any inheriting class with non-primitive members must override this clone() method to provide a full deep copy of the object, which is essential for spawnChild() to work correctly. |
boolean |
equals(Object obj)
|
Object[][] |
getPuzzleMatrix()
|
double |
getResult(int playerRole)
a default implementation for convenience which may suit most games that do not involve betting or any form of measuring how 'big' the win was. |
Object[][] |
getSolutionMatrix()
|
int[] |
getWinner()
getWinner() returns an array of all winning game roles - as there could be more than one winner. |
int |
hashCode()
rather experimental at this point; needs to be tested for efficiency |
boolean |
isEndWhenSolved()
If isEndWhenSolved(), no legal moves are possible anymore once the puzzle is solved or when it has been determined that the game has no solution path. |
boolean |
isReverseMoveDisabled()
If isReverseMoveDisabled(), reverting the game status back to the state it came from (examining the last move) is not a legal move. |
boolean |
isSolved()
checks whether the puzzle state equals the solution and whether it is impossible to reach the goal - which is done by checking whether there are exactly 2 tiles exchanged. |
protected GameMove[] |
listLegalMoves()
listLegalMoves() returns the legal moves for this game. |
int |
nextPlayer()
nextPlayer() returns the integer representing the game role of the next player. |
protected boolean |
popMove()
popMove undoes the last move by altering the game board to the stage before the last move happened. |
protected boolean |
pushMove(GameMove move)
pushMove takes a GameMove and alters the game according to to the move. |
void |
randomize(int numberOfMoves)
|
void |
randomize(int numberOfMoves,
long randomSeed)
|
void |
reset()
|
void |
setEndWhenSolved(boolean enable)
|
void |
setReverseMoveDisabled(boolean enable)
|
void |
shuffle()
|
void |
shuffle(long randomSeed)
note that calling shuffle() may make the puzzle unsolvable |
String |
toString()
overridden to provide useful information about the game |
| Methods inherited from class com.antelmann.game.AbstractGame |
|---|
addObserver, clearRedoList, gameOver, getGameName, getLastMove, getLastPlayer, getLegalMoves, getLegalMoves, getMoveHistory, getNumberOfRedoMoves, getObservers, getRedoList, isLegalMove, isWinner, loadFromFile, makeMove, numberOfMoves, numberOfPlayers, redoMove, removeObserver, resetLegalMoves, resetLists, saveToFile, spawnChild, undoLastMove, undoMoves |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public TilePuzzle()
TilePuzzleSamples
public TilePuzzle(String name,
Object[][] puzzle)
TilePuzzleSamples
public TilePuzzle(String name,
Object[][] scrampledPuzzle,
Object[][] destinationPuzzle)
TilePuzzleSamples| Method Detail |
|---|
public void reset()
public boolean isSolved()
throws PuzzleNotSolvableException
com.antelmann.game.PuzzleNotSolvableException - if the puzzle state cannot reach the solution
PuzzleNotSolvableExceptionpublic void shuffle()
public void shuffle(long randomSeed)
public void randomize(int numberOfMoves)
public void randomize(int numberOfMoves,
long randomSeed)
public Object[][] getSolutionMatrix()
public Object[][] getPuzzleMatrix()
public int[] getWinner()
GamePlay
public double getResult(int playerRole)
AbstractGame
getResult in interface GamePlaygetResult in class AbstractGamepublic int nextPlayer()
GamePlay
protected GameMove[] listLegalMoves()
AbstractGame
listLegalMoves in class AbstractGamepublic void setEndWhenSolved(boolean enable)
isEndWhenSolved()public boolean isEndWhenSolved()
public void setReverseMoveDisabled(boolean enable)
isReverseMoveDisabled()public boolean isReverseMoveDisabled()
protected boolean pushMove(GameMove move)
AbstractGame
pushMove in class AbstractGameprotected boolean popMove()
AbstractGame
popMove in class AbstractGamepublic String toString()
AbstractGame
toString in class AbstractGame
public Object clone()
throws CloneNotSupportedException
AbstractGamespawnChild() to work correctly. Ay overriding
of this method should still begin with a call to
super.clone(), though.
Also, note that this clone() method does not clone the
embedded GameMove objects, i.e. those are expected not to change
(except for their heuristics, which shouldn't affect game
functionality) - or the subclass will have to take care of this.
clone in interface GamePlayclone in class AbstractGameCloneNotSupportedExceptionAbstractGame.spawnChild(GameMove)public boolean equals(Object obj)
equals in class Objectpublic int hashCode()
hashCode in class Object
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||