Holger's
Java API

com.antelmann.game.card
Class BlackJack

java.lang.Object
  extended by com.antelmann.game.AbstractGame
      extended by com.antelmann.game.card.BlackJack
All Implemented Interfaces:
GamePlay, Serializable, Cloneable

public class BlackJack
extends AbstractGame

BlackJack implements the rules for playing BlackJack. The casino rules of the game are embedded in this class with the implementations of listLegalMoves(), dealerMove() and getResult(int playerRole). Todo for a future version: strip out casino rules and make them available as options that can be changed through public methods.

Author:
Holger Antelmann
See Also:
Serialized Form

Field Summary
static int BURN_CARDS
           
static int MINIMUM_CARDS
           
static int NUMBER_OF_DECKS
           
 
Constructor Summary
BlackJack()
           
BlackJack(CardDeck deck, float[] bet)
           
BlackJack(CardDeck deck, float[] bet, Random random)
           
BlackJack(float bet)
           
BlackJack(float[] bet)
           
BlackJack(float[] bet, Random random)
           
 
Method Summary
 Object clone()
          Note: the cloned object will have a separate Random object assiciated with it, so that operations on the cloned object will not affect the random numbers of the original.
 boolean gameOver()
          This convenience function gameOver() simply checks whether there are any legal moves left; consequently, unless this function is overridden, listLegalMoves() must not check for gameOver().
static int getCardValue(Card card, boolean softCount)
           
 com.antelmann.game.card.BJHand getCurrentHand(int playerRole)
          getCurrentHand() is internally a wrapper which returns a clone of the actual BJHand used in the game
 Vector<Card> getDealerCards()
           
 CardDeck getDeck()
           
static int getHandValue(Collection cards)
           
 Card getOpenDealerCard()
           
 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.
 int[] getWinner()
          getWinner() returns an array of all winning game roles - as there could be more than one winner.
static boolean isBlackJack(Collection cards)
          Note that a Vector of cards may not be considered BlackJack even though this function returns true, which is the case if the particular hand is derived from an Ace split.
static boolean isSoft(Collection cards)
           
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.
 String toString()
          overridden to provide useful information about the game
 
Methods inherited from class com.antelmann.game.AbstractGame
addObserver, clearRedoList, 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
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NUMBER_OF_DECKS

public static int NUMBER_OF_DECKS

MINIMUM_CARDS

public static int MINIMUM_CARDS

BURN_CARDS

public static int BURN_CARDS
Constructor Detail

BlackJack

public BlackJack()

BlackJack

public BlackJack(float bet)

BlackJack

public BlackJack(float[] bet)

BlackJack

public BlackJack(float[] bet,
                 Random random)

BlackJack

public BlackJack(CardDeck deck,
                 float[] bet)

BlackJack

public BlackJack(CardDeck deck,
                 float[] bet,
                 Random random)
Method Detail

getOpenDealerCard

public Card getOpenDealerCard()

getDealerCards

public Vector<Card> getDealerCards()

getDeck

public CardDeck getDeck()

getCurrentHand

public com.antelmann.game.card.BJHand getCurrentHand(int playerRole)
getCurrentHand() is internally a wrapper which returns a clone of the actual BJHand used in the game


getHandValue

public static int getHandValue(Collection cards)

isSoft

public static boolean isSoft(Collection cards)

getCardValue

public static int getCardValue(Card card,
                               boolean softCount)

isBlackJack

public static boolean isBlackJack(Collection cards)
Note that a Vector of cards may not be considered BlackJack even though this function returns true, which is the case if the particular hand is derived from an Ace split.


gameOver

public boolean gameOver()
Description copied from class: AbstractGame
This convenience function gameOver() simply checks whether there are any legal moves left; consequently, unless this function is overridden, listLegalMoves() must not check for gameOver().

Overrides:
gameOver in class AbstractGame

getWinner

public int[] getWinner()
Description copied from interface: GamePlay
getWinner() returns an array of all winning game roles - as there could be more than one winner. If the function returns null, it doesn't necessarily mean that the game is still in progress, but it could also mean that there is no winner in this game even though it is over (alternatively, an empty array could be returned depending on the requirements of the game). Also, if winners are returned, the game could still be in progress. Maybe, a game keeps playing to determine who is the second winner, etc.


getResult

public double getResult(int playerRole)
Description copied from class: AbstractGame
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.

Specified by:
getResult in interface GamePlay
Overrides:
getResult in class AbstractGame
Returns:
1 if game is won, -1 if game is lost and 0 if no winners are present

nextPlayer

public int nextPlayer()
Description copied from interface: GamePlay
nextPlayer() returns the integer representing the game role of the next player. If there is no next player, it is assumed that there are no more legal moves left in the game, in which case the value of nextPlayer() should be irrelevant.


listLegalMoves

protected GameMove[] listLegalMoves()
Description copied from class: AbstractGame
listLegalMoves() returns the legal moves for this game. This function is used by the final method getLegalMoves(), which is a wrapper around this method to avoid the overhead of generating the legal moves over and over again when called multiple times (as calculating legal moves is commonly expensive). Note that implementations of listLegalMoves() must not check for gameOver(), unless gameOver() is overridden not to check for listLegalMoves(). The same applies to isLegalMove().

Specified by:
listLegalMoves in class AbstractGame

pushMove

protected boolean pushMove(GameMove move)
Description copied from class: AbstractGame
pushMove takes a GameMove and alters the game according to to the move.

Specified by:
pushMove in class AbstractGame
Returns:
true only if the move was put on the board successfully.

popMove

protected boolean popMove()
Description copied from class: AbstractGame
popMove undoes the last move by altering the game board to the stage before the last move happened.

Specified by:
popMove in class AbstractGame
Returns:
true only if the move was taken back successfully.

clone

public Object clone()
             throws CloneNotSupportedException
Note: the cloned object will have a separate Random object assiciated with it, so that operations on the cloned object will not affect the random numbers of the original.

Specified by:
clone in interface GamePlay
Overrides:
clone in class AbstractGame
Throws:
CloneNotSupportedException
See Also:
AbstractGame.spawnChild(GameMove)

toString

public String toString()
Description copied from class: AbstractGame
overridden to provide useful information about the game

Overrides:
toString in class AbstractGame


(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads