Package jadex.web.examples.puzzle
Class Board
- java.lang.Object
-
- jadex.web.examples.puzzle.Board
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
public class Board extends java.lang.Object implements java.io.Serializable, java.lang.Cloneable
The board containing places, pieces and played moves.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Position
hole_pos
The hole position.protected java.util.List<Move>
moves
The moves.PropertyChangeSupport
pcs
The helper object for bean events.protected java.util.Map<Position,Piece>
pieces
The pieces.protected int
size
The size.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list.java.lang.Object
clone()
Clone the board.java.util.List<Piece>
getCurrentPosition()
Get the current board position.Move
getLastMove()
Get all moves made so far.java.util.List<Move>
getMoves()
Get all moves made so far.Piece
getPiece(Position pos)
Get a piece for a location.java.util.List<Move>
getPossibleMoves()
Get possible moves.int
getSize()
Get the board size.boolean
isFreePosition(Position pos)
Test if aposition is free.protected boolean
isPossibleMove(Move move)
Get a piece for a location.boolean
isSolution()
Test if it is a solution.static void
main(java.lang.String[] args)
Main for testing.boolean
move(Move move)
Do a move.void
removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list.boolean
takeback()
Takeback a move.java.lang.String
toString()
Get the string representation.boolean
wasLastMoveWhite()
Test if the last move was with a white piece.
-
-
-
Field Detail
-
moves
protected java.util.List<Move> moves
The moves.
-
size
protected int size
The size.
-
hole_pos
protected Position hole_pos
The hole position.
-
pcs
public PropertyChangeSupport pcs
The helper object for bean events.
-
-
Method Detail
-
getPossibleMoves
public java.util.List<Move> getPossibleMoves()
Get possible moves.- Returns:
- Get all possible move.
-
move
public boolean move(Move move)
Do a move.- Parameters:
move
- The move.
-
takeback
public boolean takeback()
Takeback a move.
-
isSolution
public boolean isSolution()
Test if it is a solution.- Returns:
- True, if solution.
-
getMoves
public java.util.List<Move> getMoves()
Get all moves made so far.
-
getLastMove
public Move getLastMove()
Get all moves made so far.
-
wasLastMoveWhite
public boolean wasLastMoveWhite()
Test if the last move was with a white piece. When no move was made, it return true.- Returns:
- True, is last move was with white piece.
-
isFreePosition
public boolean isFreePosition(Position pos)
Test if aposition is free.
-
isPossibleMove
protected boolean isPossibleMove(Move move)
Get a piece for a location.
-
getSize
public int getSize()
Get the board size.
-
getCurrentPosition
public java.util.List<Piece> getCurrentPosition()
Get the current board position.
-
toString
public java.lang.String toString()
Get the string representation.- Overrides:
toString
in classjava.lang.Object
- Returns:
- The string representation.
-
clone
public java.lang.Object clone()
Clone the board.- Overrides:
clone
in classjava.lang.Object
- Returns:
- The clone.
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list. The listener is registered for all properties.- Parameters:
listener
- The PropertyChangeListener to be added.
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.- Parameters:
listener
- The PropertyChangeListener to be removed.
-
main
public static void main(java.lang.String[] args)
Main for testing.
-
-