Пример #1
0
//
// RecordCardPlay()
//
// record that a card has been played
//
void CPlayEngine::RecordCardPlay(int nPos, CCard* pCard) 
{ 
	CPlayerStatusDialog& status = *m_pStatusDlg;
/*
	if (pDOC->GetNumCardsPlayedInRound() == 1)
	{
		status << "3==============================================\n";
		status << "3Beginning round " & pDOC->GetPlayRound() + 1 & ".\n";
	}
*/
	if (nPos == m_nPosition)
		status << "4PLAY! We" & 
				  ((pDOC->GetNumCardsPlayedInRound() == 1)? " lead" : " play") &
				  " the " & pCard->GetName() & ".\n";
	else
		status << "4PLAY! " & PositionToString(nPos) & 
				  ((pDOC->GetNumCardsPlayedInRound() == 1)? " leads" : " plays") &
				  " the " & pCard->GetName() & ".\n";

	// record the card played by the specified player
	CGuessedHandHoldings* pHand = m_ppGuessedHands[nPos];
	CGuessedCard* pGuessedCard = new CGuessedCard(pCard, // card
												  FALSE, // not outstanding
												  nPos,	 // location
												  1.0);	 // known with certainty
	*pHand << pGuessedCard;
	pHand->Sort();

	// then re-evaluate holdings in light of the new information
	AdjustHoldingsCount(pCard);
	AdjustCardCountFromPlay(nPos, pCard);
}
Пример #2
0
//
// BiddingDone()
//
// handles cleanup after it's been established that the 
// bidding is finished
//
BOOL CBidDialog::BiddingDone()
{
	// this may be called twice due to delayed <space> key rollover
	if (!theApp.GetValue(tbBiddingInProgress))
		return FALSE;
	//
	m_nCurrMode = BD_MODE_DONE;
	CString strTemp;
	strTemp.Format("Contract is %s.\nDeclarer is %s;\n%s leads.",
			pDOC->GetFullContractString(),
			PositionToString(pDOC->GetDeclarerPosition()),
			PositionToString(pDOC->GetRoundLead()));
//	AfxMessageBox(strTemp, MB_ICONINFORMATION);
//	CBiddingFinishedDialog bidFinishedDialog;
	
	// mark the bidding finished here so that if the user presses <space>,
	// we don't try to provide another bidding hint!
	theApp.SetValue(tbBiddingInProgress, FALSE);
	m_bidFinishedDialog.SetText(strTemp);
	if (m_bidFinishedDialog.DoModal())
	{
		// bidding is complete
		// the bidding-in-progress flag has to be cleared here to keep the
		// view from popping the bid dialog up again when it's activated
//		EndDialog(TRUE);
		ShowWindow(SW_HIDE);
		pVIEW->PostMessage(WM_COMMAND, WMS_BIDDING_DONE);
		return TRUE;
	}
	else
	{
		// rebid or redeal
		theApp.SetValue(tbBiddingInProgress, TRUE);
		if (m_bidFinishedDialog.m_nResultCode == 0)
		{
			PostMessage(WM_COMMAND, IDC_BID_RESTART);
			return FALSE;
		}
		else
		{
			PostMessage(WM_COMMAND, ID_DEAL_NEW_HAND);
			return FALSE;
		}
	}
}
Пример #3
0
//
// RecordRoundComplete()
//
// nPos = winner
// pCard = winning card
//
void CPlayEngine::RecordRoundComplete(int nPos, CCard* pCard) 
{ 
	CPlayerStatusDialog& status = *m_pStatusDlg;
	status << "4PLAY! " & PositionToString(nPos) & 
			  " wins the round.\n--------\n";
	//
//	AdjustHoldingsCount(pCard);
//	RecordCardsPlayed();
}
Пример #4
0
CString CTypeAFinesse::GetFullDescription()
{
	CString strText;
	return FormString("Opportunistically play the %s from %s to finesse against %s.",
					   m_pConsumedCard->GetFaceName(),
					   (m_nTargetHand == IN_HAND)? "hand" : "dummy",
					   PositionToString(m_nTargetPos));
	// done
	return strText;
}
Пример #5
0
// 
//-----------------------------------------------------------------------
//
// Initialize()
//
// one-time initialization at program start
//
void CPlayEngine::Initialize(CPlayer* pPlayer, CPlayer* pPartner, CPlayer* pLHOpponent, CPlayer* pRHOpponent, CHandHoldings* pHoldings, CCardLocation* pCardLocation, CGuessedHandHoldings** ppGuessedHands, CBidEngine* pBidder, CPlayerStatusDialog* pStatusDlg)
{ 
	//
	m_pPlayer = pPlayer; 
	m_pPartner = pPartner; 
	m_pLHOpponent = pLHOpponent;
	m_pRHOpponent = pRHOpponent;
	m_nPosition = pPlayer->GetPosition();
	m_nPartnerPosition = m_pPartner->GetPosition();
	m_pPartnersHand = &m_pPartner->GetHand();
	//
	ASSERT(ISPOSITION(m_nPartnerPosition));
	strcpy(szLHO, PositionToString(m_pLHOpponent->GetPosition()));
	strcpy(szRHO, PositionToString(m_pRHOpponent->GetPosition()));
	//
	m_pHand = pHoldings; 
	m_pCardLocation = pCardLocation; 
	m_ppGuessedHands = ppGuessedHands;
	m_pBidder = pBidder;
	m_pStatusDlg = pStatusDlg;
}
Пример #6
0
//
// RecordSpecialEvent()
//
void CPlayEngine::RecordSpecialEvent(int nCode, int nParam1, int nParam2, int nParam3)
{
	CPlayerStatusDialog& status = *m_pStatusDlg;
	int nPlayer = nParam1;
	int nTeam = GetPlayerTeam(nPlayer);
	int numTricks = nParam2;
	//
	switch(nCode)
	{
		case CEasyBDoc::EVENT_CLAIMED:
//			status << "3PLAYCL! " & TeamToString(nTeam) & " has claimed the remaining " &
			status << "3PLAYCL! " & PositionToString(nPlayer) & " has claimed the remaining " &
				      numTricks & " tricks.\n";
			break;

		case CEasyBDoc::EVENT_CONCEDED:
//			status << "3PLAYCN! " & TeamToString(nTeam) & " has conceded the remaining " &
			status << "3PLAYCN! " & PositionToString(nPlayer) & " has conceded the remaining " &
				      numTricks & " tricks.\n";
			break;
	}
}
Пример #7
0
CString CType1Finesse::GetFullDescription()
{
	CString strText;
	int nTrumpSuit = pDOC->GetTrumpSuit();
	if (m_pCoverCards->GetNumCards() > 1)
		return FormString("Lead a low %s from %s to finesse the %s in %s against %s, with the { %s } as possible cover cards.",
						   ((m_nSuit == nTrumpSuit)? "trump" : STSS(m_nSuit)),
						   ((m_nTargetHand == IN_HAND)? "dummy" : "hand"),
						   m_pConsumedCard->GetFaceName(),
//						   STS(m_nSuit),
						   ((m_nTargetHand == 0)? "hand" : "dummy"),
						   PositionToString(m_nTargetPos),
						   m_pCoverCards->GetHoldingsString());
	else
		return FormString("Lead a low %s from %s to finesse the %s in %s against %s, with the %s as cover.",
						   ((m_nSuit == nTrumpSuit)? "trump" : STSS(m_nSuit)),
						   ((m_nTargetHand == IN_HAND)? "dummy" : "hand"),
						   m_pConsumedCard->GetFaceName(),
//						   STS(m_nSuit),
						   ((m_nTargetHand == IN_HAND)? "hand" : "dummy"),
						   PositionToString(m_nTargetPos),
						   m_pCoverCards->GetAt(0)->GetFaceName());
}
Пример #8
0
//
// 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)
						{
							// playing in 4th seat, high card is partner, so discard
							pCard = GetDiscard();
							status << "PLAYB34! Partner's " & pCurrTopCard->GetFaceName() & 
									  " is high, so discard the " & pCard->GetName() & ".\n";
						}
						else
						{
							// playing in third position -- decide whether to 
							// let partner's card ride
							// do so if if partner's card beats all outstanding cards
							CCard* pTopOutstandingCard = GetHighestOutstandingCard(nSuitLed);
							if ((pTopOutstandingCard == NULL) || (*pCurrTopCard > *pTopOutstandingCard))
							{
								// let partner's card ride
								pCard = GetDiscard();
								status << "PLAYB36! Partner's " & pCurrTopCard->GetFaceName() & 
										  " is higher than any outstanding card, so discard the " & 
										  pCard->GetName() & ".\n";
							}
							else
							{
								// partner's card is not necessarily highest, so top it
								pCard = suit.GetTopSequence().GetBottomCard();
								status << "PLAYB37! Partner's " & pCurrTopCard->GetFaceName() & 
										  " might not win the round, so top it with the " & pCard->GetFaceName() & ".\n";
							}
						}
					}
				}
				else
				{
					// else high card is opponent's, so beat it w/ highest card affordable
					// although, if playing in 3rd pos ahead of dummy, just play
					// high enuff to beat dummy
					if ((nCurrentSeat == 3) && (m_bLHDefender))
					{
						CSuitHoldings& dummySuit = GetDummySuit(nSuitLed);
						int nDummyTopCard = 0;
						if (dummySuit.GetNumCards() > 0)
							nDummyTopCard = dummySuit[0]->GetFaceValue();
						int nTopVal = Max(nDummyTopCard, pCurrTopCard->GetFaceValue());
						pCard = suit.GetLowestCardAbove(nTopVal);
						// see if we can beat the top card or dummy's top card
						if (pCard)
						{
							if (nTopVal == nDummyTopCard)
							{
								// dummy has the top card and we can beat it
								status << "PLAYB38A! Playing third ahead of dummy, need to beat dummy's " & 
										  CardValToString(nDummyTopCard) & ".\n";
							}
							else
							{
								// the top card is declarer's
								status << "PLAYB38B! Play high to win with the " & pCard->GetFaceName() & ".\n";
							}
						}
						else
						{
							// else we can't beat dummy's top card, but play
							// high anyway to force out his winner
							pCard = suit.GetLowestCardAbove(pCurrTopCard);
							status << "PLAYB38C! We top declarer's " & pCurrTopCard->GetFaceName() &
								      " to force a winner from dummy.\n";
						}
					}
					else if (nCurrentSeat == 3) 
					{
						// else we're playing 3rd, so play the lowest card from the top sequence
						pCard = suit.GetTopSequence().GetBottomCard();
						status << "PLAYB40! Play high to win with the " & pCard->GetFaceName() & ".\n";
					}
					else
					{
						// else we're playing last (4th)
						// play the cheapest card that will beat the top card
						pCard = suit.GetLowestCardAbove(pCurrTopCard);
						status << "PLAYB41! Play the " & pCard->GetFaceName() & " to win the trick.\n";
					}
				}
			}
			else
			{
				// we don't have a card to top the current high card
				if (bPartnerHigh)
				{
					// but partner's card is high, so we're OK
					pCard = GetDiscard();
					status << "PLAYB47! Partner's " & pCurrTopCard->GetFaceName() & 
							  " can win the trick, so discard the " & pCard->GetName() & ".\n";
				}
				else
				{
					// else we're screwed
					pCard = GetDiscard();
					status << "PLAYB48! We can't beat " & strTopCardPos & "'s " & pCurrTopCard->GetFaceName() & 
							  ", so discard the " & pCard->GetName() & ".\n";
				}
			}
		}
		else if (ISSUIT(nTrumpSuit) && (nSuitLed != nTrumpSuit) &&
							(m_pHand->GetNumCardsInSuit(nTrumpSuit) > 0))
		{
			// here, we can play a trump, so do so if appropriate 
			// see who has the top card in this round
			if (bPartnerHigh)
			{
				// let partner's card ride
				pCard = GetDiscard();
				status << "PLAYB52! Although we could trump this hand, partner's " & pCurrTopCard->GetName() & 
						  " is high, so discard the " & pCard->GetName() & ".\n";
			}
			else
			{
				// opponents have the high card (non-trump) -- so slam 'em
				pCard = m_pHand->GetSuit(nTrumpSuit).GetBottomCard();
				status << "PLAYB55! With no cards in " & SuitToString(nSuitLed) & 
						  ", trump with the " & pCard->GetName() & ".\n";
			}
		}
		else
		{
			// here we have zero cards in the suit and in trumps, so we're hosed
			pCard = GetDiscard();
			status << "PLAYB52! With no cards in the suit led and no trumps, we discard the " & pCard->GetName() & ".\n";
		}
	}
	//
	ASSERT(pCard->IsValid());
	ASSERT(m_pHand->HasCard(pCard));
	//
	return pCard;
}
Пример #9
0
//
// 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";
				}
			}

			// also, if this is the dummy, and the dummy plays his last card 
			// in the suit, he has effectively shown out
			CPlayer* pDummy = pDOC->GetDummyPlayer();
			if ((nPos == pDummy->GetPosition()) && (pDummy->AreCardsExposed()))
			{
				if ((pCard->GetSuit() == nSuitLed) && 
					(pDummy->GetHand().GetNumCardsInSuit(nSuitLed) == 0) &&
					(!pPlayerHoldings->IsSuitShownOut(nSuitLed)))
				{
					status << "3RCP20! Dummy is now out of " & STS(nSuitLed) & ".\n";
					pPlayerHoldings->MarkSuitShownOut(nSuitLed);
				}
			}
		}
//	}

	// special code -- if dummy has just been laid down, mark a suit as shown
	// out if dummy is void in the suit
	CPlayer* pDummy = pDOC->GetDummyPlayer();
	int nRound = pDOC->GetPlayRound();
	if ((nRound == 0) && (nPos == pDummy->GetPosition()) && (pDummy->AreCardsExposed()))
	{
		CHandHoldings& dummy = pDummy->GetHand();
		for(int i=0;i<4;i++)
		{
			if (dummy.GetNumCardsInSuit(i) == 0) 
			{
				status << "3RCP25! Dummy is shown to be void in " & STS(i) & ".\n";
				pPlayerHoldings->MarkSuitShownOut(i);
			}
		}
	}
}
Пример #10
0
void CBidDialog::InitBiddingSequence()
{
	// check for autotrain mode
	if (m_nCurrMode == BD_MODE_AUTO_TRAIN)
		return;

	// get display mode
	m_bUseSuitSymbols = theApp.GetValue(tbUseSuitSymbols);

	// get manual bid option
	m_bManualBidding = theApp.GetValue(tbManualBidding);

	// get pause option
	m_bInsertBiddingPause = theApp.GetValue(tbInsertBiddingPause);
	if (m_bInsertBiddingPause)
		m_nBiddingPauseLength = theApp.GetValue(tnBiddingPauseLength) * 100;
	else
		m_nBiddingPauseLength = 0;

	// get speech option
	m_bSpeechEnabled = theApp.GetValue(tbEnableSpokenBids);

	// get bidding engine info
//	m_nBiddingEngine = theApp.GetValue(tnBiddingEngine);
//	m_bTrainingMode = theApp.GetValue(tbNNetTrainingMode);
	m_nBiddingEngine = 0;
	m_bTrainingMode = FALSE;

	// start the bidding process
	CEasyBDoc* pDoc = CEasyBDoc::GetDoc();
	if (!pDoc || !pDoc->IsInitialized())
		return;
	m_nComputerBid = NONE;
	EnableControls();
	DisableControls();
	
	// clear bid displays
	for(int i=0;i<4;i++)
	{
		SetDlgItemText(IDC_BID_SOUTH+i,"");
		((CStatic*)GetDlgItem(IDCI_BID_SOUTH+i))->SetIcon(NULL);
	}

	// and start bidding, if appropriate
	// but return if just initializing
	if (!theApp.IsBiddingInProgress())
		return;
	int nDealer = pDOC->GetDealer();
	if ((nDealer != SOUTH) || m_bTrainingMode)
	{
		GetComputerBids(nDealer);
	} 
	else 
	{
		UpdateBidDisplay(SOUTH,0,TRUE);	
		m_nCurrMode = BD_MODE_WAITFORBID;
		pDOC->ShowAutoHint();
	}

	// show dealer
	int nPos = pDOC->GetDealer();
	CString strTitle = FormString("Bid  (Dealer = %s)", PositionToString(nPos));
//	if (m_bTrainingMode)
//		strTitle += _T(" (Training Mode)");
	SetWindowText(strTitle);
}
Пример #11
0
//
// SetGameIndex()
//
void CGameReviewDialog::SetGameIndex(int nGame, BOOL bRefresh)
{
	if ((nGame < 0) || (nGame >= m_numGamesAvailable))
		return;

	// init
	m_nGameIndex = nGame;
	m_nBidIndex = 0;
	m_nPlayIndex = 0;
	m_nPlayRound = 0;

	// fill tags list
	// first clear existing items
	m_listTags.DeleteAllItems();
	// then add entries
	CGameRecord* pGameRecord = pDOC->GetGameRecord(m_nGameIndex);
	if (!pGameRecord)
		return;

	// fill the tags list
	int nIndex = 0;
	int nMaxWidth = 0;
	const int tnColSpacer = 14;
	CString strTag, strValue;
	std::map<CString,CString>::const_iterator iter;
	for(iter=pGameRecord->m_mapTagValues.begin();iter!=pGameRecord->m_mapTagValues.end();iter++)
	{
		// get the next tag & value
		strTag = (*iter).first;
		strValue = (*iter).second;

		// skip certain tags
		if ((strTag.CompareNoCase("Auction") == 0) ||
						(strTag.CompareNoCase("Play") == 0))
			continue;

		// set tag column
		m_listTags.InsertItem(nIndex, strTag);

		// set value column
		m_listTags.SetItem(nIndex, 1, LVIF_TEXT, strValue, 0, 0, 0, 0L);
		int nWidth = m_listTags.GetStringWidth(strValue) + tnColSpacer;
		if (nWidth > nMaxWidth)
			nMaxWidth = nWidth;
		nIndex++;
	}

	// set value column width 
	m_listTags.SetColumnWidth(1, nMaxWidth);

	//
	m_nGameIndex = nGame;
	m_nPlayerPosition = pGameRecord->m_nRoundLead[0];
	UpdateData(FALSE);

	// now update the display
	iter = pGameRecord->m_mapTagValues.find(_T("DEAL"));
	if (iter != pGameRecord->m_mapTagValues.end())
		strValue = (*iter).second;
	pDOC->LoadGameRecord(*pGameRecord);
	if (bRefresh)
		pDOC->ResetDisplay();
	pDOC->UpdateBiddingHistory();
	pDOC->UpdatePlayHistory();
	pMAINFRAME->SetAllIndicators();

	// NCR-759 Check if this hand has data to show
	if(pDOC->GetDeclarerPosition() == NONE) {
		return;   // No plays to make
	}  // end NCR-759

	// set prompt
	pMAINFRAME->SetMessageText(FormString("Contract is %s.  Declarer is %s; %s leads.",
										   pDOC->GetFullContractString(),
										   PositionToString(pDOC->GetDeclarerPosition()),
										   PositionToString(pDOC->GetRoundLead())));
	// set game info
	m_numPlaysAvailable = pGameRecord->m_numCardsPlayed;
	if (m_numPlaysAvailable > 0)
		m_numTricksAvailable = ((m_numPlaysAvailable-1) / 4) + 1;
	else
		m_numTricksAvailable = 0;

	// reset suit sequence
	theApp.InitDummySuitSequence(BID_SUIT(pGameRecord->m_nContract), GetPartner(pGameRecord->m_nDeclarer));

	// enable/disable play controls
	GetDlgItem(IDC_PREV)->EnableWindow(FALSE);
	GetDlgItem(IDC_FIRST)->EnableWindow(FALSE);
	if (m_numPlaysAvailable <= 1)
	{
		GetDlgItem(IDC_NEXT)->EnableWindow(FALSE);
		GetDlgItem(IDC_LAST)->EnableWindow(FALSE);
	}
	else
	{
		GetDlgItem(IDC_NEXT)->EnableWindow(TRUE);
		GetDlgItem(IDC_LAST)->EnableWindow(TRUE);
	}

	// and enable/disable game nav controls
	if (m_nGameIndex == 0)
	{
		GetDlgItem(IDC_PREV_GAME)->EnableWindow(FALSE);
		GetDlgItem(IDC_FIRST_GAME)->EnableWindow(FALSE);
	}
	else
	{
		GetDlgItem(IDC_PREV_GAME)->EnableWindow(TRUE);
		GetDlgItem(IDC_FIRST_GAME)->EnableWindow(TRUE);
	}
	//
	if (m_nGameIndex >= m_numGamesAvailable-1)
	{
		GetDlgItem(IDC_NEXT_GAME)->EnableWindow(FALSE);
		GetDlgItem(IDC_LAST_GAME)->EnableWindow(FALSE);
	}
	else
	{
		GetDlgItem(IDC_NEXT_GAME)->EnableWindow(TRUE);
		GetDlgItem(IDC_LAST_GAME)->EnableWindow(TRUE);
	}
}
void CStatusPlayPlanPage::Update()
{
	// return if not all inits are complete
	if ((!m_bInitialized) || (pDOC == NULL))
		return;
	if (!theApp.IsGameInProgress())
	{
		m_strDeclarer = "None";
		UpdateData(FALSE);
		return;
	}

	// clear existing items
	m_listPlayPlan.DeleteAllItems();

	// get the declarer & his play engine
	int nDeclarer = pDOC->GetDeclarerPosition();
	if (!ISPLAYER(nDeclarer))
		return;
	CPlayer* pPlayer = pDOC->GetDeclarer();
	CDeclarerPlayEngine* pPlayEngine = pPlayer->GetDeclarerEngine();
	CPlayList& playPlan = pPlayEngine->GetPlayPlan();

	// list declarer
	m_strDeclarer.Format("%s", PositionToString(pPlayer->GetPosition()));

	// & number of available plays
	int nCount = playPlan.GetSize();
	m_strNumPlays.Format("%d",nCount);

	// also list the current play
	const CPlay* pPlay = pPlayEngine->GetCurrentPlay();
	CString strFailedPlay = pPlayEngine->GetFailedPlayName();
	if (pPlay)
		m_strCurrentPlay = (const_cast<CPlay*>(pPlay))->GetDescription();
	else if (!strFailedPlay.IsEmpty())
		m_strCurrentPlay = strFailedPlay;
	else
		m_strCurrentPlay = "None";

	// now list the plays
	for(int i=0;i<nCount;i++)
	{
		CPlay* pPlay = playPlan[i];
		// set number
		m_listPlayPlan.InsertItem(i, FormString(i+1));
		// set name
		m_listPlayPlan.SetItem(i, 1, LVIF_TEXT, pPlay->GetPlayTypeName(), 0, 0, 0, 0L);
		// add description
		m_listPlayPlan.SetItem(i, 2, LVIF_TEXT, pPlay->GetDescription(), 0, 0, 0, 0L);
		// add winner coded
		int nProspect = pPlay->GetPlayProspect();
		m_listPlayPlan.SetItem(i, 3, LVIF_TEXT, szProspectDescription[nProspect], 0, 0, 0, 0L);
		// add consumed card
		CCard* pConsumedCard = pPlay->GetConsumedCard();
		m_listPlayPlan.SetItem(i, 4, LVIF_TEXT, (pConsumedCard? pConsumedCard->GetName() : ""), 0, 0, 0, 0L);
		// add target card
		CCard* pTargetCard = pPlay->GetTargetCard();
		m_listPlayPlan.SetItem(i, 5, LVIF_TEXT, (pTargetCard? pTargetCard->GetName() : ""), 0, 0, 0, 0L);
		// add key cards
		CCardList* pKeyCards = pPlay->GetKeyCardsList();
		m_listPlayPlan.SetItem(i, 6, LVIF_TEXT, (pKeyCards? pKeyCards->GetHoldingsString() : ""), 0, 0, 0, 0L);
		// add OR-Key cards
		CCardList* pORKeyCards = pPlay->GetOrKeyCardsList();
		m_listPlayPlan.SetItem(i, 7, LVIF_TEXT, (pORKeyCards? pORKeyCards->GetHoldingsString() : ""), 0, 0, 0, 0L);
		// add OR-Key cards 2
		CCardList* pORKeyCards2 = pPlay->GetOrKeyCardsList2();
		m_listPlayPlan.SetItem(i, 8, LVIF_TEXT, (pORKeyCards2? pORKeyCards2->GetHoldingsString() : ""), 0, 0, 0, 0L);
		// add opponents' key cards
		CCardList* pOppKeyCards = pPlay->GetEnemyKeyCardsList();
		m_listPlayPlan.SetItem(i, 9, LVIF_TEXT, (pOppKeyCards? pOppKeyCards->GetHoldingsString() : ""), 0, 0, 0, 0L);
		// add opponents' OR-Key cards
		CCardList* pOppORKeyCards = pPlay->GetEnemyOrKeyCardsList();
		m_listPlayPlan.SetItem(i, 10, LVIF_TEXT, (pOppORKeyCards? pOppORKeyCards->GetHoldingsString() : ""), 0, 0, 0, 0L);
		// add required played cards
		CCardList* pReqPlayedCards = pPlay->GetRequiredPlayedCardsList();
		m_listPlayPlan.SetItem(i, 11, LVIF_TEXT, (pReqPlayedCards? pReqPlayedCards->GetHoldingsString() : ""), 0, 0, 0, 0L);
	}

	// done
	UpdateData(FALSE);
	m_nPrevTooltipIndex = -1;
}
Пример #13
0
//
// 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:
			// can't use this play in third posiiton
			m_nStatusCode = PLAY_NOT_VIABLE;
			return m_nStatusCode;


		case 3:
			// in 4th position, simply discard 
			if (m_nStatusCode == PLAY_IN_PROGRESS)
			{
				// discard here, but see if we won
				if (pTopCard == m_pConsumedCard)
				{
					pPlayCard = playEngine.GetDiscard();
					status << "PLAFN76! The finesse worked; finish the play by discarding the " & pPlayCard->GetName() & ".\n";
					m_nStatusCode = PLAY_COMPLETE;
				}
				else
				{
					status << "PLAFN77! The finesse failed, so abandon the play\n";
					m_nStatusCode = PLAY_NOT_VIABLE;
				}
				return m_nStatusCode;
			}
			else
			{
				// play is not active
				m_nStatusCode = PLAY_INACTIVE;
				return m_nStatusCode;
			}
	}

	// done
	ASSERT(pPlayCard->IsValid());
	return m_nStatusCode;
}
Пример #14
0
//
//---------------------------------------------------------
//
BOOL CEasyBDoc::WriteFile(CArchive& ar) 
{
	pFile = ar.GetFile();
	ASSERT(pFile != NULL);

	int i,j,numCards;
	CString	strTemp,strHand;
			
	// write the data

	//
	//-----------------------------------------------------
	//
	// first the file ID
	//
	WriteBlockHeader(BLOCK_FILEINFO);
	WriteString(ITEM_PROGRAM_ID,(LPCTSTR)theApp.GetValue(tstrProgramTitle));
	WriteInt(ITEM_MAJOR_VERSIONNO,theApp.GetValue(tnProgramMajorVersion));
	WriteInt(ITEM_MINOR_VERSIONNO,theApp.GetValue(tnProgramMinorVersion));
	WriteInt(ITEM_INCREMENT_VERSIONNO,theApp.GetValue(tnProgramIncrementVersion));
	WriteInt(ITEM_BUILD_NUMBER,theApp.GetValue(tnProgramBuildNumber));
	WriteString(ITEM_BUILD_DATE,(LPCTSTR)theApp.GetValue(tstrProgramBuildDate));
	CTime time = CTime::GetCurrentTime();
	strTemp.Format(" %s",(LPCTSTR)time.Format("%c"));
	WriteString(ITEM_FILE_DATE,strTemp);
	SkipLine();


	// then the file description
	WriteBlockHeader(BLOCK_FILEDESC);
	WriteString(ITEM_NONE,m_strFileDescription);
//	SkipLine();


	//
	//-----------------------------------------------------
	//
	// hand information
	//
	WriteBlockHeader(BLOCK_HANDINFO);
	// first the current hand
	for(i=0;i<4;i++) 
	{
		numCards = PLAYER(i).GetNumCards();
		strHand.Empty();
		for(j=0;j<numCards;j++) 
		{
			strHand += PLAYER(i).GetCardByPosition(j)->GetName();
			strHand += " ";
		}
		switch(i) 
		{
			case NORTH:
				WriteString(ITEM_CURRHAND_NORTH,strHand);
				break;
			case EAST:
				WriteString(ITEM_CURRHAND_EAST,strHand);
				break;
			case SOUTH:
				WriteString(ITEM_CURRHAND_SOUTH,strHand);
				break;
			case WEST:
				WriteString(ITEM_CURRHAND_WEST,strHand);
				break;
		}
	}
	// then the original hand
	for(i=0;i<4;i++) 
	{
		if (pVIEW->GetCurrentMode() == CEasyBView::MODE_CARDLAYOUT) 
		{
			numCards = PLAYER(i).GetNumCards();
			strHand.Empty();
			for(j=0;j<numCards;j++) 
			{
				strHand += PLAYER(i).GetCardByPosition(j)->GetName();
				strHand += " ";
			}
		} 
		else 
		{
			strHand.Empty();
			for(j=0;j<13;j++) 
			{
				strHand += PLAYER(i).GetInitialHandCard(j)->GetName();
				strHand += " ";
			}
		}
		switch(i) 
		{
			case NORTH:
				WriteString(ITEM_ORIGHAND_NORTH,strHand);
				break;
			case EAST:
				WriteString(ITEM_ORIGHAND_EAST,strHand);
				break;
			case SOUTH:
				WriteString(ITEM_ORIGHAND_SOUTH,strHand);
				break;
			case WEST:
				WriteString(ITEM_ORIGHAND_WEST,strHand);
				break;
		}
	}
	SkipLine();



	//
	//-----------------------------------------------------
	//
	// current round information
	//
	WriteBlockHeader(BLOCK_ROUNDINFO);
/*
	WriteString(ITEM_CURR_ROUND_LEAD, PositionToString(m_nRoundLead));
	//
	WriteInt(ITEM_NUM_CARDS_PLAYED_IN_ROUND, m_numCardsPlayedInRound);
	// tricks in current round
	for(i=0;i<m_numCardsPlayedInRound;i++)
		WriteString(ITEM_TRICK_CARD_1+i,m_pCurrTrick[i]->GetName());
*/
	//
	SkipLine();



	//
	//-----------------------------------------------------
	//
	// game status info
	//
	WriteBlockHeader(BLOCK_GAMEINFO);
	WriteInt(ITEM_VIEW_STATUS_CODE,pVIEW->GetCurrentMode());
	WriteBool(ITEM_RUBBER_IN_PROGRESS,theApp.IsRubberInProgress());
	WriteBool(ITEM_GAME_IN_PROGRESS,theApp.IsGameInProgress());
	WriteBool(ITEM_BIDDING_IN_PROGRESS,theApp.IsBiddingInProgress());
	WriteBool(ITEM_HANDS_DEALT,m_bHandsDealt);
	strTemp.Format("%s",SuitToString(m_nContractSuit));
	WriteString(ITEM_CONTRACT_SUIT,strTemp);
	WriteInt(ITEM_CONTRACT_LEVEL,m_nContractLevel);
	WriteInt(ITEM_CONTRACT_MODIFIER, m_bRedoubled? 2 : m_bDoubled? 1 : 0);
	WriteString(ITEM_DEALER,PositionToString(m_nDealer));
	WriteInt(ITEM_NUM_BIDS,m_numBidsMade);
	// declarer & bidding history
	strTemp.Empty();
	int nIndex = 0;
	for(i=0;i<=m_numBidsMade;i++) 
	{
		strTemp += BidToShortString(m_nBiddingHistory[i]);
		strTemp += " ";
	}
	WriteString(ITEM_DECLARER,PositionToString(m_nDeclarer));
	WriteString(ITEM_BIDDING_HISTORY,strTemp);
	SkipLine();


	//
	//-----------------------------------------------------
	//
	// game play record
	//
	WriteBlockHeader(BLOCK_GAMERECORD);
	if (m_bSaveIntermediatePositions)
	{
		// write the # tricks played
		int numTricks = m_numTricksPlayed;
		
		// see if the current trick is incomplete
		if ((pDOC->GetNumCardsPlayedInRound() > 0) && (numTricks < 13))
			numTricks++;
		WriteInt(ITEM_NUM_TRICKS_PLAYED,numTricks);
		
		// # tricks won by each side
		WriteInt(ITEM_NUM_TRICKS_WON_NS,m_numTricksWon[0]);
		WriteInt(ITEM_NUM_TRICKS_WON_EW,m_numTricksWon[1]);
		WriteString(ITEM_GAME_LEAD,PositionToString(m_nGameLead));

		// and the record of tricks
		for(i=0;i<13;i++) 
		{
			if (i <= m_numTricksPlayed)
			{
				strTemp.Empty();
				strTemp += PositionToString(m_nTrickLead[i]);
				strTemp += " ";
				for(j=0;j<4;j++) 
				{
					CCard* pCard = NULL;
					if (i < m_numTricksPlayed)
						pCard = m_pGameTrick[i][j];
					else
						pCard = m_pCurrTrick[j];
					//
					if (pCard != NULL)
					{
						strTemp += pCard->GetName();
						strTemp += " ";
					}
					else
					{
						strTemp += "-- ";
					}
				}
				strTemp += PositionToString(m_nTrickWinner[i]);
			}
			else
			{
				strTemp = "";
			}
			WriteString(ITEM_GAME_TRICK_1+i,strTemp);
		}
	}
	else
	{
		WriteInt(ITEM_NUM_TRICKS_PLAYED, 0);
	}
	//
	SkipLine();



	//
	//-----------------------------------------------------
	//
	// match info
	//
	if (theApp.IsRubberInProgress())
	{
		// write block header
		WriteBlockHeader(BLOCK_MATCHINFO);

		// write out scores
		WriteInt(ITEM_SCORE_NS_BONUS, m_nBonusScore[NORTH_SOUTH]);
		WriteInt(ITEM_SCORE_NS_GAME0, m_nGameScore[0][NORTH_SOUTH]);
		WriteInt(ITEM_SCORE_NS_GAME1, m_nGameScore[1][NORTH_SOUTH]);
		WriteInt(ITEM_SCORE_NS_GAME2, m_nGameScore[2][NORTH_SOUTH]);
		WriteInt(ITEM_SCORE_NS_GAMES_WON, m_numGamesWon[NORTH_SOUTH]);
		//
		WriteInt(ITEM_SCORE_EW_BONUS, m_nBonusScore[EAST_WEST]);
		WriteInt(ITEM_SCORE_EW_GAME0, m_nGameScore[0][EAST_WEST]);
		WriteInt(ITEM_SCORE_EW_GAME1, m_nGameScore[1][EAST_WEST]);
		WriteInt(ITEM_SCORE_EW_GAME2, m_nGameScore[2][EAST_WEST]);
		WriteInt(ITEM_SCORE_EW_GAMES_WON, m_numGamesWon[EAST_WEST]);

		// write out current game
		WriteInt(ITEM_CURRENT_GAME_INDEX, m_nCurrGame+1);

		// write out score record
		int numBonusScoreRecords = m_strArrayBonusPointsRecord.GetSize();
		for(int i=0;i<numBonusScoreRecords;i++)
			WriteString(ITEM_BONUS_SCORE_RECORD, WrapInQuotes(m_strArrayBonusPointsRecord.GetAt(i)));
		//
		int numGameScoreRecords = m_strArrayTrickPointsRecord.GetSize();
		for(i=0;i<numGameScoreRecords;i++)
			WriteString(ITEM_GAME_SCORE_RECORD, WrapInQuotes(m_strArrayTrickPointsRecord.GetAt(i)));
		//
		SkipLine();
	}



	//
	//-----------------------------------------------------
	//
	// misc info
	//
	WriteBlockHeader(BLOCK_MISCINFO);
	WriteBool(ITEM_AUTOSHOW_COMMENTS,m_bShowCommentsUponOpen);
	WriteBool(ITEM_AUTOSHOW_BID_HISTORY,m_bShowBidHistoryUponOpen);
	WriteBool(ITEM_AUTOSHOW_PLAY_HISTORY,m_bShowPlayHistoryUponOpen);
	WriteBool(ITEM_AUTOSHOW_ANALYSES,m_bShowAnalysesUponOpen);
	SkipLine();

	//
	//-----------------------------------------------------
	//
	// file comments
	//
	WriteBlockHeader(BLOCK_COMMENTS);
	// get the current file comments text if the dialog is open
	CWnd* pWnd = pMAINFRAME->GetDialog(twFileCommentsDialog);
	if (pWnd)
		pWnd->SendMessage(WM_COMMAND, WMS_UPDATE_TEXT, TRUE);
	WriteString(0,m_strFileComments);
	SkipLine();

	//	
	//-----------------------------------------------------
	//
	// PlayerAnalysis, if appropriate
	//
	for(i=0;i<4;i++)
	{
		if (m_bSavePlayerAnalysis[i])
		{
			// save out the player analysis text
			WriteBlockHeader(BLOCK_PLAYER_ANALYSIS + i);
			WriteString(0, m_pPlayer[i]->GetValueString(tszAnalysis));
			SkipLine();
		}
	}

	//	
	//-----------------------------------------------------
	//
	// All done
	//
	ar.Flush();
	return TRUE;
}
Пример #15
0
BOOL CEasyBDoc::ExportGameInfo(CArchive& ar) 
{
	// export game info
	// export hands
	WriteText(ar, "[Dealt Hands]\r\n");
	CString strHands = FormatOriginalHands();
	WriteText(ar, strHands);

	// export bidding history
	WriteText(ar, "\r\n\r\n");
	WriteText(ar, "[Bidding History]\r\n");
	const CString strBiddingHistory = pMAINFRAME->GetBiddingHistory();
	WriteText(ar, strBiddingHistory);
	if (ISBID(GetContract()))
	{
		int nDeclarer = GetDeclarerPosition();
		CString strContract = FormString("Contract: %s by %s; %s leads", pDOC->GetContractString(), PositionToString(nDeclarer), PositionToString(GetNextPlayer(nDeclarer)));
//		WriteText(pFile, strContract);
	}

	// export play history
	WriteText(ar, "\r\n\r\n\r\n");
	WriteText(ar, "[Play History]\r\n");
	const CString strPlayHistory = pMAINFRAME->GetPlayHistory();
	WriteText(ar, strPlayHistory);

	// export current hands
	if (GetNumTricksPlayed() > 0)
	{
		WriteText(ar, "\r\n\r\n\r\n");
		WriteText(ar, "[Current Hands]\r\n");
		CString strHands = pDOC->FormatCurrentHands();
		WriteText(ar, strHands);
	}

	// done
	ar.Flush();
	return TRUE;
}
Пример #16
0
void Ini::Save(wxString key, wxPoint value)
{
	m_Config->Write(key, PositionToString(value));
}
Пример #17
0
wxPoint Ini::Load(wxString key, const wxPoint def_value)
{
	return StringToPosition(m_Config->Read(key, PositionToString(def_value)));
}
Пример #18
0
//
// GetMinCardsInSuit()
//
// returns the minimum number of cards a player currently holds in a suit
//
int CPlayEngine::GetMinCardsInSuit(int nPlayer, int nSuit) const
{
	VERIFY((nPlayer >= 0) && (nPlayer <= 3) && ISSUIT(nSuit));

	// see if the hand's cards have all been identified
	CGuessedSuitHoldings& suit = m_ppGuessedHands[nPlayer]->GetSuit(nSuit);
	if (suit.AreAllCardsIdentified())
		return suit.GetNumMinRemainingCards();

	// else see if the player is dummy & his cards are visible
	if (nPlayer == pDOC->GetDummyPosition() && pDOC->IsDummyExposed())
	{
		CHandHoldings& hand = pDOC->GetDummyPlayer()->GetHand();
		return hand.GetNumCardsInSuit(nSuit);
	}

	// the initial minimum is of course 0
	int nMin = 0;

	// adjust the minimum only if everyone but ourselves (and the player)
	// has shown out, and there are still cards outstanding
	BOOL bAllShownOut = TRUE;
	int nOurPos = m_pPlayer->GetPosition();
	for(int nPos=0;nPos<4;nPos++)
	{
		if ((nPos == nOurPos) || (nPos == nPlayer))
			continue;
		if (!m_ppGuessedHands[nPos]->IsSuitShownOut(nSuit))
		{
			// someone may still have cards left
			bAllShownOut = FALSE;
			break;
		}
	}

	// see if the two other players have shown out
	if (bAllShownOut)
	{
		// see if the number of suit cards played so far, plus the suit
		// cards we have remaining, add up to to less than 13
		int numCardsPlayed = 0;
		// count the cards that have been played in the suit
		for(int i=0;i<4;i++)
			numCardsPlayed += m_ppGuessedHands[i]->GetSuit(nSuit).GetNumCardsPlayed();
		// add the suit cards remaining in our own hand
		numCardsPlayed += m_pHand->GetSuit(nSuit).GetNumCards();
		if (numCardsPlayed < 13)
		{
			// the player must have the remaining cards
			nMin = 13 - numCardsPlayed;
			// take this opportunity to update the player's info
			// mark the player as having the missing cards
			CSuitHoldings  missingCards;
			int nCount = GetOutstandingCards(nSuit, missingCards);
			VERIFY(nCount == nMin);
			CGuessedHandHoldings* pHand = m_ppGuessedHands[nPlayer];
			for(int j=0;j<nCount;j++)
			{
				CGuessedCard* pGuessedCard = new CGuessedCard(missingCards[j],	// card
															  TRUE,				// still outstanding
															  nPlayer,			// location
															  1.0);				// known with certainty
				*pHand << pGuessedCard;
			}
			// update status
			suit.MarkAllCardsIdentified();
			CPlayerStatusDialog& status = *m_pStatusDlg;
			status << "4PLEMN5! " & PositionToString(nPlayer) &
					  " is now known to hold the remaining " & 
					  missingCards.GetNumCards() & " " & STS(nSuit) & 
					  " (" & missingCards.GetHoldingsString() & ").\n";
			// and update counts
			suit.SetNumOriginalCards(nMin + m_ppGuessedHands[nPlayer]->GetSuit(nSuit).GetNumCardsPlayed());
			suit.SetNumRemainingCards(nMin);
			suit.SetNumLikelyCards(nMin);
			suit.SetNumMinRemainingCards(nMin);
			suit.SetNumMaxRemainingCards(nMin);
		}
	}

	// done
	return nMin;
}