// maj des scnarios a partir du fichier void Game::updateScenar(){ scenar.clear(); //Parcours du dossier Scenar/ et ajout au jeu DIR* rep = opendir("Scenario/"); if(rep == NULL){ cout << "ERREUR DOSSIER SCENARIO NOT FOUND" << endl; return; } struct dirent* fichier = NULL; string comp = "txt"; string badswp = "~"; string nameF; string dir = "Scenario/"; size_t found; while ((fichier = readdir(rep)) != NULL){ nameF = dir + fichier->d_name; found = nameF.find(badswp); if (found!=std::string::npos){ }else{ found = nameF.find(comp); if (found!=std::string::npos){ Scenario *s = new Scenario(); s->load(nameF); scenar.push_back(*s); } } } closedir(rep); }
void DlgCScenarioManager::OnSave() { // TODO: Add your command handler code here HTREEITEM hItem = m_tree.GetSelectedItem(); if(hItem == NULL) return; DWORD key = m_tree.GetItemData(hItem); Scenario *pScenario = m_manager.LookUp(key); BOOL bRet = TRUE; PersistentModel model; PersistentMgr persistentMgr; bRet = m_manager.SaveCurModel(model.GetScenarioPersist(),pScenario); if(bRet) { static TCHAR BASED_CODE szFilter[] = _T("AFT原始数据(*.imp)|*.imp|PFA计算文件(*.calc)|*.calc|All Files (*.*)|*.*||"); CFileDialog dlg(FALSE,_T("imp"),pScenario->GetName(),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter); if(IDOK == dlg.DoModal()) { persistentMgr.Save(dlg.GetPathName(),model); } } }
void DlgCScenarioManager::OnCreatChild() { // TODO: Add your command handler code here HTREEITEM hItem = m_tree.GetSelectedItem(); if(hItem == NULL) return; //根据key值找到对应的工况 DWORD key = m_tree.GetItemData(hItem); Scenario *pScenario = GetCurScenario(); DlgScenarioName dlg; if(IDOK == dlg.DoModal()) { //检查名称没有存在子工况则增加一个子工况 CString strName = dlg.GetName(); if(pScenario->CheckName(strName)) { InsertTree(m_manager.AddChildScenario(pScenario,strName),hItem); InitPage(); UpdateData(FALSE); } else { AfxMessageBox(IDS_NAMEERROR); } } }
/* FileClose: Handles user close request. */ void FileClose(HWND sheet, HWND control) { HWND page = (HWND)SendMessage(sheet, PSM_GETCURRENTPAGEHWND, 0, 0); int sel = IDYES; if (!control) SendMessage(page, AOKTS_Closing, 0, 0); if (scen.needsave()) { sel = MessageBox(sheet, "Do you want to save your changes?", "Save", MB_YESNOCANCEL); if (sel == IDYES) FileSave(sheet, false, true); else if (sel == IDCANCEL) return; //stop closing } scen.reset(); *setts.ScenPath = '\0'; if (!control) SendMessage(page, AOKTS_Loading, 0, 0); SetSaveState(sheet, MF_ENABLED); SetWindowText(propdata.statusbar, "Scenario reset."); SendMessage(propdata.mapview, MAP_Reset, 0, 0); SetWindowText(sheet, szTitle); }
std::string Calaos::get_new_scenario_id() { int cpt = 0; bool found = true; list<Scenario *> autosc = ListeRoom::Instance().getAutoScenarios(); while (found && autosc.size() > 0) { list<Scenario *>::iterator it = autosc.begin(); bool found2 = false; for (;it != autosc.end() && !found2;it++) { Scenario *sc = *it; if (sc->get_param("auto_scenario") == "scenario_" + Utils::to_string(cpt)) found2 = true; } if (found2) cpt++; else found = false; } string ret = "scenario_" + Utils::to_string(cpt); return ret; }
void Scenario::reposiciona(Scenario& reference) { if(position.getX()+width<=0) { setPosition(reference.getPosition().getX() + reference.getWidth() + speed.getX(),position.getY()); } }
Viewer::Viewer(Scenario & s) : scenario(s), clickDisabled(false) { items = s.getItemSequence(); periodMs = s.getPeriodMs(); index = 0; imageLabel = new Image; imageLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); distractor = 0; if (scenario.getMode() == MODE_DIVIDED_ATTENTION_VISUAL) { distractor = new QLabel(this); const QImage img("Data/lutin.png"); const QPixmap p = QPixmap::fromImage(img); int w = width()/4; int h = height()/4; // set a scaled pixmap to a w x h window keeping its aspect ratio distractor->setPixmap(p.scaled(w, h, Qt::KeepAspectRatio)); distractor->hide(); } else if (scenario.getMode() == MODE_DIVIDED_ATTENTION_SOUND) { // nothing at this stage } else distractor = 0; nDistractor = 0; descriptionLabel = 0; setWindowTitle(QString("ji") + VERSION); showFullScreen(); start(); }
void Municao::insertCenario(Scenario &cenario){ cenario.insert(*this); cenario.insert(spark); cenario.insert(light); cenario.insert(bala); }
void ListeRoom::checkAutoScenario() { list<Scenario *>::iterator it = auto_scenario_cache.begin(); for (;it != auto_scenario_cache.end();it++) { Scenario *sc = *it; if (sc->getAutoScenario()) sc->getAutoScenario()->checkScenarioRules(); } list<Rule *> to_remove; for (int i = 0;i < ListeRule::Instance().size();i++) { Rule *rule = ListeRule::Instance().get_rule(i); if (rule->param_exists("auto_scenario") && !rule->isAutoScenario()) to_remove.push_back(rule); } list<Rule *>::iterator itr = to_remove.begin(); for (;itr != to_remove.end();itr++) ListeRule::Instance().Remove(*itr); //Resave config, auto scenarios have probably created/deleted ios and rules Config::Instance().SaveConfigIO(); Config::Instance().SaveConfigRule(); }
//-------------------------------------------- //Parameters: // return: // Memo: 将this工况的子工况保存的父工况改为this // //--------------------------------------------- void Scenario::ChangeAncestor() { POSITION pos = m_childList.GetHeadPosition(); Scenario *pChild = NULL; while(pos) { pChild = m_childList.GetNext(pos); pChild->m_pAnScenario = this; pChild->ChangeAncestor(); } }
//-------------------------------------------- //Parameters: strName[In] 工况名称 // return: 当前增加的工况 // Memo: 复制this工况包括子孙工况增加一个名称为strName的兄弟工况 // //--------------------------------------------- Scenario * Scenario::CloneWithChild(CString strName) { Scenario *pClone = CloneWithOutChild(strName); POSITION pos = m_childList.GetHeadPosition(); Scenario *pChild = NULL; while(pos) { pChild = m_childList.GetNext(pos); pClone->m_childList.AddTail(new Scenario(*pChild)); } pClone->ChangeAncestor(); return pClone; }
//-------------------------------------------- //Parameters: strName[In] 工况名称 // return: 如果this工况存在名称为strName的子工况返回Ture // Memo: 检查strName是否被this工况的子工况使用 // //--------------------------------------------- BOOL Scenario::CheckName(CString strName) { BOOL bRet = TRUE; POSITION pos = m_childList.GetHeadPosition(); Scenario *pChild = NULL; while(pos) { pChild = m_childList.GetNext(pos); if(0 == strName.Compare(pChild->GetName())) { bRet = FALSE; } } return bRet; }
bool ScenarioMapLoader::load(const std::string& filename, Scenario& oScenario) { std::fstream f(filename.c_str(), std::ios::in | std::ios::binary); _d->initClimate(f, oScenario.getCity()); _d->loadMap(f, oScenario); _d->initEntryExit(f, oScenario.getCity()); _d->initCameraStartPos(f, oScenario.getCity()); f.close(); return true; }
CString DlgCScenarioManager::DefaultName(Scenario *pScenario) { Scenario *pAnScenario = pScenario->GetAnScenario(); CString strName = pScenario->GetName(); CString strNewName; if(pAnScenario != NULL) { int i = 2; do { strNewName.Format(_T("%s(%d)"),strName,i); i++; } while(!pAnScenario->CheckName(strNewName)); } return strNewName; }
/* DisplayStats: Fills out controls for statistics dialog. */ BOOL DisplayStats(HWND dialog) { // TODO: split this into model/view UINT total = 0, i; UINT ne = 0, nc = 0; Trigger *t_parse; Player *p_parse; /* total enabled players */ SetDlgItemInt(dialog, IDC_S_PLAYERS, scen.getPlayerCount(), FALSE); /* Units (including buildings, GAIA stuff, etc.) */ total = 0; p_parse = scen.players; for (i = 0; i < NUM_PLAYERS; i++, p_parse++) { int count = p_parse->units.size(); if (i <= GAIA_INDEX) SetDlgItemInt(dialog, IDC_S_UNITS1 + i, count, FALSE); total += count; } SetDlgItemInt(dialog, IDC_S_UNITS, total, FALSE); /* Disabled (techs only) */ total = 0; p_parse = scen.players; for (i = 0; i < NUM_PLAYERS; i++, p_parse++) { int count = p_parse->ndis_t; if (i <= GAIA_INDEX) SetDlgItemInt(dialog, IDC_S_DISABLE1 + i, count, FALSE); total += count; } SetDlgItemInt(dialog, IDC_S_DISABLE, total, FALSE); /* total triggers */ SetDlgItemInt(dialog, IDC_S_TRIGGERS, scen.triggers.size(), FALSE); /* total effects & conditions */ total = scen.triggers.size(); if (total > 0) { t_parse = &(*scen.triggers.begin()); while (total--) { ne += t_parse->effects.size(); nc += t_parse->conds.size(); t_parse++; } } SetDlgItemInt(dialog, IDC_S_CONDITIONS, nc, FALSE); SetDlgItemInt(dialog, IDC_S_EFFECTS, ne, FALSE); /* map size (why here?) */ SetDlgItemInt(dialog, IDC_S_MAPSIZE, scen.map.x, FALSE); return TRUE; }
GraphPanel::GraphPanel(const QString & username, const Scenario & refScenario) { graph = new Graph(); graph->setFixedSize(QSize(800, 200)); resize(800, 600); User u; u.load(username.toStdString()); std::vector<Scenario> sList = refScenario.getSameScenario(u.getScenarioList()); std::vector<int> clickSpeedCurve = getClickSpeedCurve(sList); Axis clickAxis; clickAxis.side = LEFT; clickAxis.labels << tr("Lent") << tr("Rapide"); graph->addCurve(clickSpeedCurve, 0, 2000, tr("Vitesse de click"), true, clickAxis); Axis gradeAxis; gradeAxis.side = RIGHT; gradeAxis.labels << tr("0 %") << tr("100 %"); std::vector<int> correctnessCurve = getGlobalGradeCurve(sList); graph->addCurve(correctnessCurve, 0, 100, tr("Réussite"), false, gradeAxis); // do the grid grid = new QVBoxLayout(this); grid->addWidget(graph); // add divide attention graph if (refScenario.modeInhibition == MODE_DIVIDED_ATTENTION_SOUND || refScenario.modeInhibition == MODE_DIVIDED_ATTENTION_VISUAL) { std::vector<int> distractorCurve = getDistractorCurve(sList); graph = new Graph(GR_HISTOGRAM, 2); // green color graph->setFixedSize(QSize(800, 200)); Axis axis; axis.side = LEFT; axis.labels << tr("-10") << tr("10"); graph->addCurve(distractorCurve, -10, 10, tr("Écart distracteurs"), false, axis); grid->addWidget(graph); } table = createTable(sList); grid->addWidget(table); closeButton = createButton(tr("Fermer"), SLOT(close())); grid->addWidget(closeButton); setLayout(grid); setWindowTitle(QString("ji") + VERSION); showFullScreen(); }
void ScreenGame::setScenario(Scenario& scenario) { _d->scenario = &scenario; CityPtr city = scenario.getCity(); Tilemap& tilemap = city->getTilemap(); _d->mapArea.init( tilemap ); _d->mapRenderer.init( city, _d->mapArea, this); }
void VerkeersRegelaar::doeWachtrij() { while(wachtrijbeheerder->geefEersteInWachtrij() != 0) { //Wanneer er iets in de wachtrij staat wordt de loop doorlopen Scenario* scenario = wachtrijbeheerder->geefEersteInWachtrij(); //Het eerste scenario uit de wachtrij wordt gegeven scenario->zetAllesNaarGroen(); //In het scenario alles naar groen zetten for (int n = 0; n < variabelebeheerder->krijgVariabele('g'); n++) _delay_ms(1000); //Een bepaalde tijd wachten scenario->zetAllesNaarRood(); //En alles weer naar rood laten gaan wachtrijbeheerder->haalEersteUitWachtrij(); //Het eerste scenario uit de wachtrij halen for (int n = 0; n < variabelebeheerder->krijgVariabele('r'); n++) _delay_ms(1000); //En 5 sec wachten voordat het volgende scenario op groen gaat if(variabelebeheerder->krijgNacht() == true) //Checken of het onderhand nacht is, zo ja dan moet er uit de functie worden gesprongen return; } }
std::map<std::string, Result*> Suite::RunScenarios() { std::map<std::string, Result*> results; // coverage_.Clear(); // will accumulate this for(std::vector<Scenario*>::iterator itr = scenarios_.begin(); itr < scenarios_.end(); ++itr) { Scenario* scenario = (*itr); printf("Running scenario %s\n", scenario->name()); Result* result = scenario->Explore(); safe_assert(Config::ExitOnFirstExecution >= 0 || result != NULL); if(result != NULL) { // accumulate coverage // if(result->IsSuccess()) { // coverage_.AddAll(static_cast<SuccessResult*>(result)->coverage()); // } results[scenario->name()] = result; printf("\nDone with scenario %s. Result: %s\n", scenario->name(), (result->IsSuccess() ? "SUCCESS" : "FAILURE")); } } return results; }
void indexScenario(const Scenario& scenario, InquiryToReplies& inquiryToReplies) { int index = 0; int counter = 0; bool isInSaying = 0; InquiryToReply inquiryToReply; std::for_each( scenario.begin(), scenario.end(), [&inquiryToReplies, &inquiryToReply, &index, &counter, &isInSaying](const ScriptLine& line) { LineRange& inquiry = inquiryToReply.first; LineRange& reply = inquiryToReply.second; if (isLine<SAYING>(line)) { if (counter % 2 == 0) { inquiry.lower = index; inquiry.upper = index; reply.lower = -1; } if (counter % 2 == 1) { reply.lower = index; reply.upper = index; } isInSaying = true; ++counter; } else if (!isMarkedLine(line) && isInSaying) { if (reply.lower == -1) { inquiry.upper++; } else { reply.upper++; } } else if (isMarkedLine(line) && isInSaying && reply.lower != -1) { inquiryToReplies.insert(inquiryToReply); isInSaying = false; } else { isInSaying = false; } ++index; }); }
//-------------------------------------------- //Parameters: nKey[In] 工况的唯一标记Key // return: // Memo: 查找this工况的子孙工况的唯一标记Key=nKey的工况 // //--------------------------------------------- Scenario* Scenario::LookUp(int nKey) { if(m_nKey == nKey) { return this; } else { POSITION pos = m_childList.GetHeadPosition(); Scenario *pChild = NULL; Scenario *pFind = NULL; while(pos) { pChild = m_childList.GetNext(pos); pFind = pChild->LookUp(nKey); if(pFind != NULL) break; } return pFind; } }
/** * Handles a user request to dump triggers to textual format. */ void OnFileTrigWrite(HWND dialog) { char path[MAX_PATH] = "trigs.xml"; // TODO: set the path to aokts directory. if (!GetSaveFileNameA(dialog, path, MAX_PATH)) return; AutoFile textout(path, "w"); std::ostringstream ss; scen.accept(TrigXmlVisitor(ss)); fputs(ss.str().c_str(), textout.get()); }
int WorldInfo::chooseScenarioByScore(void) { Scenario *AScenario; if(this->score>=3) { AScenario = new FullDefence(); this->pActiveScenario=AScenario; AScenario->displayInfo(); return AScenario->ID; } if(this->score<=-2) { AScenario = new Rush(); this->pActiveScenario=AScenario; AScenario->displayInfo(); return AScenario->ID; } AScenario = new FlankAttack(); this->pActiveScenario=AScenario; AScenario->displayInfo(); return AScenario->ID; }
void VerkeersRegelaar::doeStandaardSequentie() { //Deze functie voert de standaard sequentie uit for (int i = 1; scenariolijst->geefPositie(i) != 0; i++) { //Doorloop alle scenario's omstebeurt Scenario* scenario = scenariolijst->geefPositie(i); scenario->zetAllesNaarGroen(); //In het scenario alles naar groen zetten for (int n = 0; n < variabelebeheerder->krijgVariabele('g'); n++) _delay_ms(1000); //Een bepaalde tijd wachten scenario->zetAllesNaarRood(); //En alles weer naar rood laten gaan for (int n = 0; n < variabelebeheerder->krijgVariabele('r'); n++) _delay_ms(1000); //En 5 sec wachten voordat het volgende scenario op groen gaat int j = i + 1; if(scenariolijst->geefPositie(j) == 0) //Checken of de volgende positie in scenariolijst een scenario bevat i = 0; //Zo niet, dan begint de lijst weer van voor af aan //i wordt op 0 gezet ipv op 1 omdat aan het eind van de loop er eentje wordt opgeteld //Wanneer er iets in de wachtrij staat of wanneer het nacht is moet er uit deze functie gesprongen worden if((wachtrijbeheerder->geefEersteInWachtrij() != 0) || variabelebeheerder->krijgNacht()) return; } }
int main() { Scenario s; Action & a1 = s.getAction(0); Action & a2 = s.getAction(1); Action & a3 = s.getAction(2); a1.setUnit(1); a1.setCommand(5); a1.setTime(625); a2.setUnit(2); a2.setCommand(8); a2.setTime(234); a3.setUnit(3); a3.setCommand(1); a3.setTime(1400); cout << s; return 0; }
void VerkeersRegelaar::komtUitNachtStand() { //Deze functie wordt aangeroepen bij de overgang van nacht naar dag //Alle scenario's worden eenmalig langsgelopen in hun vaste patroon //Eerst wordt van alle scenario's alle verkeerslichten op rood gezet for (int i = 1; scenariolijst->geefPositie(i) != 0; i++) { Scenario* scenario = scenariolijst->geefPositie(i); scenario->allesDirectRood(); } for (int n = 0; n < variabelebeheerder->krijgVariabele('r'); n++) _delay_ms(1000); //Vijf seconden wachten for (int i = 1; scenariolijst->geefPositie(i) != 0; i++) { //Doorloop alle scenario's omstebeurt Scenario* scenario = scenariolijst->geefPositie(i); scenario->zetAllesNaarGroen(); //In het scenario alles naar groen zetten for (int n = 0; n < variabelebeheerder->krijgVariabele('g'); n++) _delay_ms(1000); //Een bepaalde tijd wachten scenario->zetAllesNaarRood(); //En alles weer naar rood laten gaan wachtrijbeheerder->haalUitWachtrij(scenario); for (int n = 0; n < variabelebeheerder->krijgVariabele('r'); n++) _delay_ms(1000); //En 5 sec wachten voordat het volgende scenario op groen gaat } }
void extractScenarios(const std::string& script, Scenarios& scenarios) { int braceCounter = 0; Scenario scenario; std::vector<ScriptLine> lines = tokenizeInLines(script); std::for_each(lines.begin(), lines.end(), [&scenarios, &scenario, &braceCounter](ScriptLine& line) { boost::trim(line.content); if (isLine<CLOSE_SCENARIO>(line)) { --braceCounter; } if (braceCounter == 1) { scenario.push_back(line); } if (isLine<START_SCENARIO>(line)) { ++braceCounter; } if (braceCounter == 0) { if (!scenario.empty()) scenarios.push_back(scenario); scenario.clear(); } }); }
void GameController::init() { std::srand(std::time(NULL)); // Place the enemies and Pengo all over the free spaces std::vector< std::pair<int,int> > freePositions = scenario.getFreeMapPositions(); int size = freePositions.size(); if (size < GAMECONTROLLER_MIN_ENEMIES + 1) { throw std::string("Mapa não permite criação dos elementos do jogo"); } int randomPosition; for (int i=0; i<GAMECONTROLLER_MIN_ENEMIES + 1; i++) { randomPosition = std::rand() % size; std::pair<int,int> &newPosition = freePositions[randomPosition]; if (i == 0) { this->penguin = scenario.createPenguinAt(newPosition.first, newPosition.second); } else { this->enemies.push_back(scenario.createEnemyAt(newPosition.first, newPosition.second)); } size--; freePositions.erase(freePositions.begin() + randomPosition); } // Place the items inside random moblie blocks std::vector< std::pair<int,int> > mobileBlocksPos = scenario.getMobileBlockPositions(); int sizeBlocks = mobileBlocksPos.size(); if (sizeBlocks < GAMECONTROLLER_MIN_ITEMS) { throw std::string("Mapa não permite criação dos itens nos blocos"); } for (int i=0; i<GAMECONTROLLER_MIN_ITEMS; i++) { randomPosition = std::rand() % sizeBlocks; std::pair<int,int> chosenBlockPos = mobileBlocksPos[randomPosition]; if (i < (GAMECONTROLLER_MIN_ITEMS/2)) { scenario.createItemInsideBlockAt(chosenBlockPos.first, chosenBlockPos.second, ITEM_KIND_PLUS_SPEED); } else { scenario.createItemInsideBlockAt(chosenBlockPos.first, chosenBlockPos.second, ITEM_KIND_PLUS_CONCEPTION); } sizeBlocks--; mobileBlocksPos.erase(mobileBlocksPos.begin() + randomPosition); } }
// // Calculate a cut as // g_omega = -Transp( T_omega ) * pi // where // g_omega is the cutting plane, // Transp( T_omega ) is technology matrix transpose, // pi is either a row of basis inverse, or a dual // vector of the first stage problem. // void RD_SubproblemSolver::CalculateGradient( Real_T *grad, Int_T n, // ) Array<Real_T> &pi, const Scenario &Scen ) const { Ptr<Real_T> a; Ptr<Int_T> row; Int_T j, len; //-------------------------------------------------------------------------- // First calculate the basis part of the gradient vector. // for( j = 0; j < n; j++ ) { Real_T &g = grad[j]; g = 0.0; for( LP.T_base.GetColumn( j, a, row, len ); len; --len, ++a, ++row ) g -= *a * pi[*row]; } //-------------------------------------------------------------------------- // Then calculate the scenario-dependent part. // Int_T l = Scen.GetLength(); for( j = 0; j < l; j++ ) for( Int_T i = 0, bl = Scen[j].Len(); i < bl; i++ ) { const Delta &d = Scen[j][i]; if( d.type == Delta::MATRIX ) { assert( d.col >= 0 && d.col < n ); grad[ d.col ] -= pi[ d.row ] * d.value; } } }
void DlgCScenarioManager::OnReName() { // TODO: Add your command handler code here HTREEITEM hItem = m_tree.GetSelectedItem(); if(hItem == NULL) return; //根据key值找到对应的工况 DWORD key = m_tree.GetItemData(hItem); Scenario *pScenario = m_manager.LookUp(key); Scenario *pAnScenario = pScenario->GetAnScenario(); DlgScenarioName dlg; dlg.m_strName = pScenario->GetName(); if(IDOK == dlg.DoModal()) { CString strName = dlg.GetName(); if(pAnScenario != NULL) { if(pAnScenario->CheckName(strName)) { pScenario->SetName(strName); m_tree.SetItemText(hItem,strName); UpdateData(FALSE); } else { AfxMessageBox(IDS_NAMEERROR); } } else { pScenario->SetName(strName); m_tree.SetItemText(hItem,strName); UpdateData(FALSE); } } }