本文整理汇总了C++中CCard::GetSuit方法的典型用法代码示例。如果您正苦于以下问题:C++ CCard::GetSuit方法的具体用法?C++ CCard::GetSuit怎么用?C++ CCard::GetSuit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCard
的用法示例。
在下文中一共展示了CCard::GetSuit方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PlayBestCard
//
// PlayBestCard()
//
// called on the third and fourth hand plays to try to win the trick
//
CCard* CPlayEngine::PlayBestCard(int nPosition)
{
CPlayerStatusDialog& status = *m_pStatusDlg;
// status << "2PLAY3! Playing best card.\n";
// get play info
CCard* pCurrentCard = pDOC->GetCurrentTrickCardLed();
int nSuitLed = pCurrentCard->GetSuit();
int nTopPos;
CCard* pCurrTopCard = pDOC->GetCurrentTrickHighCard(&nTopPos);
CString strTopCardPos = PositionToString(nTopPos);
BOOL bPartnerHigh = FALSE;
int nCurrentRound = pDOC->GetPlayRound();
int nCurrentSeat = pDOC->GetNumCardsPlayedInRound() + 1;
CCard* pPartnersCard = pDOC->GetCurrentTrickCard(m_pPartner->GetPosition());
if (pPartnersCard == pCurrTopCard)
bPartnerHigh = TRUE;
//
int nTrumpSuit = pDOC->GetTrumpSuit();
int numCardsInSuitLed = m_pHand->GetNumCardsInSuit(nSuitLed);
// card to play
CCard* pCard = NULL;
//
// first see if somebody trumped in this hand
//
if ((pDOC->WasTrumpPlayed()) && (nTrumpSuit != nSuitLed))
{
// a trump has been played
// see whether it was played by partner or by an opponent
if (bPartnerHigh)
{
// partner trumped -- leave it alone for now
pCard = GetDiscard();
status << "PLAYB10! We let partner's " & pCurrTopCard->GetName() & " trump ride and discard the " &
pCard->GetName() & ".\n";
}
else
{
// it was an opponent that did the trumping
// see if we can overtrump
CSuitHoldings& trumpSuit = m_pHand->GetSuit(nTrumpSuit);
CCard* pTopTrump = NULL;
if (trumpSuit.GetNumCards() > 0)
pTopTrump = trumpSuit.GetTopCard();
if ((numCardsInSuitLed == 0) && (pTopTrump) && (*pTopTrump > *pCurrTopCard))
{
// get the lowest trump that wil top the current top trump
int numTopCards = trumpSuit.GetNumCardsAbove(pCurrTopCard);
pCard = trumpSuit[numTopCards-1];
status << "PLAYB20! We can overtrump " & strTopCardPos & "'s " & pCurrTopCard->GetName() &
" with the " & pCard->GetFaceName() & ".\n";
}
else
{
// no chance to win, so discard
pCard = GetDiscard();
if ((numCardsInSuitLed == 0) && (trumpSuit.GetNumCards() > 0))
status << "PLAYB22! We can't overtrump " & strTopCardPos & "'s " &
pCurrTopCard->GetFaceName() & ", so discard the " & pCard->GetName() & ".\n";
else
status << "PLAYB23! We can't beat the opponent's " & pCurrTopCard->GetFaceName() &
" of trumps, so discard the " & pCard->GetName() & ".\n";
}
}
}
else
{
// else nobody has played a trump this round, _or_ a trump was led
// see if we can play trumps
if (numCardsInSuitLed > 0)
{
// nope, gotta follow the suit that was led, trumps or otherwise
// if we can beat the current top card, do so with the cheapest card
CSuitHoldings& suit = m_pHand->GetSuit(nSuitLed);
if (*(suit.GetTopCard()) > *pCurrTopCard)
{
// but see if the top card is partner's
if (bPartnerHigh)
{
// see if we should unblock here
if (ISSUIT(nTrumpSuit) && (nCurrentRound == 0) &&
(suit.GetNumHonors() == 1))
{
// first round in an NT contract, with one honor
// in the suit -- unblock
pCard = suit.GetTopCard();
if (suit.GetNumCards() > 1)
status << "PLAYB30! Drop the " & pCard->GetFaceName() &
" here to unblock the suit for partner.\n";
}
else
{
// else this is not an unblocking situation
if (nCurrentSeat == 4)
//.........这里部分代码省略.........
示例2: AdjustCardCountFromPlay
//
// AdjustCardCountFromPlay()
//
// adjust card count and analysis after a card is played
//
void CPlayEngine::AdjustCardCountFromPlay(int nPos, CCard* pCard)
{
// default code
// if (nPos != m_pPlayer->GetPosition())
// {
// note the card that was played
CGuessedHandHoldings* pPlayerHoldings = m_ppGuessedHands[nPos];
CGuessedCard* pGuessedCard = new CGuessedCard(pCard, // card
FALSE, // no longer outstanding
nPos, // location
1.0); // known with certainty
*pPlayerHoldings << pGuessedCard;
// see if the player showed out
CPlayerStatusDialog& status = *m_pStatusDlg;
CCard* pCardLed = pDOC->GetCurrentTrickCardByOrder(0);
if (pCard)
{
int nSuitLed = pCardLed->GetSuit();
ASSERT(nSuitLed != NONE);
CGuessedSuitHoldings& suit = pPlayerHoldings->GetSuit(nSuitLed);
if ((pCard->GetSuit() != nSuitLed) && (!suit.IsSuitShownOut()))
{
status << "4RCP10! " & PositionToString(nPos) &
" shows out of " & STS(nSuitLed) & ".\n";
suit.MarkSuitShownOut();
if (pPlayerHoldings->GetNumSuitsFullyIdentified() > 1)
{
// multiple suits identified
status << "4RCP1A! " & PositionToString(nPos) &
" is now known to have started with ";
int numTotalIdentifiedSuits = pPlayerHoldings->GetNumSuitsFullyIdentified();
int numIdentifiedSuits = 0;
int numTotalIdentifiedCards = 0;
int numTotalOriginalCards = 0;
int nIdentifiedSuits[4];
for(int i=0;i<4;i++)
{
if (pPlayerHoldings->GetSuit(i).AreAllCardsIdentified())
{
CGuessedSuitHoldings& currSuit = pPlayerHoldings->GetSuit(i);
status < ((numIdentifiedSuits > 0)? " and " : " ") &
currSuit.GetNumOriginalCards() & " " &
((suit.GetNumOriginalCards() > 1)? STS(i) : STSS(i));
nIdentifiedSuits[numIdentifiedSuits] = i;
numIdentifiedSuits++;
numTotalIdentifiedCards += currSuit.GetNumDefiniteCards();
numTotalOriginalCards += currSuit.GetNumOriginalCards();
}
}
status < ".\n";
// if the number of cards is known in 3 suits, the orignal
// and current length of the 4th suit is also known
if (numTotalIdentifiedSuits == 3)
{
// first identify the fourth suit
int nFourthSuit = NONE;
for(int i=0;i<4;i++)
{
// test each suit to see if it's in the list of know suits
for(int j=0;j<3;j++)
{
if (nIdentifiedSuits[j] == i)
break;
}
if (j == 3)
nFourthSuit = i;
}
//
VERIFY(nFourthSuit != NONE);
CGuessedSuitHoldings& fourthSuit = pPlayerHoldings->GetSuit(nFourthSuit);
int numOriginalCards = 13 - numTotalOriginalCards;
VERIFY(numOriginalCards >= 0);
fourthSuit.SetNumOriginalCards(numOriginalCards);
int numRemainingCards = numOriginalCards - fourthSuit.GetNumCardsPlayed();
VERIFY(numRemainingCards >= 0);
// mark the # of remaining cards
// revisit this later
// fourthSuit.SetNumLikelyCards(numRemainingCards);
fourthSuit.SetNumRemainingCards(numRemainingCards);
//
status << "4RCP1B! Therefore, " & PositionToString(nPos) &
" started with " & numOriginalCards & " " & STS(nFourthSuit) &
" and has " & numRemainingCards & " left.\n";
}
}
else
{
status < "RCP5A! " & PositionToString(nPos) &
" is now known to have started with " &
suit.GetNumOriginalCards() & " " &
((suit.GetNumOriginalCards() == 1)? STSS(nSuitLed) : STS(nSuitLed)) & ".\n";
}
}
//.........这里部分代码省略.........
示例3: PlaySecond
//
// PlaySecond()
//
// default implementation, generally should be overridden in derived classes
//
CCard* CPlayEngine::PlaySecond()
{
CPlayerStatusDialog& status = *m_pStatusDlg;
status << "5PLAY2! Playing second, using default player logic.\n";
// get play info
int nDummyPos = pDOC->GetDummyPosition();
CCard* pCardLed = pDOC->GetCurrentTrickCardLed();
int nSuitLed = pCardLed->GetSuit();
int nFaceValue = pCardLed->GetFaceValue();
CCard* pCurrTopCard = pDOC->GetCurrentTrickHighCard();
int nTrumpSuit = pDOC->GetTrumpSuit();
CSuitHoldings& suit = m_pHand->GetSuit(nSuitLed);
// card to play
CCard* pCard = NULL;
// second hand low
int numCardsInSuit = suit.GetNumCards();
if (numCardsInSuit > 0)
{
// default behavior -- just play the low card
pCard = m_pHand->GetSuit(nSuitLed).GetBottomCard();
if (numCardsInSuit > 1)
{
if (*pCard < *pCurrTopCard)
status << "PLY2C1! Play second hand low with the " & pCard->GetFaceName() & ".\n";
else
status << "PLY2C2! As second hand, we play the lowest card we have in the suit, the " & pCard->GetFaceName() & ".\n";
}
else
{
status << "PLY2C4! Play our only " & STSS(nSuitLed) & ", the " & pCard->GetFaceName() & ".\n";
}
}
else
{
// no cards in the suit led
// trump here if possible
if (m_pHand->GetNumTrumps() > 0)
{
//
CSuitHoldings& trumpSuit = m_pHand->GetSuit(nTrumpSuit);
// see if partner would win the suit otherwise
CGuessedSuitHoldings& partnerSuit = m_pPlayer->GetGuessedHand(m_nPartnerPosition)->GetSuit(nSuitLed);
CCardList outstandingCards;
GetOutstandingCards(nSuitLed, outstandingCards);
if (partnerSuit.AreAllCardsIdentified() && partnerSuit.HasCard(outstandingCards[0]->GetFaceValue()))
{
// partner may win the trick, so discard
status << "PLY2K1! We could trump here, but we know partner holds the " & outstandingCards[0]->GetName() &
" and can win the trick, so discard the " & pCard->GetName() & ".\n";
}
else
{
// trump here if possible
// but first see if we're playing ahead of dummy (dummy is to our left),
// and dummy is also void in the suit
CGuessedHandHoldings* pDummyHand = m_pPlayer->GetGuessedHand(nDummyPos);
if ((m_pLHOpponent == pDOC->GetDummyPlayer()) &&
(pDummyHand->GetSuit(nSuitLed).GetNumRemainingCards() == 0) &&
(pDummyHand->GetSuit(nTrumpSuit).GetNumRemainingCards() > 0))
{
// dummy is also void, so trump if we have a trump higher than dummy's
CGuessedCard* pDummyTopTrump = pDummyHand->GetSuit(nTrumpSuit).GetAt(0);
if (trumpSuit.GetNumCardsAbove(pDummyTopTrump->GetFaceValue()) > 0)
{
// go ahead and ruff
pCard = trumpSuit.GetLowestCardAbove(pDummyTopTrump->GetFaceValue());
status << "PLY2M1! Trump here, making sure to thwart dummy's " & pDummyTopTrump->GetFaceName() &
" of trumps by playing the " & pCard->GetFaceName() & ".\n";
}
else
{
// dummy would overtrump
pCard = GetDiscard();
status << "PLY2M2! We'd like to trump here, but Dummy may overruff, so discard the " & pCard->GetName() & ".\n";
}
}
else
{
// safe to trump -- play the lowest trump
pCard = trumpSuit.GetBottomCard();
status << "PLY2P1! Trump with the " & pCard->GetFaceName() & ".\n";
}
}
}
else
{
// discard
pCard = GetDiscard();
status << "PLY2Y! We have no " & SuitToString(nSuitLed) & ", so discard the " & pCard->GetName() & ".\n";
}
}
//
//.........这里部分代码省略.........
示例4: Perform
//
// Perform()
//
// called to do the deed
//
PlayResult CCash::Perform(CPlayEngine& playEngine, CCombinedHoldings& combinedHand,
CCardLocation& cardLocation, CGuessedHandHoldings** ppGuessedHands,
CPlayerStatusDialog& status, CCard*& pPlayCard)
{
// check which hand this is
int nOrdinal = pDOC->GetNumCardsPlayedInRound();
CPlayer* pPlayer = playEngine.GetPlayer();
BOOL bPlayingInHand = (pDOC->GetCurrentPlayer() == pPlayer);
CHandHoldings& playerHand = *(combinedHand.GetPlayerHand());
CHandHoldings& dummyHand = *(combinedHand.GetPartnerHand());
CSuitHoldings& declarerSuit = playerHand.GetSuit(m_nSuit);
CSuitHoldings& dummySuit = dummyHand.GetSuit(m_nSuit);
CCombinedSuitHoldings& combinedSuit = combinedHand.GetSuit(m_nSuit);
CCard* pCardLed = pDOC->GetCurrentTrickCardByOrder(0);
int nSuitLed = pCardLed? pCardLed->GetSuit() : NONE;
CDeclarerPlayEngine& declarerEngine = (CDeclarerPlayEngine&) playEngine;
// see if a trump was played in this round
BOOL bTrumped = FALSE;
int nTrumpSuit = pDOC->GetTrumpSuit();
if ((nSuitLed != nTrumpSuit) && (pDOC->WasTrumpPlayed()))
bTrumped = TRUE;
pPlayCard = NULL;
// see what the top card in the round is
CCard* pTopCard = pDOC->GetCurrentTrickHighCard();
CCard* pDeclarerCard = pDOC->GetCurrentTrickCard(playEngine.GetPlayerPosition());
CCard* pDummysCard = pDOC->GetCurrentTrickCard(playEngine.GetPartnerPosition());
CCard* pPartnersCard = bPlayingInHand? pDummysCard : pDeclarerCard;
BOOL bPartnerHigh = (pTopCard == pPartnersCard);
//
if (!CPlay::IsPlayUsable(combinedHand, playEngine))
{
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// see if one or more opponents are void in the suit AND have not shown out
// of trumps
if (ISSUIT(nTrumpSuit))
{
int numOutstandingTrumps = playEngine.GetNumOutstandingCards(nTrumpSuit);
BOOL bSkipPlay = FALSE;
// if leading, check LHO
CGuessedHandHoldings* pLHOHand = ppGuessedHands[playEngine.GetLHOpponent()->GetPosition()];
if ((nOrdinal == 0) && (numOutstandingTrumps > 0) && pLHOHand->IsSuitShownOut(m_nSuit) && !pLHOHand->IsSuitShownOut(nTrumpSuit))
{
bSkipPlay = TRUE;
status << "5PLCSHZ1! The play <" & m_strName & "> is not yet safe as LHO has shown out of the suit and may ruff.\n";
}
// also check RHO
CGuessedHandHoldings* pRHOHand = ppGuessedHands[playEngine.GetRHOpponent()->GetPosition()];
if ((numOutstandingTrumps > 0) && pRHOHand->IsSuitShownOut(m_nSuit) && !pRHOHand->IsSuitShownOut(nTrumpSuit))
{
bSkipPlay = TRUE;
status << "5PLCSHZ2! The play <" & m_strName & "> is not yet safe as RHO has shown out of the suit and may ruff.\n";
}
//
if (bSkipPlay)
{
// opponents might ruff
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
}
// else proceed
// check our position in the play
switch(nOrdinal)
{
case 0:
// we're leading, player #0
if (bPlayingInHand)
{
// playing from our own hand (declarer) and cashing in hand
if (m_nTargetHand == IN_HAND)
{
// cashing from hand -- check to be sure the other hand has losers
// i.e., don't discard a winner on a winner UNLESS both hands
// have nothing but winners, OR the other hand has only one card,
// a winner that's lower than the top card in this hand,
// AND this hand has only winners
// this is because we don't want to end up stranded in the wrong hand
// examples:
// ---------
// from Kx/A -- don't lead the King!
// Kxx/AQ -- again, don't lead the King
// KJ/Q -- we _can_ lead the K (in fact, we should)
// KQJ/T9 -- doesn't matter
// Qx/AKJ -- doesn't matter
if ((dummySuit.GetNumCards() == 1) && (combinedSuit.GetNumDummyLosers() == 0) &&
(combinedSuit.GetNumDeclarerLosers() == 0) && (*dummySuit[0] < *m_pConsumedCard))
{
// this is a special case, so it's OK
//.........这里部分代码省略.........
示例5: GetLeadCard
//
// GetLeadCard()
//
CCard* CPlayEngine::GetLeadCard()
{
// default implementation
CPlayerStatusDialog& status = *m_pStatusDlg;
CCard* pLeadCard = NULL;
int nTrumpSuit = pDOC->GetTrumpSuit();
// look to see if we have any winners
if (m_pHand->GetNumWinners() > 0)
{
// return the first winner found
// but avoid the trump suit unless there are no other winners
int nSuit = NONE;
if (ISSUIT(nTrumpSuit))
nSuit = GetNextSuit(nTrumpSuit);
else
nSuit= CLUBS; // else start with the club suit
//
for(int i=0;i<4;i++)
{
CSuitHoldings& suit = m_pHand->GetSuit(nSuit);
if ((suit.GetNumTopCards() > 0) && (nSuit != nTrumpSuit))
{
pLeadCard = suit.GetTopSequence().GetBottomCard();
status << "PLYLDA! With no other obvious plays, cash a winner with the " & pLeadCard->GetName() & ".\n";
ASSERT(m_pHand->HasCard(pLeadCard));
return pLeadCard;
}
// else look at the next suit
nSuit = GetNextSuit(nSuit);
}
}
// if we have a card in an unbid suit, lead from that suit.
CArray<int,int> suitsUnbid;
int numSuitsUnbid = pDOC->GetSuitsUnbid(suitsUnbid);
for(int i=0;i<numSuitsUnbid;i++)
{
CSuitHoldings& suit = m_pHand->GetSuit(suitsUnbid[i]);
if (suit.GetNumCards() > 0)
{
pLeadCard = suit.GetBottomCard();
status << "PLYLDB! With no other clear plays available, lead a card from the unbid " &
STSS(pLeadCard->GetSuit()) & " suit.\n";
ASSERT(m_pHand->HasCard(pLeadCard));
return pLeadCard;
}
}
// no winners in hand, so just lead anything
if (ISSUIT(nTrumpSuit))
{
// playing in a suit contract
// if we have any trumps left, _and_ have a singleton, then lead it
if ((m_pHand->GetNumTrumps() > 0) && (m_pHand->GetNumSingletons() > 0))
{
// search for the singleton suit
BOOL bSuitFound = FALSE;
int nSuit;
for(int i=3;i>=0;i--)
{
nSuit = m_pHand->GetSuitsByLength(3);
if (m_pHand->GetNumCardsInSuit(nSuit) > 1)
break; // oops, no more singletons
// check if this is a non-trump singleton suit
if ((m_pHand->GetNumCardsInSuit(nSuit) == 1) && (nSuit != nTrumpSuit))
{
bSuitFound = TRUE;
break;
}
}
// lead a card from the suit
if (bSuitFound)
{
CSuitHoldings& suit = m_pHand->GetSuit(nSuit);
pLeadCard = suit[0];
status << "PLYLDC! Lead the singleton " & pLeadCard->GetName() & " in the hopes of setting up a ruff later.\n";
ASSERT(m_pHand->HasCard(pLeadCard));
return pLeadCard;
}
}
// else we're stuck -- just lead a card from the worst suit
// (i.e., keep the "good" suits alive)
for(int i=3;i>=0;i--)
{
int nSuit = m_pHand->GetSuitsByPreference(i);
// avoid leading from the trump suit if we can help it
if (nSuit == nTrumpSuit)
continue;
// else lead from this suit
if (m_pHand->GetNumCardsInSuit(nSuit) > 0)
{
pLeadCard = m_pHand->GetSuit(nSuit).GetBottomCard();
ASSERT(m_pHand->HasCard(pLeadCard));
return pLeadCard;
}
//.........这里部分代码省略.........
示例6: Perform
//
// Perform()
//
PlayResult CForce::Perform(CPlayEngine& playEngine, CCombinedHoldings& combinedHand,
CCardLocation& cardLocation, CGuessedHandHoldings** ppGuessedHands,
CPlayerStatusDialog& status, CCard*& pPlayCard)
{
// a "force" is a play of the lowest possible card that will force out
// a key enemy card
// check which hand this is
int nOrdinal = pDOC->GetNumCardsPlayedInRound();
CPlayer* pPlayer = playEngine.GetPlayer();
BOOL bPlayingInHand = (pDOC->GetCurrentPlayer() == pPlayer);
CHandHoldings& playerHand = *(combinedHand.GetPlayerHand());
CHandHoldings& dummyHand = *(combinedHand.GetPartnerHand());
CCombinedSuitHoldings& combinedSuit = combinedHand.GetSuit(m_nSuit);
CSuitHoldings& playerSuit = playerHand.GetSuit(m_nSuit);
CSuitHoldings& dummySuit = dummyHand.GetSuit(m_nSuit);
CCard* pCardLed = pDOC->GetCurrentTrickCardByOrder(0);
int nSuitLed = NONE;
if (pCardLed)
nSuitLed = pCardLed->GetSuit();
// see if a trump was played in this round
BOOL bTrumped = FALSE;
if ((nSuitLed != pDOC->GetTrumpSuit()) && (pDOC->WasTrumpPlayed()))
bTrumped = TRUE;
pPlayCard = NULL;
// test preconditions
if (!CPlay::IsPlayUsable(combinedHand, playEngine))
{
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
//
// test to make sure that the required played cards have indeed been played
//
if (m_pRequiredPlayedCardsList)
{
// check if any of the cards that should have benen played
// are still outstanding
for(int i=0;i<m_pRequiredPlayedCardsList->GetNumCards();i++)
{
CCard* pCard = (*m_pRequiredPlayedCardsList)[i];
if (playEngine.IsCardOutstanding(pCard))
{
status << "5PLFRCA! The force play of the " & m_pConsumedCard->GetFaceName() &
" to force out the " & m_nTargetCardVal &
" is not yet viable as the card [" & pCard->GetFaceName() &
"] is still outstanding.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
}
}
//
// check our position in the play
//
switch(nOrdinal)
{
case 0:
// we're leading, player #0
if (bPlayingInHand)
{
// playing from our own hand (declarer)
if (m_nTargetHand == IN_HAND)
{
// play the card necessary to force the opponent
pPlayCard = playerSuit.GetHighestCardBelow(m_nTargetCardVal);
// NCR check that dummy does not have a singleton honor that's same value as our lead
if(dummySuit.IsSingleton()
&& ((dummySuit.GetTopCard()->GetFaceValue() > pPlayCard->GetFaceValue()) // NCR-28
|| (combinedHand.AreEquivalentCards(pPlayCard, dummySuit.GetTopCard()))))
pPlayCard = playerSuit.GetBottomCard(); // NCR get lowest card
if (pPlayCard == NULL)
{
status << "4PLFRC02! Error in force play -- no cards in declarer hand usable in a force play.\n";
m_nStatusCode = PLAY_ERROR;
return m_nStatusCode;
}
status << "PLFRC04! Play the " & pPlayCard->GetName() &
" from hand to force out the opponents' " & CardValToString(m_nTargetCardVal) & ".\n";
}
else
{
// forcing from dummy, so lead a low card
if (playerSuit.GetNumCards() > 0)
{
pPlayCard = playerSuit.GetBottomCard();
status << "PLFRC06! Lead a low " & STSS(m_nSuit) &
" (" & pPlayCard->GetFaceName() &
") from hand to trigger a force play in dummy.\n";
}
else
{
// oops, no card in the suit to lead!
//.........这里部分代码省略.........
示例7: Perform
//
// Perform()
//
PlayResult CTypeAFinesse::Perform(CPlayEngine& playEngine, CCombinedHoldings& combinedHand,
CCardLocation& cardLocation, CGuessedHandHoldings** ppGuessedHands,
CPlayerStatusDialog& status, CCard*& pPlayCard)
{
// Type A Finesse
// - opportunistic play of a non-top card in second position to
// finesse against LHO
// check which hand this is
int nOrdinal = pDOC->GetNumCardsPlayedInRound();
CPlayer* pPlayer = playEngine.GetPlayer();
BOOL bPlayingInHand = (pDOC->GetCurrentPlayer() == pPlayer);
CHandHoldings& playerHand = *(combinedHand.GetPlayerHand());
CHandHoldings& dummyHand = *(combinedHand.GetPartnerHand());
CSuitHoldings& playerSuit = playerHand.GetSuit(m_nSuit);
CSuitHoldings& dummySuit = dummyHand.GetSuit(m_nSuit);
CCard* pCardLed = pDOC->GetCurrentTrickCardByOrder(0);
int nSuitLed = NONE;
if (pCardLed)
nSuitLed = pCardLed->GetSuit();
// see if a trump was played in this round
BOOL bTrumped = FALSE;
if ((nSuitLed != pDOC->GetTrumpSuit()) && (pDOC->WasTrumpPlayed()))
bTrumped = TRUE;
CCard* pTopCard = pDOC->GetCurrentTrickHighCard();
pPlayCard = NULL;
CCard* pOppCard = NULL;
// test preconditions
if (!CPlay::IsPlayUsable(combinedHand, playEngine))
{
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// check our position in the play
switch(nOrdinal)
{
case 0:
// can't use in first seat
m_nStatusCode = PLAY_NOT_VIABLE;
return m_nStatusCode;
case 1:
// playing second -- this is the key to the finesse
// see if the wrong suit was led
if (nSuitLed != m_nSuit)
{
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// check which hand we're playing in
if (bPlayingInHand)
{
// playing second in our own hand (declarer)
// see if it's time to finesse
if (m_nTargetHand == IN_HAND)
{
// play the finesse card
pPlayCard = m_pConsumedCard;
status << "PLAFN20! Opportunistically finesse the " & pPlayCard->GetName() & " from hand in second position against " &
PositionToString(playEngine.GetLHOpponent()->GetPosition()) & ".\n";
}
else
{
// finessing in hand, but this is dummy? messed up
status << "4PLAFN30! We intended to finesse in hand, but ended up here in dummy in third position -- so skip this play.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
}
else
{
// playing third in dummy
// see if it's time to finnesse here
if (m_nTargetHand == IN_DUMMY)
{
// finesse the card from dummy
pPlayCard = m_pConsumedCard;
status << "PLAFN54! Opportunistically finesse the " & pPlayCard->GetName() & " from dummy in second position against " &
PositionToString(playEngine.GetRHOpponent()->GetPosition()) & ".\n";
}
else
{
// messed up
status << "4PLAFN60! We intended to finesse in hand, but ended up here in dummy in third position -- so skip this play.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
}
// all went OK
m_nStatusCode = PLAY_IN_PROGRESS;
break;
case 2:
//.........这里部分代码省略.........
示例8: Perform
//
// Perform()
//
PlayResult CHoldUp::Perform(CPlayEngine& playEngine, CCombinedHoldings& combinedHand,
CCardLocation& cardLocation, CGuessedHandHoldings** ppGuessedHands,
CPlayerStatusDialog& status, CCard*& pPlayCard)
{
// check which hand this is
int nOrdinal = pDOC->GetNumCardsPlayedInRound();
CPlayer* pPlayer = playEngine.GetPlayer();
BOOL bPlayingInHand = (pDOC->GetCurrentPlayer() == pPlayer);
CHandHoldings& playerHand = *(combinedHand.GetPlayerHand());
CHandHoldings& dummyHand = *(combinedHand.GetPartnerHand());
CSuitHoldings& playerSuit = playerHand.GetSuit(m_nSuit);
CSuitHoldings& dummySuit = dummyHand.GetSuit(m_nSuit);
CCard* pCardLed = pDOC->GetCurrentTrickCardByOrder(0);
int nSuitLed = NONE;
if (pCardLed)
nSuitLed = pCardLed->GetSuit();
// see if a trump was played in this round
BOOL bTrumped = FALSE;
int nTrumpSuit = pDOC->GetTrumpSuit();
if ((nSuitLed != nTrumpSuit) && (pDOC->WasTrumpPlayed()))
bTrumped = TRUE;
pPlayCard = NULL;
CCard* pOppCard = NULL;
//
CCard* pRoundTopCard = pDOC->GetCurrentTrickHighCard();
CCard* pDeclarerCard = pDOC->GetCurrentTrickCard(playEngine.GetPlayerPosition());
CCard* pDummysCard = pDOC->GetCurrentTrickCard(playEngine.GetPartnerPosition());
CCard* pPartnersCard = bPlayingInHand? pDummysCard : pDeclarerCard;
BOOL bPartnerHigh = (pRoundTopCard == pPartnersCard);
//
BOOL bValid = FALSE;
// test preconditions
if (!CPlay::IsPlayUsable(combinedHand, playEngine))
{
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// a holdup is simple -- discard instead of winning
switch(nOrdinal)
{
case 0:
// can't hold up here
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
case 1:
if (bPlayingInHand)
pPlayCard = playerHand.GetDiscard();
else
pPlayCard = dummyHand.GetDiscard();
status << "PLHLD04! Hold up a round of " & STS(m_nSuit) &
" and discard the " & pPlayCard->GetFaceName() & " from " &
(bPlayingInHand? "hand" : "dummy") & ".\n";
m_nStatusCode = PLAY_IN_PROGRESS;
break;
case 2:
// can't hold up here
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
case 3:
// complete the hold-up
if (m_nStatusCode != PLAY_IN_PROGRESS)
return PLAY_INACTIVE;
if (bPlayingInHand)
pPlayCard = playerHand.GetDiscard();
else
pPlayCard = dummyHand.GetDiscard();
status << "PLHLD08! Finish the hold-up and discard the " &
pPlayCard->GetFaceName() & " from " & (bPlayingInHand? "hand" : "dummy") & ".\n";
m_nStatusCode = PLAY_COMPLETE;
break;
}
// done
ASSERT(pPlayCard->IsValid());
return m_nStatusCode;
}
示例9: this
//
// Perform()
//
PlayResult CType1Finesse::Perform(CPlayEngine& playEngine, CCombinedHoldings& combinedHand,
CCardLocation& cardLocation, CGuessedHandHoldings** ppGuessedHands,
CPlayerStatusDialog& status, CCard*& pPlayCard)
{
// Type I Finesse
// - lead of a low card towards a higher card in the opposite hand,
// which holds a higher cover card and a commanding top card.
// e.g., AQ3 (dummy) / 4 (hand) -- lead the 4, then finesse the Q
// check which hand this is
int nOrdinal = pDOC->GetNumCardsPlayedInRound();
CPlayer* pPlayer = playEngine.GetPlayer();
BOOL bPlayingInHand = (pDOC->GetCurrentPlayer() == pPlayer);
CHandHoldings& playerHand = *(combinedHand.GetPlayerHand());
CHandHoldings& dummyHand = *(combinedHand.GetPartnerHand());
CSuitHoldings& playerSuit = playerHand.GetSuit(m_nSuit);
CSuitHoldings& dummySuit = dummyHand.GetSuit(m_nSuit);
CCard* pCardLed = pDOC->GetCurrentTrickCardByOrder(0);
int nSuitLed = NONE;
if (pCardLed)
nSuitLed = pCardLed->GetSuit();
// see if a trump was played in this round
BOOL bTrumped = FALSE;
if ((nSuitLed != pDOC->GetTrumpSuit()) && (pDOC->WasTrumpPlayed()))
bTrumped = TRUE;
pPlayCard = NULL;
CCard* pOppCard = NULL;
// BOOL bLeading = TRUE;
CString strRHO = bPlayingInHand? playEngine.szRHO : playEngine.szLHO;
// test preconditions
if (!CPlay::IsPlayUsable(combinedHand, playEngine))
{
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// check our position in the play
switch(nOrdinal)
{
case 0:
// we're leading, player #0
if (bPlayingInHand)
{
// playing from our own hand (declarer)
// see where the finese card is located
if (m_nTargetHand == IN_HAND)
{
// can't finesse here
status << "4PL1FNS10! Can't use this (Type I) finesse leading from hand, as the finesse card (" &
m_pConsumedCard->GetName() & ") and its covers are in our own hand.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
else
{
// finessing from dummy so lead low card of the suit from hand
if (playerHand.GetNumCardsInSuit(m_nSuit) > 0)
{
pPlayCard = playerHand.GetSuit(m_nSuit).GetBottomCard();
status << "PL1FN12! Leading a low " & STSS(m_nSuit) &
" (the " & pPlayCard->GetFaceName() &
") from hand to finesse the " &
m_pConsumedCard->GetFaceName() & " in dummy.\n";
}
else
{
// oops, no card in the suit to lead!
status << "4PL1FN14! Oops, we wanted to finesse a " & STSS(m_nSuit) &
" in dummy, but we have no " & STS(m_nSuit) &
" in hand to lead, so we have to abandon the play.\n";
m_nStatusCode = PLAY_NOT_VIABLE;
return m_nStatusCode;
}
}
}
else
{
// leading from dummy
if (m_nTargetHand == IN_DUMMY)
{
// leading from dummy & finessing in dummy? no can do
status << "4PL1FNS20! Can't use this (Type I) finesse leading from dummy, as the finesse card (" &
m_pConsumedCard->GetName() & ") and its covers are in dummy.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
else
{
// leading from dummy and finessing in hand, so do it
if (dummyHand.GetNumCardsInSuit(m_nSuit) > 0)
{
pPlayCard = dummyHand.GetSuit(m_nSuit).GetBottomCard();
status << "PL1FN22! Lead a low " & STSS(m_nSuit) &
" (the " & pPlayCard->GetFaceName() &
") from dummy to finesse the " &
m_pConsumedCard->GetFaceName() & " in hand.\n";
//.........这里部分代码省略.........
示例10: Perform
//
// Perform()
//
PlayResult CRuff::Perform(CPlayEngine& playEngine, CCombinedHoldings& combinedHand,
CCardLocation& cardLocation, CGuessedHandHoldings** ppGuessedHands,
CPlayerStatusDialog& status, CCard*& pPlayCard)
{
// check which hand this is
int nOrdinal = pDOC->GetNumCardsPlayedInRound();
CPlayer* pPlayer = playEngine.GetPlayer();
BOOL bPlayingInHand = (pDOC->GetCurrentPlayer() == pPlayer);
CHandHoldings& playerHand = *(combinedHand.GetPlayerHand());
CHandHoldings& dummyHand = *(combinedHand.GetPartnerHand());
CSuitHoldings& playerSuit = playerHand.GetSuit(m_nSuit);
CSuitHoldings& dummySuit = dummyHand.GetSuit(m_nSuit);
CCombinedSuitHoldings& combinedSuit = combinedHand.GetSuit(m_nSuit);
CCard* pCardLed = pDOC->GetCurrentTrickCardByOrder(0);
int nSuitLed = NONE;
if (pCardLed)
nSuitLed = pCardLed->GetSuit();
// see if a trump was played in this round
BOOL bTrumped = FALSE;
int nTrumpSuit = pDOC->GetTrumpSuit();
if ((nSuitLed != nTrumpSuit) && (pDOC->WasTrumpPlayed()))
bTrumped = TRUE;
pPlayCard = NULL;
CCard* pOppCard = NULL;
//
CCard* pRoundTopCard = pDOC->GetCurrentTrickHighCard();
CCard* pDeclarerCard = pDOC->GetCurrentTrickCard(playEngine.GetPlayerPosition());
CCard* pDummysCard = pDOC->GetCurrentTrickCard(playEngine.GetPartnerPosition());
CCard* pPartnersCard = bPlayingInHand? pDummysCard : pDeclarerCard;
BOOL bPartnerHigh = (pRoundTopCard == pPartnersCard);
//
BOOL bValid = FALSE;
// test preconditions
if (!CPlay::IsPlayUsable(combinedHand, playEngine))
{
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// check our position in the play
switch(nOrdinal)
{
case 0:
// we're leading, player #0
if (bPlayingInHand)
{
// playing from our own hand (declarer)? can't do so!
if (m_nTargetHand == IN_HAND)
{
// can't ruff here
// status << "4PLRUF02! Can't ruff a card when leading.\n";
m_nStatusCode = PLAY_POSTPONE;
return m_nStatusCode;
}
else
{
// ruffing in dummy -- first check eligibility
if (dummyHand.GetNumCardsInSuit(m_nSuit) > 0)
{
// can't use this now
m_nStatusCode = PLAY_POSTPONE;
return m_nStatusCode;
}
// now lead a low card of the suit from hand
if (combinedSuit.GetNumDeclarerLosers() > 0)
{
pPlayCard = playerHand.GetSuit(m_nSuit).GetBottomCard();
status << "PLRUF04! Lead a low " & STSS(m_nSuit) &
" (the " & pPlayCard->GetFaceName() & ") from hand to ruff in dummy.\n";
}
else
{
// oops, no card in the suit to lead!
status << "4PLRUF08! Oops, we wanted to ruff a " & STSS(m_nSuit) &
" in dummy, but we have no " & STSS(m_nSuit) &
" losers in hand to lead, so we have to abandon the play.\n";
m_nStatusCode = PLAY_NOT_VIABLE;
return m_nStatusCode;
}
}
}
else
{
// leading from dummy
if (m_nTargetHand == IN_DUMMY)
{
// leading from dummy & ruffing in dummy? no can do
// status << "4PLRUF12! Can't lead from dummy and ruff in dummy at the same time.\n";
m_nStatusCode = PLAY_POSTPONE;
return m_nStatusCode;
}
else
{
// ruffing in hand -- first check eligibility
if (playerHand.GetNumCardsInSuit(m_nSuit) > 0)
//.........这里部分代码省略.........