void KnowledgeBase::InitKB( Set<Card> oSet ) { oSet.Begin(); while( oSet.HasNext() ) { Card* pCard = oSet.GetNext(); if ( i_KitID == ( pCard->GetID() & (SUIT::SUIT_MASK | KIT::KIT_MASK) ) ) { SetState(i_ThisPlayerID, pCard->GetID(), STATE::HAVE); for(int i=0; i<NUM_PLAYERS; ++i) { if ( i != i_ThisPlayerID ) { SetState(i, pCard->GetID(), STATE::DONT_HAVE); } } } } // There cannot be NOT_CHECKED states in this player's positions, turn them to DONT_HAVE for (int i = 0; i < NUM_CARDS; ++i) { if ( GetState(i_ThisPlayerID, GetCardIDFromIndex(i)) == STATE::NOT_CHECKED ) { SetState(i_ThisPlayerID, GetCardIDFromIndex(i), STATE::DONT_HAVE); } } }
AutoPtr< List<String> > TokenWatcher::DumpInternal() { AutoPtr< List<String> > a = new List<String>; { AutoLock lock(mLock); Set<AutoPtr<IBinder> > keys; HashMap<AutoPtr<IBinder>, AutoPtr<Death> >::Iterator iter = mTokens.Begin(); for (; iter != mTokens.End(); ++iter) { keys.Insert(iter->mFirst); } StringBuilder sb("Token count: "); sb += mTokens.GetSize(); a->PushBack(sb.ToString()); Int32 i = 0; Set<AutoPtr<IBinder> >::Iterator iter2 = keys.Begin(); AutoPtr<IBinder> b; for (; iter2 != keys.End(); ++iter) { StringBuilder sb2("["); sb2 += i; sb2 += "] "; sb2 += mTokens[b]->mTag; sb2 += " - "; String bstr; b->ToString(&bstr); sb2 += bstr; a->PushBack(sb2.ToString()); i++; } } return a; }
template <class T> void print(const Set<T>& l, const string& name) { // Print the contents of a Set. Notice the presence of a constant iterator. cout << endl << name << ", size of set is " << l.Size() << "\n[ "; set<T>::const_iterator i; for (i = l.Begin(); i != l.End(); ++i) { cout << *i << " "; } cout << "]\n"; }
// Assumes the input set only contains cards of a single kit Set<Card>* DifferentialFilter::Enter( Set<Card>* pInput ) { pInput->Begin(); if ( pInput->HasNext() ) { Card* pCard = pInput->GetNext(); int iSuit = pCard->GetSuit(); int iKit = pCard->GetKit(); Set<Card>* pCompleteKit = Deck::GetInstace()->GetKit( iSuit | iKit ); Set<Card>* pResultSet = new Set<Card>(); for (pCompleteKit->Begin(); pCompleteKit->HasNext();) { Card* pResultCard = pCompleteKit->GetNext(); bool bRequired = true; for (pInput->Begin(); pInput->HasNext();) { Card* pInputCard = pInput->GetNext(); if ( pResultCard->GetID() == pInputCard->GetID() ) { bRequired = false; break; } } if (bRequired) { pResultSet->PushBack(pResultCard); } } return pResultSet; } return NULL; }
/*---------------------------------------------------------------------------------------------- Generate the actual FSM table for the pass. Process: * Initialize the table with the start state, corresponding to 0 slots matched. * For each rule in the pass, add a state corresponding to 1 slot matched. Keep track of the relevant rule(s) and whether the new state is a terminating state for the rule(s). * When we have created all the 1-slot-matched states, merge any equivalent states.... * For each 1-slot-matched, add 2-slots-matched states for any rules with at least 2 slots. Keep track of the relevant rule(s) and whether the new state is a terminating state for the rule(s). * When we have created all the 2-slots-matched states, merge any equivalent states. * Continue this process until we have created terminating states for every rule (ie, N-slots-matched state where the rule has N slots). ----------------------------------------------------------------------------------------------*/ void GdlPass::GenerateFsmTable(GrcManager * pcman) { // Hungarian: ifs = index of FsmState if (m_nGlobalID == -1) { m_nMaxRuleContext = 0; return; } m_pfsm = new FsmTable(m_nGlobalID, NumberOfFsmMachineClasses()); Assert(m_pfsm->RawNumberOfStates() == 0); // Create the start state, equivalent to no slots matched. m_pfsm->AddState(0); int ifsCurrent = 0; // Index of the first state whose slot-count == the slot count of currState, ie, the // beginning of the state range which may need to be fixed up as we merge. int ifsCurrSlotCntMin = 0; // Index of first state whose slot-count == slot count of currState + 1, ie, the // beginning of the state range in which to check for duplicates. int ifsNextSlotCntMin = 1; while (ifsCurrent < m_pfsm->RawNumberOfStates()) { FsmState * pfstateCurr = m_pfsm->RawStateAt(ifsCurrent); int critSlotsMatched = pfstateCurr->SlotsMatched(); if (!pfstateCurr->HasBeenMerged()) { for (int iprule = 0; iprule < m_vprule.Size(); iprule++) { GdlRule * prule = m_vprule[iprule]; if (ifsCurrent == 0 || // for state #0, all rules are consider matched pfstateCurr->RuleMatched(iprule)) { if (pfstateCurr->SlotsMatched() == prule->NumberOfInputItems()) { pfstateCurr->AddRuleToSuccessList(iprule); } else { Set<FsmMachineClass *> setpfsmc; GetMachineClassesForRuleItem(prule, critSlotsMatched, setpfsmc); for (Set<FsmMachineClass *>::iterator it = setpfsmc.Begin(); it != setpfsmc.End(); ++it) { FsmMachineClass * pfsmc = *it; int ifsmcColumn = pfsmc->Column(); int ifsNextState = pfstateCurr->CellValue(ifsmcColumn); if (ifsNextState == 0) { // Add a new state. ifsNextState = m_pfsm->RawNumberOfStates(); m_pfsm->AddState(critSlotsMatched + 1); pfstateCurr->SetCellValue(ifsmcColumn, ifsNextState); } // Store this rule as one matched for this state. m_pfsm->RawStateAt(ifsNextState)->AddRuleToMatchedList(iprule); } } } } } if (m_pfsm->RawNumberOfStates() > (ifsCurrent + 1) && m_pfsm->RawStateAt(ifsCurrent + 1)->SlotsMatched() != critSlotsMatched) { // We have just finished processing a group of states with critSlotsMatched, // which had the effect of creating a group of states where slots-matched == // critSlotsMatched + 1. There could be duplicates in the latter group, // which are pointed at by the former group. Mark the duplicates so that they // point to the earlier identical state. (Note that since we are currently // not actually deleting the duplicates, we don't need to fix up the earlier // group.) MergeIdenticalStates(ifsCurrSlotCntMin, ifsNextSlotCntMin, m_pfsm->RawNumberOfStates()); ifsCurrSlotCntMin = ifsNextSlotCntMin; ifsNextSlotCntMin = m_pfsm->RawNumberOfStates(); } ifsCurrent++; // go on to next state } m_nMaxRuleContext = m_pfsm->RawStateAt(ifsCurrent - 1)->m_critSlotsMatched; ReorderFsmStates(); GenerateStartStates(pcman); }
/*---------------------------------------------------------------------------------------------- Called by the framework to initialize the dialog. All one-time initialization should be done here (that is, all controls have been created and have valid hwnd's, but they need initial values.) See ${AfDialog#FWndProc} @param hwndCtrl (not used) @param lp (not used) @return true if Successful ----------------------------------------------------------------------------------------------*/ bool RnTlsOptDlg::OnInitDlg(HWND hwndCtrl, LPARAM lp) { m_qrmw = dynamic_cast<RecMainWnd *>(MainWindow()); AfMdiClientWndPtr qmdic = m_qrmw->GetMdiClientWnd(); AssertPtr(qmdic); // Cancel the dialog if we aren't allowed to make changes. AfClientRecWndPtr qafcrw = dynamic_cast<AfClientRecWnd *>(qmdic->GetCurChild()); // This might not exist yet if the filter doesn't match anything during startup. if (qafcrw && !qafcrw->IsOkToChange()) { SuperClass::OnCancel(); return true; } Assert(m_cTabs == 6); // Ensure that the number of dialogs is what we expect. m_hwndTab = GetDlgItem(m_hwnd, kcidTlsOptDlgTab); AfLpInfo * plpi = m_qrmw->GetLpInfo(); AssertPtr(plpi); // Setup m_vuvs plpi->GetDbInfo()->GetCopyUserViewSpecs(&m_vuvs); SetVuvsCopy(); AfViewBarShell * pvwbrs = m_qrmw->GetViewBarShell(); AssertPtr(pvwbrs); // CAUTION! The order these are inserted is important since we use constant indexes to // access them (e.g., kidlgGeneral). AfDialogViewPtr qadv; qadv.Attach(NewObj TlsOptDlgCst(this)); m_vdlgv.Push(qadv); qadv.Attach(NewObj TlsOptDlgVw(this)); m_vdlgv.Push(qadv); qadv.Attach(NewObj FwFilterDlg(this)); m_vdlgv.Push(qadv); qadv.Attach(NewObj TlsOptDlgSort(this)); m_vdlgv.Push(qadv); qadv.Attach(NewObj TlsOptDlgOvr(this)); m_vdlgv.Push(qadv); qadv.Attach(NewObj TlsOptDlgGen(this)); m_vdlgv.Push(qadv); // Initialize the object classes that we can create in this dialog. TlsObject to; to.m_clsid = kclidRnEvent; to.m_nLevel = 0; to.m_strName.Load(kstidEventEntry); m_vto.Push(to); to.m_clsid = kclidRnAnalysis; to.m_nLevel = 0; to.m_strName.Load(kstidAnalEntry); m_vto.Push(to); // Initialize the Custom Define In vector. to.m_clsid = kclidRnEvent; to.m_nLevel = 0; to.m_strName.Load(kstidEventEntry); to.m_strClsName = "RnEvent"; m_vcdi.Push(to); to.m_clsid = kclidRnAnalysis; to.m_nLevel = 0; to.m_strName.Load(kstidAnalEntry); to.m_strClsName = "RnAnalysis"; m_vcdi.Push(to); to.m_clsid = kclidRnGenericRec; to.m_nLevel = 1000; // Level 1000 means ALL Entries to.m_strName.Load(kstidTlsOptCstAllEnt); to.m_strClsName = "RnGenericRec"; m_vcdi.Push(to); m_iDefaultCstDfn = m_vcdi.Size() - 1; // If we don't get a reasonable values from GetCurClsLevel, we just default to 0 for the // index. m_ivto = 0; for (int ivto = 0; ivto < m_vto.Size(); ++ivto) { if (m_vto[ivto].m_clsid == m_tgv.clsid && m_vto[ivto].m_nLevel == m_tgv.nLevel) { m_ivto = ivto; break; } } // Initialize the master view types supported by this dialog. TlsView tv; tv.m_vwt = kvwtBrowse; tv.m_fMaster = false; m_vtv.Push(tv); tv.m_vwt = kvwtDE; tv.m_fMaster = true; m_vtv.Push(tv); tv.m_vwt = kvwtDoc; tv.m_fMaster = false; m_vtv.Push(tv); // Update the General tab. TlsOptDlgGen * ptodg = dynamic_cast<TlsOptDlgGen *>(m_vdlgv[kidlgGeneral].Ptr()); AssertPtr(ptodg); ptodg->SetDialogValues(m_vuvs, &m_siwndClientDel); // Update the Custom Fields tab. TlsOptDlgCst * ptodc = dynamic_cast<TlsOptDlgCst *>(m_vdlgv[kidlgCustom].Ptr()); AssertPtr(ptodc); ptodc->SetDialogValues(m_vuvs, &m_siwndClientDel, &m_siCustFldDel); int iv1; // Update the Views tab. TlsOptDlgVw * ptodv = dynamic_cast<TlsOptDlgVw *>(m_vdlgv[kidlgViews].Ptr()); AssertPtr(ptodv); if (m_tgv.itabInitial == kidlgViews && m_tgv.iv1 >= 0) { iv1 = m_tgv.iv1; } else { // Use the current view that is selected. Set<int> sisel; pvwbrs->GetSelection(m_qrmw->GetViewbarListIndex(kvbltView), sisel); if (sisel.Size()) iv1 = *sisel.Begin(); else { iv1 = -1; Assert(!qafcrw); } } if (iv1 >= 0) ptodv->SetDialogValues(m_vuvs, &m_siwndClientDel, iv1); // Update the Filters tab. FwFilterDlg * pfltdlg = dynamic_cast<FwFilterDlg *>(m_vdlgv[kidlgFilters].Ptr()); AssertPtr(pfltdlg); if (m_tgv.itabInitial == kidlgFilters && m_tgv.iv1 >= 0) { iv1 = m_tgv.iv1; } else { // Use the current filter that is selected. Set<int> sisel; pvwbrs->GetSelection(m_qrmw->GetViewbarListIndex(kvbltFilter), sisel); if (sisel.Size()) iv1 = *sisel.Begin() - 1; // Subtract one for the No Filter item. else { iv1 = -1; Assert(!qafcrw); } } pfltdlg->SetDialogValues(m_qrmw, Max(0, iv1)); // Update the Sort Methods tab. TlsOptDlgSort * psrtdlg = dynamic_cast<TlsOptDlgSort *>(m_vdlgv[kidlgSortMethods].Ptr()); AssertPtr(psrtdlg); if (m_tgv.itabInitial == kidlgSortMethods && m_tgv.iv1 >= 0) { iv1 = m_tgv.iv1; } else { // Use the current sort method that is selected. Set<int> sisel; pvwbrs->GetSelection(m_qrmw->GetViewbarListIndex(kvbltSort), sisel); if (sisel.Size()) iv1 = *sisel.Begin() - 1; // Subtract one for the No sort item. else { iv1 = -1; Assert(!qafcrw); } } psrtdlg->SetDialogValues(m_qrmw, Max(0, iv1)); // Update the Overlays tab. TlsOptDlgOvr * ptodo = dynamic_cast<TlsOptDlgOvr *>(m_vdlgv[kidlgOverlays].Ptr()); AssertPtr(ptodo); if (m_tgv.itabInitial == kidlgOverlays && m_tgv.iv1 >= 0) { iv1 = m_tgv.iv1; } else { // Use the first overlay that is selected. Set<int> sisel; pvwbrs->GetSelection(m_qrmw->GetViewbarListIndex(kvbltOverlay), sisel); if (sisel.Size()) iv1 = *sisel.Begin() - 1; // Subtract one for the No Overlay item. else { iv1 = -1; Assert(!qafcrw); } } ptodo->SetDialogValues(plpi, Max(0, iv1), (m_tgv.itabInitial == kidlgOverlays && m_tgv.iv2 >= 0) ? m_tgv.iv2 : 0); // WARNING: If this ever gets changed to anything but a fixed length buffer, make sure // ti.pszText is set after loading each string, since the memory pointed to by strb // could be different each time. StrAppBuf strb; TCITEM ti; ti.mask = TCIF_TEXT; ti.pszText = const_cast<achar *>(strb.Chars()); // Add a tab to the tab control for each dialog view. strb.Load(kstidTlsOptCust); TabCtrl_InsertItem(m_hwndTab, kidlgCustom, &ti); strb.Load(kstidTlsOptView); TabCtrl_InsertItem(m_hwndTab, kidlgViews, &ti); strb.Load(kstidTlsOptFltr); TabCtrl_InsertItem(m_hwndTab, kidlgFilters, &ti); strb.Load(kstidTlsOptSort); TabCtrl_InsertItem(m_hwndTab, kidlgSortMethods, &ti); strb.Load(kstidTlsOptOvr); TabCtrl_InsertItem(m_hwndTab, kidlgOverlays, &ti); strb.Load(kstidTlsOptGen); TabCtrl_InsertItem(m_hwndTab, kidlgGeneral, &ti); // This section must be after at least one tab gets added to the tab control. RECT rcTab; ::GetWindowRect(m_hwndTab, &rcTab); TabCtrl_AdjustRect(m_hwndTab, false, &rcTab); POINT pt = { rcTab.left, rcTab.top }; ::ScreenToClient(m_hwnd, &pt); m_dxsClient = pt.x; m_dysClient = pt.y; // Subclass the Help button. AfButtonPtr qbtn; qbtn.Create(); qbtn->SubclassButton(m_hwnd, kctidHelp, kbtHelp, NULL, 0); ShowChildDlg(m_tgv.itabInitial); m_siwndClientDel.Clear(); m_siCustFldDel.Clear(); AfApp::Papp()->EnableMainWindows(false); SetFocus(::GetDlgItem(m_hwnd, kcidTlsOptDlgTab)); return SuperClass::OnInitDlg(hwndCtrl, lp); }