Exemplo 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;
}
Exemplo 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;
}
Exemplo n.º 3
0
//
//---------------------------------------------------------------
//
// RespondToConvention()
//
BOOL CCueBidConvention::RespondToConvention(const CPlayer& player, 
											const CConventionSet& conventions, 
											CHandHoldings& hand, 
											CCardLocation& cardLocation, 
											CGuessedHandHoldings** ppGuessedHands,
											CBidEngine& bidState,  
											CPlayerStatusDialog& status)
{
	// first see if another convention is active
	if (bidState.GetActiveConvention() &&
							(bidState.GetActiveConvention() != this))
		return FALSE;

	// basic test -- see if we had agreed on a suit last time
	if (bidState.m_nAgreedSuit == NONE)
		return FALSE;

	// get status
	int nStatus = bidState.GetConventionStatus(this);

	//
	int nPartnersBid = bidState.nPartnersBid;
	int nPartnersBidLevel = bidState.nPartnersBidLevel;
	int nPartnersSuit = bidState.nPartnersSuit;
	int nPartnersPrevSuit = bidState.nPartnersPrevSuit;
	int nAgreedSuit = bidState.m_nAgreedSuit;
	int nSupportLevel = bidState.nPartnersSuitSupport;
	int nBid;

	// see if partner made a cue bid
	// it needs to be a bid that commits the partnership to game, 
	// after a suit has been agreed upon
	if ((nAgreedSuit != NONE) && (nPartnersSuit != NOTRUMP) && (nPartnersSuit != nAgreedSuit) &&
		((nPartnersBid > MAKEBID(nAgreedSuit,3)) && (nPartnersBid < bidState.GetGameBid(nAgreedSuit))))
	{
		//NCR what if suit was previously bid by this player???
		// EG: N->1H, S->2C, N->3C, S->3H  3H is NOT a cue bid, it's a response to this player's  previous bid
		// NCR how to test if partner's current bid was in suit previously bid ???
		// NCR what about a game bid???
		int nSuit =  BID_SUIT(nPartnersBid);
		for(int i=0; i < player.GetNumBidsMade(); i++) { // NCR had to add const to this function def
			int nSuitBid = pDOC->GetBidByPlayer(player.GetPosition(), i);
			if(BID_SUIT(nSuitBid) == nSuit)
				return FALSE;  // NCR not cue if partner bid before ???
		}
                                            // NCR-295 game bid in agreed suit???
		if(bidState.IsGameBid(nPartnersBid) && (nSuit == nAgreedSuit) ) // || CheckIfSuitBid(player, BID_SUIT(nPartnersBid))) 
		{
			return FALSE;  //NCR don't treat Game bid as cue bid
		}
		// met the requirements
		status << "CUR0! Partner made a cue bid of " & BTS(nPartnersBid) &
				  ", hinting at slam prospects.\n";
	}
	else
	{
		// this is not a cue bid
		return FALSE;
	}

	//
	// respond to a cue bid only if we have an interest in slam 
	// 
	// only qualify if we have 30+ team points, _OR_
	// strong trump support and 28+ poitns
	//
	if (bidState.m_fMinTPPoints >= 30)
	{
		// 30+ team points
		status << "2CUR1! And since we have " & 
				  bidState.m_fMinTPPoints & "-" & bidState.m_fMaxTPPoints &
				  "+ points in the partnership, we want to respond favorably.\n";
	}
	else if ((nSupportLevel >= SS_GOOD_SUPPORT) && 
								(bidState.m_fMinTPPoints >= 28))
	{
		// good support (4 good or 5 moderate cards)
		status << "2CUR2! And since we have " & bidState.SLTS(nPartnersSuit) &
				   " trump support, " & 
				   ((bidState.m_fMinTPPoints >= 30)? " as well as " : " albeit only with ") &
				   bidState.m_fMinTPPoints & "-" & bidState.m_fMaxTPPoints &
				   " points in the partnership, we want to respond favorably.\n";
	}
	else
	{
		// insufficient strength for slam -- correct back to the agreed suit
		nBid = bidState.GetCheapestShiftBid(nAgreedSuit);
		status << "CUR4! But we don't have the points (only " & 
				  bidState.m_fMinTPPoints & "-" & bidState.m_fMaxTPPoints &
				  " pts in the partnership) or the excellent trump support needed for a marginal slam, so we decline by returning to the agreed suit at a bid of " &
				  BTS(nBid) & ".\n";
		bidState.SetBid(nBid);
		bidState.SetConventionStatus(this, CONV_FINISHED);
		return TRUE;
	}

	//
	// else we're playing along -- find the cheapest response
	//
	if (nStatus == CONV_INACTIVE)
	{
		// first invocation -- find the cheapest Ace
		int nSuit = GetCheapestAce(hand, nPartnersSuit, bidState.m_nAgreedSuit);
		// found a suit with an ace?
		if ((nSuit != nPartnersSuit) && (nSuit != nAgreedSuit)) 
		{
			// found a suit to cue bid
			nBid = bidState.GetCheapestShiftBid(nSuit);
			status << "CUR20! Respond to partner's cue bid, showing our cheapest ace (" &
					  STS(nSuit) & ") with a bid of " & BTS(nBid) & ".\n";
			bidState.SetBid(nBid);
			bidState.SetConventionStatus(this, CONV_RESPONDED_ROUND1);
			return TRUE;
		} 
		else 
		{
			// found no ace, or else it's in the trump suit, so either way
			// just sign off at the agreed suit
			nBid = bidState.GetCheapestShiftBid(nAgreedSuit);
			if (hand.SuitHasCard(nSuit, ACE))
				status << "CUR22! But our only Ace is in the trump suit of " &
						  STSS(nAgreedSuit) & ", so sign off at a bid of " & BTS(nBid) & ".\n";
			else
				status << "CUR24! We have no other Aces to offer, so sign off with the agreed " &
						  STSS(nAgreedSuit) & " suit at a bid of " & BTS(nBid) & ".\n";
			bidState.SetBid(nBid);
			bidState.SetConventionStatus(this, CONV_FINISHED);
			return TRUE;
		}
	}
	else if (nStatus == CONV_RESPONDED_ROUND1)
	{
		// second invocation -- find cheapest King or void
		// first invocation -- find teh cheapest Ace
		int nSuit = GetCheapestKingOrVoid(hand, nPartnersSuit, bidState.m_nAgreedSuit);
		// found an appropriate suit?
		if ((nSuit != nPartnersSuit) && (nSuit != nAgreedSuit)) 
		{
			// found a suit to cue bid
			nBid = bidState.GetCheapestShiftBid(nSuit);
			status << "CUR30! Respond to partner's cue bid, showing our cheapest " &
					  ((hand.GetSuitLength(nSuit) > 0)? "King" : "void suit") &
					  " (in " & STS(nSuit) & ") with a bid of " & BTS(nBid) & ".\n";
			bidState.SetBid(nBid);
//			bidState.SetConventionStatus(this, CONV_RESPONDED_ROUND2);
			bidState.SetConventionStatus(this, CONV_FINISHED);
			return TRUE;
		} 
		else 
		{
			// found no king or void, or else found a king in the trump suit, 
			// so either way, just sign off at the agreed suit
			nBid = bidState.GetCheapestShiftBid(nAgreedSuit);
			if (hand.SuitHasCard(nSuit, KING))
				status << "CUR32! But our only Ace is in the trump suit of " &
						  STSS(nAgreedSuit) & ", so sign off at a bid of " & BTS(nBid) & ".\n";
			else
				status << "CUR34 We have no other Kings or void suits to offer, so sign off with the agreed " &
						  STSS(nAgreedSuit) & " suit at a bid of " & BTS(nBid) & ".\n";
			bidState.SetBid(nBid);
			bidState.SetConventionStatus(this, CONV_FINISHED);
			return TRUE;
		}
	}
	else
	{
		// error!
		bidState.SetConventionStatus(this, CONV_ERROR);
		return FALSE;
	}
}
Exemplo n.º 4
0
//
//---------------------------------------------------------------
//
// InvokeGerber()
//
// Start the Gerber convention
//	 
BOOL CGerberConvention::InvokeGerber(CHandHoldings& hand, CBidEngine& bidState, CPlayerStatusDialog& status, int nEventualSuit)
{
	// record intended suit for later use
	ASSERT(nEventualSuit != NONE);
	bidState.m_nAgreedSuit = nEventualSuit;
	double fMinTPPoints = bidState.m_fMinTPPoints;
	double fMaxTPPoints = bidState.m_fMaxTPPoints;
	double fMinTPCPoints = bidState.m_fMinTPCPoints;
	double fMaxTPCPoints = bidState.m_fMaxTPCPoints;
	double fCardPts = bidState.fCardPts;
	double fPts = bidState.fPts;
	double fAdjPts = bidState.fAdjPts;
	int nBid;


	// if Gerber has already been used, return
	if (bidState.GetConventionStatus(this) >= CONV_INVOKED) 
		return FALSE;

	//
	// if Gerber is not enabled, just bid slam directly
	//
	if (!pCurrConvSet->IsConventionEnabled(tidGerber))
	{
		// no Gerber? go ahead and bid slam directly
		status << "2GERBX! we have " & fCardPts & "/" & fPts & "/" & fAdjPts &
				  " points in hand, for a total of approx. " &
				  fMinTPPoints & "-" & fMaxTPPoints & " / " &
				  fMinTPCPoints & "-" & fMaxTPCPoints & 
				  " pts in the partnership, but we can't use Gerber to investigate Aces and Kings since it's currently not enabled.\n";
		// bid a grand slam if we have 37+ pts and the trump ace
		// or a small slam with 32+ points
		// or make the cheapest shift bid otherwise (D'oh!)
		if ((fMinTPPoints >= PTS_GRAND_SLAM+1) && (hand.SuitHasCard(nEventualSuit, ACE)))
		{
			nBid = MAKEBID(nEventualSuit, 7);
			status << "2GERBX1! but since we have the points for a grand slam and we hold the trump ace, go ahead and bid " & 
					  BTS(nBid) & ".\n";
		}
		else if (fMinTPPoints >= PTS_SLAM)
		{
			nBid = MAKEBID(nEventualSuit, 6);
			status << "2GERBX2! but since we have the points for a small slam, go ahead and bid " & 
					  BTS(nBid) & ".\n";
		}
		else
		{
			// get cheapest shift bid
			nBid = bidState.GetCheapestShiftBid(nEventualSuit);
			status << "2GERBX3! so we just bid " & BTS(nBid) & ".\n";
		}
		//
		bidState.SetBid(nBid);
		return TRUE;
	}

	
	//
	// shouldn't use Gerber if we have all four aces
	//
	if (bidState.numAces == 4)
	{
		// no Gerber? go ahead and bid slam directly
		status << "2GERBY! Unfortunately, since we hold all four aces, Gerber is of little value to us.\n";
		// bid a grand slam if we have 37+ pts and the trump ace
		// or a small slam with 32+ points
		// or make the cheapest shift bid otherwise (D'oh!)  
		if ((fMinTPPoints >= PTS_SLAM+1) 
			    // NCR-324 added NOTRUMP test
			 && ((nEventualSuit == NOTRUMP) || (hand.SuitHasCard(nEventualSuit, ACE))))
		{
			nBid = MAKEBID(nEventualSuit, 7);
			status << "2GERBY1! so since we have the points for a grand slam, go ahead and bid " & 
					  BTS(nBid) & ".\n";
		}
		else if (fMinTPPoints >= PTS_SLAM)
		{
			nBid = MAKEBID(nEventualSuit, 6);
			status << "2GERBY2! so since we have the points for a small slam, go ahead and bid " & 
					  BTS(nBid) & ".\n";
		}
		else
		{
			nBid = bidState.GetCheapestShiftBid(nEventualSuit, pDOC->GetLastValidBid());
			status << "2GERBY3! so without quite enough points for a slam, we just bid " & BTS(nBid) & ".\n";
		}
		//
		bidState.SetBid(nBid);
		return TRUE;
	}


	//
	// else we're playing Gerber and do not hold all four aces
	// so make the bid to ask for aces
	//
	int nPartnersbid = bidState.nPartnersBid;
	if ((nPartnersbid == BID_1NT) || (nPartnersbid == BID_2NT) 
		// NCR-246a Allow Gerber after Stayman 2C
		|| ((nPartnersbid < BID_3NT) && bidState.nPreviousBid == BID_2C) )
	{
		nBid = BID_4C;
		status << "GERBD! with " & bidState.fCardPts & "/" & bidState.fPts & "/" & bidState.fAdjPts & 
				  " points in the hand, for a total of approx. " & 
				  fMinTPCPoints & "-" & fMaxTPCPoints & " / " &
				  fMinTPPoints & "-" & fMaxTPPoints & 
				  " pts in the partnership, explore slam possibilities with Gerber at " &
				  BTS(nBid) & ".\n";
	}
	else
	{
		nBid = BID_PASS;
		status << "GERBDx! we'd like to use Gerber, but partner has already bid higher than 4C, so we have to pass.\n";
	}
	bidState.SetBid(nBid);
	bidState.SetConventionStatus(this, CONV_INVOKED_ROUND1);

	// done	
	return TRUE;
}