org.ninm.games.cardgames.belot
Class PlayingState

java.lang.Object
  |
  +--org.ninm.games.cardgames.belot.StateAdapter
        |
        +--org.ninm.games.cardgames.belot.PlayingState
All Implemented Interfaces:
State
Direct Known Subclasses:
AllTrumpsState, NoTrumpsState, SpecificTrumpState

public abstract class PlayingState
extends StateAdapter

The superclass of all the playing states which holds most of the common functionality

Version:
1.0
Author:
Nikolay

Field Summary
private  int m_cardsPlayedInHand
           
protected  Hand m_hand
           
protected  boolean m_isFirstHand
           
protected  boolean m_isFirstMove
           
protected  java.util.Set m_trumpSuits
           
 
Fields inherited from class org.ninm.games.cardgames.belot.StateAdapter
m_belotEngine
 
Constructor Summary
PlayingState(BelotEngine belotEngine, java.util.Set trumpSuits)
          Constructor PlayingState.
 
Method Summary
 boolean announceTrick(BelotTrick trick)
          tells the engine that a particular player wishes to anounce a trick
 boolean beats(Card card1, Card card2)
           
static boolean beats(Card card1, Card card2, java.util.Set trumpSuits)
          determines if the first card beats the second card in any game
static boolean beats(Face face1, Face face2, boolean isTrump)
          determines if the first face is higher than the second face in either trump or non trump order
protected  java.util.Set findAnnouncedBelots()
          finds any announced belots
abstract  java.util.Set getAllowedCards()
          returns the allowed cards that the current player can play
 java.util.Set getAllowedTricks()
          returns the allowed tricks that the current player can announce
 java.util.Set getCardsThatBeat(java.util.Set cards, Card card)
           
static java.util.Set getCardsThatBeat(java.util.Set cards, Card card, java.util.Set trumpSuits)
           
static int getScore(Card card, java.util.Set trumpSuits)
           
 boolean isTrump(Card card)
           
static boolean isTrump(Card card, java.util.Set trumpSuits)
           
 boolean playCard(Card card)
          indicates a card has been played by a particular player
private  void removeBeatenTricks(java.util.Set tricksSoFar, java.util.Set oppositionAnnouncedTricks)
          removes any tricks that are beaten by opposition announced tricks
protected  java.util.Set removeBelot(java.util.Set announcedTricks)
          removes any belots from the set of announced tricks
protected  java.util.Set removeConflictingTricks(java.util.Set currentPalyerTricks, java.util.Set announcedTricks)
          removes any tricks that conflict with announced tricks
 void start()
          starts the logic of this state!
 
Methods inherited from class org.ninm.games.cardgames.belot.StateAdapter
bidMade, getAllowedBids
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_hand

protected final Hand m_hand

m_trumpSuits

protected final java.util.Set m_trumpSuits

m_isFirstHand

protected boolean m_isFirstHand

m_isFirstMove

protected boolean m_isFirstMove

m_cardsPlayedInHand

private int m_cardsPlayedInHand
Constructor Detail

PlayingState

public PlayingState(BelotEngine belotEngine,
                    java.util.Set trumpSuits)
Constructor PlayingState.

Parameters:
belotEngine - a reference to the belot engine
trumpSuits - all the suits that are trumps
Method Detail

announceTrick

public boolean announceTrick(BelotTrick trick)
Description copied from interface: State
tells the engine that a particular player wishes to anounce a trick

Specified by:
announceTrick in interface State
Overrides:
announceTrick in class StateAdapter
Parameters:
trick - the trick
Returns:
true if the trick was announced successfully

getAllowedCards

public abstract java.util.Set getAllowedCards()
Description copied from interface: State
returns the allowed cards that the current player can play

Specified by:
getAllowedCards in interface State
Overrides:
getAllowedCards in class StateAdapter
Returns:
List the array of allowed cards for the player

playCard

public boolean playCard(Card card)
Description copied from interface: State
indicates a card has been played by a particular player

Specified by:
playCard in interface State
Overrides:
playCard in class StateAdapter
Parameters:
card - the card being played
Returns:
true if the card was played succesfully

start

public void start()
Description copied from interface: State
starts the logic of this state!


beats

public static boolean beats(Face face1,
                            Face face2,
                            boolean isTrump)
determines if the first face is higher than the second face in either trump or non trump order

Parameters:
face1 - the first face
face2 - the second face
isTrump - true if the order is trump order
Returns:
boolean returns true if the first face beats the second face

beats

public static boolean beats(Card card1,
                            Card card2,
                            java.util.Set trumpSuits)
determines if the first card beats the second card in any game

Parameters:
card1 - the first card
card2 - the second card
trumpSuits - all trump suits
Returns:
boolean returns true if the first card beats the second card

isTrump

public static boolean isTrump(Card card,
                              java.util.Set trumpSuits)

isTrump

public boolean isTrump(Card card)

getCardsThatBeat

public java.util.Set getCardsThatBeat(java.util.Set cards,
                                      Card card)

getCardsThatBeat

public static java.util.Set getCardsThatBeat(java.util.Set cards,
                                             Card card,
                                             java.util.Set trumpSuits)

beats

public boolean beats(Card card1,
                     Card card2)

getScore

public static int getScore(Card card,
                           java.util.Set trumpSuits)

getAllowedTricks

public java.util.Set getAllowedTricks()
Description copied from interface: State
returns the allowed tricks that the current player can announce

Specified by:
getAllowedTricks in interface State
Overrides:
getAllowedTricks in class StateAdapter
Returns:
List the array of allowed tricks for the current player

removeBeatenTricks

private void removeBeatenTricks(java.util.Set tricksSoFar,
                                java.util.Set oppositionAnnouncedTricks)
removes any tricks that are beaten by opposition announced tricks

Parameters:
tricksSoFar - the tricks found so far in the players hand
oppositionAnnouncedTricks - any tricks announced by the opposition

removeConflictingTricks

protected java.util.Set removeConflictingTricks(java.util.Set currentPalyerTricks,
                                                java.util.Set announcedTricks)
removes any tricks that conflict with announced tricks

Parameters:
currentPalyerTricks -
announcedTricks -
Returns:
Set

removeBelot

protected java.util.Set removeBelot(java.util.Set announcedTricks)
removes any belots from the set of announced tricks

Parameters:
announcedTricks -
Returns:
Set

findAnnouncedBelots

protected java.util.Set findAnnouncedBelots()
finds any announced belots

Returns:
Set

SourceForge.net Logo