org.jscience.computing.game.puzzle
Class Solitaire

java.lang.Object
  extended by org.jscience.computing.game.AbstractGame
      extended by org.jscience.computing.game.puzzle.Solitaire
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, GamePlay

public class Solitaire
extends AbstractGame

A one-player game where the goal is to remove all 'peggs' on the board by jumping over them one by one.

See Also:
Serialized Form

Constructor Summary
Solitaire()
          uses SolitaireSamples.getSolitiare() to initialize the game
Solitaire(java.lang.String name, int[][] board)
          Instead of building the board array yourself, you can take advantage of the static methods of the class SolitaireSamples, which provides convenient standard configurations; if you build a configuration yourself, the convention for int[][] board is as follows.
 
Method Summary
 java.lang.Object clone()
          DOCUMENT ME!
 boolean equals(java.lang.Object obj)
          DOCUMENT ME!
 double getResult(int playerRole)
          DOCUMENT ME!
 int getValueAt(int column, int row)
          DOCUMENT ME!
 int getValueAt(org.jscience.computing.game.puzzle.SolitairePosition pos)
          DOCUMENT ME!
 int[] getWinner()
          DOCUMENT ME!
 int hashCode()
          still experimental at this point
 boolean isSolved()
          DOCUMENT ME!
protected  GameMove[] listLegalMoves()
          DOCUMENT ME!
 int nextPlayer()
          DOCUMENT ME!
 int pegsLeft()
          DOCUMENT ME!
protected  boolean popMove()
          DOCUMENT ME!
protected  boolean pushMove(GameMove move)
          DOCUMENT ME!
 java.lang.String toString()
          DOCUMENT ME!
 
Methods inherited from class org.jscience.computing.game.AbstractGame
clearRedoList, gameOver, getGameName, getLastMove, getLastPlayer, getLegalMoves, getLegalMoves, getMoveHistory, getNumberOfRedoMoves, getRedoList, isLegalMove, isWinner, loadFromFile, makeMove, numberOfMoves, numberOfPlayers, redoMove, resetLegalMoves, resetLists, saveToFile, spawnChild, undoLastMove, undoMoves
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Solitaire

public Solitaire()
uses SolitaireSamples.getSolitiare() to initialize the game

See Also:
SolitaireSamples.getSolitaire()

Solitaire

public Solitaire(java.lang.String name,
                 int[][] board)
Instead of building the board array yourself, you can take advantage of the static methods of the class SolitaireSamples, which provides convenient standard configurations; if you build a configuration yourself, the convention for int[][] board is as follows.
  • array must be of size [8][8]
  • 0 values in the array are wasted; for the game the values considered are only the array values 1 to 7 to make it more 'human-readable'
  • every position outside the Solitaire playing field (here including the 0 value border arrays) must be other than 0 or 1
  • every Solitaire game position is either set to 0 or 1, where 0 is an empty tile and 1 is a peg
  • The String name is just used as an identification

    See Also:
    SolitaireSamples
    Method Detail

    getWinner

    public int[] getWinner()
    DOCUMENT ME!

    Returns:
    DOCUMENT ME!

    getResult

    public double getResult(int playerRole)
    DOCUMENT ME!

    Specified by:
    getResult in interface GamePlay
    Overrides:
    getResult in class AbstractGame
    Parameters:
    playerRole - DOCUMENT ME!
    Returns:
    DOCUMENT ME!

    nextPlayer

    public int nextPlayer()
    DOCUMENT ME!

    Returns:
    DOCUMENT ME!

    listLegalMoves

    protected GameMove[] listLegalMoves()
    DOCUMENT ME!

    Specified by:
    listLegalMoves in class AbstractGame
    Returns:
    DOCUMENT ME!

    pushMove

    protected boolean pushMove(GameMove move)
    DOCUMENT ME!

    Specified by:
    pushMove in class AbstractGame
    Parameters:
    move - DOCUMENT ME!
    Returns:
    DOCUMENT ME!

    popMove

    protected boolean popMove()
    DOCUMENT ME!

    Specified by:
    popMove in class AbstractGame
    Returns:
    DOCUMENT ME!

    isSolved

    public boolean isSolved()
    DOCUMENT ME!

    Returns:
    DOCUMENT ME!

    pegsLeft

    public int pegsLeft()
    DOCUMENT ME!

    Returns:
    DOCUMENT ME!

    getValueAt

    public int getValueAt(org.jscience.computing.game.puzzle.SolitairePosition pos)
    DOCUMENT ME!

    Parameters:
    pos - DOCUMENT ME!
    Returns:
    DOCUMENT ME!

    getValueAt

    public int getValueAt(int column,
                          int row)
                   throws java.lang.ArrayIndexOutOfBoundsException
    DOCUMENT ME!

    Parameters:
    column - DOCUMENT ME!
    row - DOCUMENT ME!
    Returns:
    DOCUMENT ME!
    Throws:
    java.lang.ArrayIndexOutOfBoundsException - DOCUMENT ME!

    clone

    public java.lang.Object clone()
                           throws java.lang.CloneNotSupportedException
    DOCUMENT ME!

    Specified by:
    clone in interface GamePlay
    Overrides:
    clone in class AbstractGame
    Returns:
    DOCUMENT ME!
    Throws:
    java.lang.CloneNotSupportedException - DOCUMENT ME!
    See Also:
    AbstractGame.spawnChild(GameMove)

    toString

    public java.lang.String toString()
    DOCUMENT ME!

    Overrides:
    toString in class AbstractGame
    Returns:
    DOCUMENT ME!

    hashCode

    public int hashCode()
    still experimental at this point

    Overrides:
    hashCode in class java.lang.Object
    Returns:
    DOCUMENT ME!

    equals

    public boolean equals(java.lang.Object obj)
    DOCUMENT ME!

    Overrides:
    equals in class java.lang.Object
    Parameters:
    obj - DOCUMENT ME!
    Returns:
    DOCUMENT ME!