smithers.cards
Class Klondike

java.lang.Object
  extended by smithers.cards.Klondike

public class Klondike
extends java.lang.Object

Represents a game of Klondike, also known as Canfield in the UK. For the rules, see http://en.wikipedia.org/wiki/Klondike_(solitaire). Notice that the methods in this class are precisely those available to the player.


Constructor Summary
Klondike()
          Creates a new game of Klondike.
 
Method Summary
 int deckLength()
          Returns the number of cards remaining in the deck.
 void draw()
          Draws from the deck to the wastepile.
 int drawsLeft()
          Returns the remaining number of times the wastepile can be turned over to the deck.
 int faceDownLength(int col)
          Returns the number of face down cards in the specified tableau column.
 Card foundationTopCard(int col)
          Returns the top card in the specified foundation pile.
 void move(int from, int to)
          Attempts to move cards from one location to another.
 Card[] tableauCards(int col)
          Returns an array of the cards in the specified tableau column.
 Card[] visibleWaste()
          Returns an array of the visible cards in the wastepile.
 boolean won()
          Checks if the game has been won.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Klondike

public Klondike()
Creates a new game of Klondike.

Method Detail

won

public boolean won()
Checks if the game has been won.

Returns:
true if the game has been won

foundationTopCard

public Card foundationTopCard(int col)
Returns the top card in the specified foundation pile. If there are no cards, this will return null.

Parameters:
col - the index of the foundation pile
Returns:
the number of facedown cards in the column

faceDownLength

public int faceDownLength(int col)
Returns the number of face down cards in the specified tableau column.

Parameters:
col - the index of the tableau column
Returns:
the number of facedown cards in the column

tableauCards

public Card[] tableauCards(int col)
Returns an array of the cards in the specified tableau column.

Parameters:
col - the index of the tableau column
Returns:
an array of the cards in the column

deckLength

public int deckLength()
Returns the number of cards remaining in the deck.

Returns:
the number of cards in the deck

visibleWaste

public Card[] visibleWaste()
Returns an array of the visible cards in the wastepile.

Returns:
an array containing the (up to three) visible cards in the wastepile

drawsLeft

public int drawsLeft()
Returns the remaining number of times the wastepile can be turned over to the deck.

Returns:
the number of times the deck can be redealt

draw

public void draw()
Draws from the deck to the wastepile.


move

public void move(int from,
                 int to)
Attempts to move cards from one location to another. Cards are moved from the wastepile if from == 0 or the indicated column of the tableau if 1 <= from && from <= 7. Cards are moved to the foundations if to == 0 or the indicated column of the tableau if 1 <= from && from <= 7. One card will be moved, unless both indices refer to the tableau, in which case whatever number of cards can be moved will be. If no cards can be moved, a CardMoveException will be thrown.

Parameters:
from - the location to move from
to - the location to move to