Ejemplo n.º 1
0
//
// GetCheapestKingOrVoid()
//
// returns the next cheapest suit with a king or void
//
int CCueBidConvention::GetCheapestKingOrVoid(CHandHoldings& hand, int nBaseSuit, int nSecondSuit)
{
	int i;
	//
	if (nBaseSuit < CLUBS)
		return NONE;
	//
	int nSuit;
	if (nBaseSuit == NOTRUMP)
		nSuit = CLUBS;
	else
		nSuit = GetNextSuit(nBaseSuit);
	for(i=0;i<4;i++) 
	{
		// suit should be void or else have a king
		if ( ((hand.GetSuitLength(nSuit) == 0) || hand.SuitHasCard(nSuit, KING)) &&
			 (nSuit != nSecondSuit) )
			break;
		nSuit = GetNextSuit(nSuit);
	}
	//
	if (i < 4)
		return nSuit;
	else
		return nBaseSuit;
}
Ejemplo n.º 2
0
//
// GetCheapestAce()
//
// returns the next cheapest suit with an Ace
// used for cue bidding
//
int CCueBidConvention::GetCheapestAce(CHandHoldings& hand, int nBaseSuit, int nSecondSuit)
{
	int i;
	//
	if (nBaseSuit < CLUBS)
		return NONE;
	//
	int nSuit;
	if (nBaseSuit == NOTRUMP)
		nSuit = CLUBS;
	else
		nSuit = GetNextSuit(nBaseSuit);
	for(i=0;i<4;i++) 
	{
		if (hand.SuitHasCard(nSuit, ACE) && (nSuit != nSecondSuit))
			break;
		nSuit = GetNextSuit(nSuit);
	}
	//
	if (i < 4)
		return nSuit;
	else
		return nBaseSuit;
}
Ejemplo n.º 3
0
//
// 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;
			}
		}
		// else we're stuck with leading a trump
		if (m_pHand->GetNumTrumps() > 0)
			return m_pHand->GetSuit(nTrumpSuit).GetAt(0);
	}
	else
	{
		// playing in notrump
		// lead a card from the worst suit, keeping the good suits alive
		for(int i=3;i>=0;i--)
		{
			int nSuit = m_pHand->GetSuitsByPreference(i);
			if (m_pHand->GetNumCardsInSuit(nSuit) > 0)
			{
				pLeadCard = m_pHand->GetSuit(nSuit).GetBottomCard();
				ASSERT(m_pHand->HasCard(pLeadCard));
				return pLeadCard;
			}
		}
	}


	// we should NEVER get here
	ASSERT(FALSE);
	return NULL;
}