void CTestPlayDialog::OnStart() { // GetDlgItem(ID_START)->EnableWindow(FALSE); GetDlgItem(ID_STOP)->EnableWindow(TRUE); m_bPlayActive = TRUE; // results array is 8 x 8 // Clubs Diamonds Hearts Spades NT Doubled Redoubled Total // ----------------------------------------------------------------------- // 1-level xx/yy // 2-level // ... // 7-level // Totals // int numHands = 0; BOOL bBreak = FALSE; // // suppress updates // pDOC->SuppressBidHistoryUpdate(TRUE); pDOC->SuppressPlayHistoryUpdate(TRUE); pMAINFRAME->HideDialog(twBidDialog); pVIEW->ClearDisplay(); //NCR pVIEW->SuppressRefresh(); // Dialog box "smears" with this code ??? pDOC->ClearAllInfo(); // save settings BOOL bOldClaimSetting = theApp.GetValue(tbComputerCanClaim); theApp.SetValue(tbComputerCanClaim, FALSE); BOOL bOldAnalysisSetting = theApp.GetValue(tbEnableAnalysisTracing); #ifndef _TESTING theApp.SetValue(tbEnableAnalysisTracing, FALSE); #endif // theApp.SetValue(tbAutoTestMode, TRUE); m_strStatus = "Auto play in progress..."; UpdateData(FALSE); // int nCode = 0; double lfTotalTime = 0; long lNumHands = 0; CString strAvgTime; // loop do { // play continuously // deal a new hand m_strStatus = "Dealing..."; UpdateData(FALSE); pDOC->DealHands(); numHands++; // and get bids m_strStatus = "Bidding..."; UpdateData(FALSE); do { // get the computer's bids int nPos = pDOC->GetCurrentPlayerPosition(); int nBid = pDOC->GetCurrentPlayer()->Bid(); nCode = pDOC->EnterBid(nPos, nBid); if ((nCode == -99) || (nCode == 1)) { // passed out, or 3 passes, and bidding is complete break; } else if (nCode == -1) { AfxMessageBox("Error in Bidding Dialog!"); bBreak = TRUE; break; } } while (!bBreak); // bidding is complete; see if we reached a contract if (nCode == -99) continue; // passed out, so redeal // start timeing long lStartTime = timeGetTime(); // now play out the hand -- play on full auto theApp.SetValue(tnCardPlayMode, CEasyBApp::PLAY_FULL_AUTO_EXPRESS); pDOC->SetValue(tbExpressPlayMode, TRUE); pDOC->InvokeNextPlayer(); // pump the mesage loop while the hand is being played out m_strStatus = "Playing hand..."; UpdateData(FALSE); MSG msg; while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!AfxGetApp()->PumpMessage()) { ::PostQuitMessage(0); return; } } // reset flags pDOC->SetValue(tbExpressPlayMode, FALSE); // end timer lNumHands++; long lEndTime = timeGetTime(); lfTotalTime += (lEndTime - lStartTime); strAvgTime.Format(_T("%.1f secs"), lfTotalTime / (lNumHands*1000)); // CStatic* pText = (CStatic*) GetDlgItem(IDC_AVG_TIME); pText->SetWindowText(strAvgTime); pText->UpdateWindow(); // CStatic* pLabel = (CStatic*) GetDlgItem(IDC_LABEL_AVGTIME); if (!pLabel->IsWindowVisible()) { pLabel->ShowWindow(SW_SHOW); pLabel->UpdateWindow(); } // if (m_bStopFlag) break; // save results and update the display Update(); } while (!bBreak); // // done -- reset // pDOC->SuppressBidHistoryUpdate(FALSE); pDOC->SuppressPlayHistoryUpdate(FALSE); pVIEW->EnableRefresh(); pVIEW->Refresh(TRUE); pDOC->ClearAllInfo(); // restore settings theApp.SetValue(tbComputerCanClaim, bOldClaimSetting); theApp.SetValue(tbEnableAnalysisTracing, bOldAnalysisSetting); // theApp.SetValue(tbAutoTestMode, FALSE); GetDlgItem(ID_START)->EnableWindow(TRUE); GetDlgItem(ID_STOP)->EnableWindow(FALSE); m_bPlayActive = FALSE; m_bStopFlag = FALSE; // m_strStatus = "Ready."; UpdateData(FALSE); }
void CTestPlayDialog::Update() { // display each row m_listResults.DeleteAllItems(); // get the latest results from the document int nTrumpSuit = pDOC->GetTrumpSuit(); int nContractLevel = pDOC->GetContractLevel(); int nDeclaringTeam = pDOC->GetDeclaringTeam(); int numTricksMade = pDOC->GetNumTricksWonByTeam(nDeclaringTeam); BOOL bDoubled = pDOC->IsContractDoubled(); BOOL bReDoubled = pDOC->IsContractRedoubled(); // update counts m_numContracts[nContractLevel-1][nTrumpSuit]++; m_numContracts[nContractLevel-1][nTotalsColumn]++; m_numContracts[nTotalsRow][nTrumpSuit]++; m_numContracts[nTotalsRow][nTotalsColumn]++; if (bDoubled) { m_numContracts[nContractLevel-1][nDoubledColumn]++; m_numContracts[7][nDoubledColumn]++; } else if (bReDoubled) { m_numContracts[nContractLevel-1][nRedoubledColumn]++; m_numContracts[7][nRedoubledColumn]++; } // NCR-706 WRite out boards that go down using Cash play BOOL bSaveThisBoard = FALSE; if(theApp.GetValue(tnFileProgramBuildNumber) == 1234) { bSaveThisBoard = TRUE; // Ask that this board be written theApp.SetValue(tnFileProgramBuildNumber, 1); // turn off } // NCR-706 end // also update # contracts made if (numTricksMade >= (nContractLevel+6)) { m_numMade[nContractLevel-1][nTrumpSuit]++; m_numMade[nContractLevel-1][nTotalsColumn]++; m_numMade[nTotalsRow][nTrumpSuit]++; m_numMade[nTotalsRow][nTotalsColumn]++; if (bDoubled) { m_numMade[nContractLevel-1][nDoubledColumn]++; m_numMade[7][nDoubledColumn]++; } else if (bReDoubled) { m_numMade[nContractLevel-1][nRedoubledColumn]++; m_numMade[7][nRedoubledColumn]++; } } // NCR-AT Save contracts that went down else if (((nContractLevel >= 1) && m_bSaveDowns) || bSaveThisBoard) //<<<<<<<< NCR changed to 1 vs 4 for NCR-706 testing { int nDownCnt = (nContractLevel+6) - numTricksMade; // show number of tricks down CFile file; CFileException fileException; CString strPath; // CTime time = CTime::GetCurrentTime(); strPath.Format("%s\\LostContract_Down_%d_%s.brd",theApp.GetValue(tszProgramDirectory), nDownCnt, pDOC->GetDealIDString()); // (LPCTSTR)time.Format("%X")); int nCode = file.Open((LPCTSTR)strPath, CFile::modeWrite | CFile::modeCreate | CFile::shareDenyWrite, &fileException); CArchive ar(&file, CArchive::store); pDOC->WriteFile(ar); ar.Close(); file.Close(); } // NCR-AT end saving lost contracts #ifdef _DEBUG // NCR-SCU Save hands that have used conventions // if(m_bSaveConvUsed && (pDOC->GetNumSCU() > 0)) { CFile file; CFileException fileException; CString strPath; // Build filename from conventions used CString fileNm = "CU"; // Filename prefix const int nInitNameLen = fileNm.GetLength(); // save length for test below bool usedConv[] = {false,false,false,false,false,false,false,false,false,false, false,false,false,false,false,false,false,false,false,false, false,false,false,false,false,false,false,false,false,false, false,false,false,false,false,false,false,false,false,false}; for(int k = 0; k < pDOC->GetNumSCU(); k++) { int cix = pDOC->GetSCU(k); // get next convention if(cix == tidOvercalls) continue; // skip saving overcalls if(usedConv[cix]) continue; // skip if seen before usedConv[cix] = true; // remember that we've use this one fileNm += GetConvName(cix); // add on convention } // end for(k) thru used conventions if(fileNm.GetLength() > nInitNameLen) { // Only write if a convention used // build filename from conventions used strPath.Format("%s\\%s_%s.brd",theApp.GetValue(tszProgramDirectory), fileNm, pDOC->GetDealIDString()); int nCode = file.Open((LPCTSTR)strPath, CFile::modeWrite | CFile::modeCreate | CFile::shareDenyWrite, &fileException); CArchive ar(&file, CArchive::store); pDOC->WriteFile(ar); ar.Close(); file.Close(); } } // NCR-SCU end saving hands that used a convention #endif // and display for(int nRow=0;nRow<8;nRow++) { m_listResults.InsertItem(nRow, tszRowTitle[nRow]); for(int nCol=0;nCol<8;nCol++) m_listResults.SetItem(nRow, nCol+1, LVIF_TEXT, FormString("%d / %d", m_numMade[nRow][nCol], m_numContracts[nRow][nCol]), 0, 0, 0, 0L); } // show % made CStatic* pLabel = (CStatic*) GetDlgItem(IDC_GAMES_MADE_LABEL); if (!pLabel->IsWindowVisible()) { pLabel->ShowWindow(SW_SHOW); pLabel->UpdateWindow(); } double fPercent = m_numMade[nTotalsRow][nTotalsColumn] / (double) m_numContracts[nTotalsRow][nTotalsColumn]; m_strPercentMade.Format(_T("%.1f%%"), fPercent * 100); UpdateData(FALSE); // m_listResults.UpdateWindow(); }