Blackjack

com.amoebacode.blackjack.core
Class PlayerHand

java.lang.Object
  |
  +--com.amoebacode.blackjack.core.GameObject
        |
        +--com.amoebacode.blackjack.core.CardCollection
              |
              +--com.amoebacode.blackjack.core.Hand
                    |
                    +--com.amoebacode.blackjack.core.PlayerHand
All Implemented Interfaces:
ICardCollection, IGameObject, IHand, IPlayerHand

class PlayerHand
extends Hand
implements IPlayerHand

PlayerHand manages one player's hand.

Version:
0.9
Author:
Jason Gurney

Field Summary
private  int bet
          The current bet for this hand
private static int DECLINED_INSURANCE
          Indicates that the player has declined insurance
private  int handIndex
          This hand's position relative to the player's other hands
private static int HAS_INSURANCE
          Indicates that the player has purchased insurance
private  int hasInsurance
          Indicates whether the player has purchased or declined insurance for this hand
private  boolean isStanding
          Indicates whether the player is standing on this hand
private  boolean isSurrendering
          Indicates whether the player has surrendered this hand
private  double netGain
          The net gain for this hand
private static int NO_INSURANCE_SELECTION
          Indicates that the player has not made an insurance selection
private static int PLAYER_LOSES
          Outcome signifying a player loss
private static int PLAYER_PUSHES
          Outcome signifying a push (tie)
private static int PLAYER_SURRENDERS
          Outcome signifying a player surrender
private static int PLAYER_WINS
          Outcome signifying a player victory
 
Fields inherited from class com.amoebacode.blackjack.core.Hand
MAXIMUM_HARD_CARD_SCORE, MAXIMUM_NUMBER_OF_CARDS, MAXIMUM_SCORE
 
Fields inherited from class com.amoebacode.blackjack.core.CardCollection
cards
 
Fields inherited from class com.amoebacode.blackjack.core.GameObject
listeners, parent
 
Constructor Summary
protected PlayerHand(IPlayer player, int bet, int handIndex)
          Default public constructor.
 
Method Summary
 void buyInsurance()
          Accepts the insurance offer.
 boolean canAct()
          Indicates whether the player can act on this hand.
 boolean canDoubleDown()
          Indicates whether the player can double down this hand.
private  boolean canEarlySurrender()
          Indicates whether the player can accept early surrender on this hand.
 boolean canHit()
          Indicates whether the player can hit this hand.
 boolean canSplit()
          Indicates whether the player can split this hand.
 boolean canStand()
          Indicates whether the player can stand on this hand.
 boolean canSurrender()
          Indicates whether the player can accept surrender on this hand.
 void checkAction(java.lang.String action)
          Checks whether the specified user action is the proper basic strategy play.
 void computeNetGain(int dealerScore)
          Calculates the net gain for this hand based on the specified dealer score, the current bet, and the outcome.
private  boolean dealerHasBlackjack()
          Indicates whether the dealer has blackjack.
 void declineInsurance()
          Declines the insurance offer.
 void doubleBet()
          Doubles the current bet and notifies the GUI listeners.
 int getBet()
          Returns the amount of the current bet for this hand.
 int getHandIndex()
          Returns the relative index of this hand within the player's collection of hands.
 double getNetGain()
          Returns the user's net gain for this hand.
 Card getNextCard()
          Removes and returns the first card in this collection and notifies the GUI listeners.
private  int getOutcome(int dealerScore)
          Returns this hand's outcome based on the specified dealer score.
private  IPlayer getPlayer()
          Returns the player that manages this hand.
private  PlayerHandEventListenerCollection getPlayerHandEventListenerCollection()
          Returns the event listener collection for this player hand.
protected  java.lang.String getTotalLabel()
          Returns the prefix for the current score label (for example, "Score:").
 boolean hasBlackjack()
          Indicates whether this hand has blackjack.
private  boolean hasInsurance()
          Indicates whether the player purchased insurance.
 boolean hasSurrendered()
          Indicates whether the player has surrendered this hand.
private  void makeInsuranceDecision(int decision)
          Makes the specified insurance decision and checks for dealer blackjack.
private  boolean noInsuranceSelection()
          Indicates whether the player has made an insurance selection.
 boolean offerInsurance()
          Indicates whether the player should be offered insurance.
 void split()
          Splits this hand's pair into two different hands.
 void stand()
          Stands on this hand.
 void surrender()
          Accepts surrender on this hand.
 void updateAvailableCommands()
          Updates the set of available player hand commands for each GUI listener.
 
Methods inherited from class com.amoebacode.blackjack.core.Hand
addCard, clear, getBestTotal, getBestTotal, getCurrentScore, getHandEventListenerCollection, getHardTotal, getHardTotal, getHouseRules, getMaximumSafeHitScore, getRound, getSoftTotal, getSoftTotal, hasBusted, hasMaximumNumberOfCards, hasMaximumScore, hasPair, hasSoftTotal, hit, shouldUseMixedTotal
 
Methods inherited from class com.amoebacode.blackjack.core.CardCollection
getCardAt, getNumberOfCards, setCards
 
Methods inherited from class com.amoebacode.blackjack.core.GameObject
addEventListener, getEventListenerCollection, getGame, getParent, hasParent, setEventListenerCollection
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 
Methods inherited from interface com.amoebacode.blackjack.core.IHand
clear, getBestTotal, getBestTotal, getCurrentScore, getHardTotal, getSoftTotal, hasBusted, hasPair, hasSoftTotal, hit
 
Methods inherited from interface com.amoebacode.blackjack.core.ICardCollection
addCard, getCardAt, getNumberOfCards, setCards
 
Methods inherited from interface com.amoebacode.blackjack.core.IGameObject
addEventListener, getGame, getParent
 

Field Detail

bet

private int bet
The current bet for this hand

netGain

private double netGain
The net gain for this hand

isStanding

private boolean isStanding
Indicates whether the player is standing on this hand

isSurrendering

private boolean isSurrendering
Indicates whether the player has surrendered this hand

hasInsurance

private int hasInsurance
Indicates whether the player has purchased or declined insurance for this hand

handIndex

private int handIndex
This hand's position relative to the player's other hands

PLAYER_WINS

private static final int PLAYER_WINS
Outcome signifying a player victory

PLAYER_LOSES

private static final int PLAYER_LOSES
Outcome signifying a player loss

PLAYER_PUSHES

private static final int PLAYER_PUSHES
Outcome signifying a push (tie)

PLAYER_SURRENDERS

private static final int PLAYER_SURRENDERS
Outcome signifying a player surrender

NO_INSURANCE_SELECTION

private static final int NO_INSURANCE_SELECTION
Indicates that the player has not made an insurance selection

HAS_INSURANCE

private static final int HAS_INSURANCE
Indicates that the player has purchased insurance

DECLINED_INSURANCE

private static final int DECLINED_INSURANCE
Indicates that the player has declined insurance
Constructor Detail

PlayerHand

protected PlayerHand(IPlayer player,
                     int bet,
                     int handIndex)
Default public constructor.
Parameters:
player - the IPlayer that is instantiating this hand
Method Detail

updateAvailableCommands

public void updateAvailableCommands()
Description copied from interface: IPlayerHand
Updates the set of available player hand commands for each GUI listener.
Specified by:
updateAvailableCommands in interface IPlayerHand
See Also:
IPlayerHand.updateAvailableCommands()

canAct

public boolean canAct()
Description copied from interface: IPlayerHand
Indicates whether the player can act on this hand.
Specified by:
canAct in interface IPlayerHand
See Also:
IPlayerHand.canAct()

canEarlySurrender

private boolean canEarlySurrender()
Indicates whether the player can accept early surrender on this hand.
Returns:
true if the player can accept early surrender

canSplit

public boolean canSplit()
Description copied from interface: IPlayerHand
Indicates whether the player can split this hand.
Specified by:
canSplit in interface IPlayerHand
See Also:
IPlayerHand.canSplit()

canDoubleDown

public boolean canDoubleDown()
Description copied from interface: IPlayerHand
Indicates whether the player can double down this hand.
Specified by:
canDoubleDown in interface IPlayerHand
See Also:
IPlayerHand.canDoubleDown()

canHit

public boolean canHit()
Description copied from interface: IPlayerHand
Indicates whether the player can hit this hand.
Specified by:
canHit in interface IPlayerHand
See Also:
IPlayerHand.canHit()

canStand

public boolean canStand()
Description copied from interface: IPlayerHand
Indicates whether the player can stand on this hand.
Specified by:
canStand in interface IPlayerHand
See Also:
IPlayerHand.canStand()

canSurrender

public boolean canSurrender()
Description copied from interface: IPlayerHand
Indicates whether the player can accept surrender on this hand.
Specified by:
canSurrender in interface IPlayerHand
See Also:
IPlayerHand.canSurrender()

stand

public void stand()
Description copied from interface: IPlayerHand
Stands on this hand.
Specified by:
stand in interface IPlayerHand
See Also:
IPlayerHand.stand()

surrender

public void surrender()
Description copied from interface: IPlayerHand
Accepts surrender on this hand.
Specified by:
surrender in interface IPlayerHand
See Also:
IPlayerHand.surrender()

doubleBet

public void doubleBet()
Description copied from interface: IPlayerHand
Doubles the current bet and notifies the GUI listeners.
Specified by:
doubleBet in interface IPlayerHand
See Also:
IPlayerHand.doubleBet()

split

public void split()
Description copied from interface: IPlayerHand
Splits this hand's pair into two different hands.
Specified by:
split in interface IPlayerHand
See Also:
IPlayerHand.split()

getOutcome

private int getOutcome(int dealerScore)
Returns this hand's outcome based on the specified dealer score.
Parameters:
dealerScore - the score of the dealer hand
Returns:
an integer representing the outcome

dealerHasBlackjack

private boolean dealerHasBlackjack()
Indicates whether the dealer has blackjack.
Returns:
true if the dealer has blackjack

offerInsurance

public boolean offerInsurance()
Description copied from interface: IPlayerHand
Indicates whether the player should be offered insurance.
Specified by:
offerInsurance in interface IPlayerHand
See Also:
IPlayerHand.offerInsurance()

computeNetGain

public void computeNetGain(int dealerScore)
Description copied from interface: IPlayerHand
Calculates the net gain for this hand based on the specified dealer score, the current bet, and the outcome. Also notifies the GUI listeners.
Specified by:
computeNetGain in interface IPlayerHand
See Also:
IPlayerHand.computeNetGain(int)

getNetGain

public double getNetGain()
Description copied from interface: IPlayerHand
Returns the user's net gain for this hand.
Specified by:
getNetGain in interface IPlayerHand
See Also:
IPlayerHand.getNetGain()

hasBlackjack

public boolean hasBlackjack()
Description copied from interface: IHand
Indicates whether this hand has blackjack.
Specified by:
hasBlackjack in interface IHand
Overrides:
hasBlackjack in class Hand
See Also:
IHand.hasBlackjack()

hasSurrendered

public boolean hasSurrendered()
Description copied from interface: IPlayerHand
Indicates whether the player has surrendered this hand.
Specified by:
hasSurrendered in interface IPlayerHand
See Also:
IPlayerHand.hasSurrendered()

makeInsuranceDecision

private void makeInsuranceDecision(int decision)
Makes the specified insurance decision and checks for dealer blackjack.
Parameters:
decision - the insurance decision (accept or decline)

buyInsurance

public void buyInsurance()
Description copied from interface: IPlayerHand
Accepts the insurance offer.
Specified by:
buyInsurance in interface IPlayerHand
See Also:
IPlayerHand.buyInsurance()

declineInsurance

public void declineInsurance()
Description copied from interface: IPlayerHand
Declines the insurance offer.
Specified by:
declineInsurance in interface IPlayerHand
See Also:
IPlayerHand.declineInsurance()

hasInsurance

private boolean hasInsurance()
Indicates whether the player purchased insurance.
Returns:
true if the player purchased insurance

noInsuranceSelection

private boolean noInsuranceSelection()
Indicates whether the player has made an insurance selection.
Returns:
true if the player has not made an insurance decision

getTotalLabel

protected java.lang.String getTotalLabel()
Description copied from class: Hand
Returns the prefix for the current score label (for example, "Score:").
Overrides:
getTotalLabel in class Hand
See Also:
Hand.getTotalLabel()

checkAction

public void checkAction(java.lang.String action)
Description copied from interface: IPlayerHand
Checks whether the specified user action is the proper basic strategy play.
Specified by:
checkAction in interface IPlayerHand
See Also:
IPlayerHand.checkAction(String)

getBet

public int getBet()
Description copied from interface: IPlayerHand
Returns the amount of the current bet for this hand.
Specified by:
getBet in interface IPlayerHand
See Also:
IPlayerHand.getBet()

getHandIndex

public int getHandIndex()
Description copied from interface: IPlayerHand
Returns the relative index of this hand within the player's collection of hands.
Specified by:
getHandIndex in interface IPlayerHand
See Also:
IPlayerHand.getHandIndex()

getNextCard

public Card getNextCard()
Description copied from interface: ICardCollection
Removes and returns the first card in this collection and notifies the GUI listeners.
Specified by:
getNextCard in interface ICardCollection
Overrides:
getNextCard in class CardCollection
See Also:
ICardCollection.getNextCard()

getPlayerHandEventListenerCollection

private PlayerHandEventListenerCollection getPlayerHandEventListenerCollection()
Returns the event listener collection for this player hand.
Returns:
this object's PlayerHandEventListenerCollection

getPlayer

private IPlayer getPlayer()
Returns the player that manages this hand.
Returns:
the IPlayer parent

Blackjack

Copyright © 2002 amoebacode.com.