HS_BOOL8 CHSInterface::LinkExits(HS_DBREF sexit, HS_DBREF dexit) { if (!sexit || !dexit) return false; #ifdef PENNMUSH if (!IsExit(sexit) || !IsExit(dexit)) return false; Location(dexit) = Home(sexit); Location(sexit) = Home(dexit); #endif #if defined(TM3) || defined(MUX) if (!isExit(sexit) || !isExit(dexit)) return false; s_Location(dexit, where_is(sexit)); s_Location(sexit, where_is(dexit)); #endif #ifdef TM3 s_Modified(dexit); s_Modified(sexit); #endif return true; }
void AbstractVM::run(std::ifstream &input) { std::string line; bool exit_present = false; int numLine = 0; try { while (getline(input, line)) { if (isExit(line)) exit_present = true; else _parser.parseStr(line); numLine++; } interpret(_parser.getResult(), _parser.getGrammar()); if (exit_present == false) throw AbstractException("Exit is not present at the end !"); } catch (AbstractException &e) { std::cout << "Line " << numLine + 1 << " : " << e.what() << std::endl; } }
void Labirinth::print(int robot_x, int robot_y) const // print on screen the labirinth // # represent a wall // X represnt the exit point // # represent the robot // blank tiles are represtend by empty spaces { system("clear"); for ( int i = 0; i < x_side + 2; i++ ) { std::cout << "#"; } std::cout << std::endl; for ( int i = 0; i < y_side; i++ ) { std::cout << "#"; for ( int j = 0; j < x_side; j++ ){ if ((j == robot_x) && (i == robot_y)) std::cout << "@"; else if (isExit(j,i)) std::cout << "X"; else if (isWall(j,i)) std::cout << "#"; else std::cout << " "; } std::cout << "#"; std::cout << std::endl; } for ( int i = 0; i < x_side + 2; i++ ) { std::cout << "#"; } std::cout << std::endl; }
void GameManager::start() { while (!isExit() && m_alivePlayersCount > 1) { m_gameCounter++; // assume the game counter is lower than int max value. Sleep(SLEEP_TIME); if (isExit()) { continue; } m_gameBoard.moveArrows(); // move the game players if (m_gameCounter % 2 == 0) { for (int iPlayer = 0; iPlayer < m_alivePlayersCount; iPlayer++) { m_players[iPlayer]->move(); if (m_gameCounter % 15 == 0) { //TODO - implement a shooting algorithm - probably should be in the player class on the shoot method. m_players[iPlayer]->shoot(); } } // TODO - handle more then 2 players if (m_alivePlayersCount > 1) { handleCollision(*(m_players[0]), *(m_players[1])); } } if (m_gameCounter % 4 == 0) { m_gameBoard.addSurprise(); } } if (m_alivePlayersCount == 1) { printWinner(); } }
/** * Print the reference for a basic block. * @param out Output stream. */ void BasicBlock::print(io::Output& out) const { if(isEntry()) out << "ENTRY"; else if(isExit()) out << "EXIT"; else out << "BB " << number() << " (" << address() << ")"; }
int ArroundColor(VertexInfo* map, int current){ int count = 0; for(int i = 0 ; i < numberEdge ; i++){ if(map[current].connection[i] && map[i].color != -1 && !isExit(map,i,current)){ count++; } } return count; }
void HistoricalReplay::processOrders(InstrumentCB & icb, const Tick & tick, bool executeOnLimitOrStop) { // Scan all orders and check for a fill against the current tick for (auto it = std::begin(icb.orders); it != std::end(icb.orders); ++it) { numeric fillPrice; long filledQuantity; long transactionQuantity; long newPosition; long previousPosition = icb.instrumentPosition.position; bool filled = it->tryFill(tick, previousPosition, executeOnLimitOrStop, fillPrice, filledQuantity, transactionQuantity, newPosition); if (filled) { if (filled) { // Update the position icb.instrumentPosition = { newPosition, tick.timestamp }; // Some previous exit orders may need to be cancelled. For instance, if we // just exited a long position, any previous exit orders are cancelled. bool removeExits; if ((previousPosition > 0 && newPosition <= 0) || (previousPosition < 0 && newPosition >= 0)) { removeExits = true; } else { removeExits = false; } // cancel the orders if (removeExits) { for (auto oo = std::begin(icb.orders); oo != it; ++oo) { // Cancel active, exit orders if (oo->isExit() && oo->isActive()) oo->cancel(); } } // Mark the current order as filled it->fill(); // Add a transaction to the portfolio Poco::Logger::root().debug("appending transaction: " + icb.instrument->symbol() + ": " + Poco::DateTimeFormatter::format(tick.timestamp, "%Y-%m-%d") + ": " + Poco::NumberFormatter::format(transactionQuantity) + ", " + Poco::NumberFormatter::format(filledQuantity)); portfolio_.appendTransaction(*icb.instrument, tick.timestamp, transactionQuantity, fillPrice, 0.0); // Add an execution icb.executions.emplace_back(tick.timestamp, fillPrice, filledQuantity); // Add a notification (posted after the order processing loop finishes) icb.orderNotifications.emplace_back(&*it, &icb.executions.back()); } } } }
HS_BOOL8 CHSInterface::UnlinkExits(HS_DBREF sexit, HS_DBREF dexit) { if (!sexit || !dexit) return false; #ifdef PENNMUSH if (!IsExit(sexit) || !IsExit(dexit)) return false; Location(dexit) = NOTHING; Location(sexit) = NOTHING; #endif #if defined(TM3) || defined(MUX) if (!isExit(sexit) || !isExit(dexit)) return false; s_Location(dexit, NOTHING); s_Location(sexit, NOTHING); #endif return true; }
void AbstractVM::run(std::string &str) { static bool exit_present = false; if (found_colon(str) == true && exit_present == false) throw AbstractException("Exit is not present at the end !"); if (isExit(str)) exit_present = true; else if (found_colon(str) == false) _parser.parseStr(str); else if (_parser.getResult().size()) { std::cout << "================= RES =================" << std::endl; interpret(_parser.getResult(), _parser.getGrammar()); } }
int has_flag( dbref player, dbref it, char *flagname ) { FLAGENT *fp; FLAG fv; fp = find_flag( it, flagname ); if( fp == NULL ) { /* find_flag() uppercases the string */ if( !strcmp( flagname, "PLAYER" ) ) { return isPlayer( it ); } if( !strcmp( flagname, "THING" ) ) { return isThing( it ); } if( !strcmp( flagname, "ROOM" ) ) { return isRoom( it ); } if( !strcmp( flagname, "EXIT" ) ) { return isExit( it ); } return 0; } if( fp->flagflag & FLAG_WORD3 ) { fv = Flags3( it ); } else if( fp->flagflag & FLAG_WORD2 ) { fv = Flags2( it ); } else { fv = Flags( it ); } if( fv & fp->flagvalue ) { if( ( fp->listperm & CA_WIZARD ) && !Wizard( player ) ) { return 0; } if( ( fp->listperm & CA_GOD ) && !God( player ) ) { return 0; } /* * don't show CONNECT on dark wizards to mortals */ if( isPlayer( it ) && isConnFlag( fp ) && Can_Hide( it ) && Hidden( it ) && !See_Hidden( player ) ) { return 0; } return 1; } return 0; }
//---------------------------------------------------------------------------- // void TelnetTCPClient::DispatchCommand(QString command) { QString cmd = command.trimmed(); if (isExit(cmd)) { SendResponse( "bye..." ); Socket->close(); return; } QString ret = telnetLogic->ProcessCommand( cmd ); if ( ! ret.isEmpty() ) { SendResponse( ret + strCR ); } }
int main(){ //allocate buffer to read to: char *line = (char*)malloc(MAX_LINE_LENGTH +1); //main loop: while (fgets(line,MAX_LINE_LENGTH,stdin)!=NULL){ if(isExit(line)) { break; } parse(line); //see SP_Aux } printf("Exiting...\n"); free(line); return 0; }
int Controller::getPen(int code) { int result = 0; if (!isExit()) { switch (code) { case 0: // UNTIL PEN(0) - wait until click or move processEvents(EVENT_WAIT_INFINITE, EVENT_TYPE_POINTER_PRESSED); // fallthru case 3: // returns true if the pen is down (and save curpos) if (_touchX != -1 && _touchY != -1) { result = 1; } else { processEvents(EVENT_WAIT_NONE); } break; case 1: // last pen-down x result = _touchX; break; case 2: // last pen-down y result = _touchY; break; case 4: // cur pen-down x case 10: result = _touchCurX; break; case 5: // cur pen-down y case 11: result = _touchCurY; break; } } return result; }
int main(void) { char prompt[100]="$SAM: "; char *input=(char *)malloc(sizeof(char)*100); printf("%s",prompt); gets(input); while(!isExit(input)) { if(isSetPrompt(input)) { char *token = strtok (input," "); token = strtok (NULL, " "); token = strtok (NULL, " "); strcat(token," "); strcpy(prompt,token); } else { system(input); } printf("%s",prompt); gets(input); } }
// Main processing loop for the shell int main(int argc, char **argv) { printf("SMUsh Version 0.1.234\n"); // Allocate outside of the loop for efficiency char *command = NULL; char *param1 = NULL; char *param2 = NULL; char sep[] = " "; char *result = NULL; char part[3][255] = {0}; char input[256] = {0}; // Begin the command processing loop while(true) { // Clear out the storage at the beginning of each loop int i = 0; input[0] = '\0'; part[0][0] = '\0'; part[1][0] = '\0'; part[2][0] = '\0'; // Capture command line input printf("SMUsh> "); scanf("%255[^\n]%*c", input); // parse the input into three separate arguments // Pull the first token from the input result = strtok(input, sep); // Loop through remaining tokens until there are none left while( result != NULL ) { // Copy the result into the argument array strcpy(part[i],result); result = strtok( NULL, sep ); i++; } // Transfer the parts into named storage command = part[0]; param1 = part[1]; param2 = part[2]; // Evaluate the command types and pass the appropriate parameters if(isExit(command)) { printf("Exiting... Thanks for using SMUsh - Scott's Shell.\n"); break; } else if (isCopy(command)) { copy(param1, param2); } else if (isDelete(command)) { delete(param1); } else if (isType(command)) { type(param1); } else if (isExecutable(command)) { execute(command); } else { displayError(command); } } return 0; }
/* * Unit */ void print(std::ostream& os, const IRUnit& unit, const AsmInfo* asmInfo, const GuardConstraints* guards) { // For nice-looking dumps, we want to remember curMarker between blocks. BCMarker curMarker; static bool dotBodies = getenv("HHIR_DOT_BODIES"); auto blocks = rpoSortCfg(unit); // Partition into main, cold and frozen, without changing relative order. auto cold = std::stable_partition(blocks.begin(), blocks.end(), [&] (Block* b) { return b->hint() == Block::Hint::Neither || b->hint() == Block::Hint::Likely; } ); auto frozen = std::stable_partition(cold, blocks.end(), [&] (Block* b) { return b->hint() == Block::Hint::Unlikely; } ); if (dumpIREnabled(kExtraExtraLevel)) printOpcodeStats(os, blocks); // Print the block CFG above the actual code. auto const retreating_edges = findRetreatingEdges(unit); os << "digraph G {\n"; for (auto block : blocks) { if (block->empty()) continue; if (dotBodies && block->hint() != Block::Hint::Unlikely && block->hint() != Block::Hint::Unused) { // Include the IR in the body of the node std::ostringstream out; print(out, block, AreaIndex::Main, asmInfo, guards, &curMarker); auto bodyRaw = out.str(); std::string body; body.reserve(bodyRaw.size() * 1.25); for (auto c : bodyRaw) { if (c == '\n') body += "\\n"; else if (c == '"') body += "\\\""; else if (c == '\\') body += "\\\\"; else body += c; } os << folly::format("B{} [shape=\"box\" label=\"{}\"]\n", block->id(), body); } auto next = block->nextEdge(); auto taken = block->takenEdge(); if (!next && !taken) continue; auto edge_color = [&] (Edge* edge) { auto const target = edge->to(); return target->isCatch() ? " [color=blue]" : target->isExit() ? " [color=cyan]" : retreating_edges.count(edge) ? " [color=red]" : target->hint() == Block::Hint::Unlikely ? " [color=green]" : ""; }; auto show_edge = [&] (Edge* edge) { os << folly::format( "B{} -> B{}{}", block->id(), edge->to()->id(), edge_color(edge) ); }; if (next) { show_edge(next); if (taken) os << "; "; } if (taken) show_edge(taken); os << "\n"; } os << "}\n"; AreaIndex currentArea = AreaIndex::Main; curMarker = BCMarker(); for (auto it = blocks.begin(); it != blocks.end(); ++it) { if (it == cold) { os << folly::format("\n{:-^60}", "cold blocks"); currentArea = AreaIndex::Cold; } if (it == frozen) { os << folly::format("\n{:-^60}", "frozen blocks"); currentArea = AreaIndex::Frozen; } print(os, *it, currentArea, asmInfo, guards, &curMarker); } }
void Room::print(int number) { if (!isExit()) std::cout << to_string(number) << " : " << currentValueDijkstra << std::endl; else std::cout << to_string(number) << " : exit" << std::endl; }
bool QA::init(void) { // Open the qa-result.nc file, when available or create // it from scratch. Meta data checks are performed. // Initialisation of time and time boundary testing. // Eventually, entry() is called to test the data of fields. notes->init(); // safe qaExp.setParent(this); qaTime.setParent(this); // default for the qaFile setFilename( pIn->file ); // apply parsed command-line args applyOptions(); std::string vName(qaExp.getVarnameFromFilename()); if(isRequiredVariable) pIn->pullMetaData('V', vName); if(isRequiredTime && !isRequiredVariable) pIn->pullMetaData('T'); if(isRequiredGlobal) pIn->pullMetaData('G'); initCheckStatus(); // check for CF Convention. if(isCheckCF) { cF->setDataVarName(vName); cF->setFilename(pIn->file); (void) cF->run(); } // exclude user-defined data variables from any checking pIn->excludeVars(); qaTime.init(optStr); qaExp.init(optStr); // DRS specifications if(isCheckDRS_F || isCheckDRS_P) { drs_cv_table.setParent(this); drs_cv_table.setPath(tablePath); drs_cv_table.applyOptions(optStr); drs_cv_table.read(); } // experiment specific obj: set parent, pass over options // check consistency between sub-sequent files or experiments if(isCheckCNSTY && (fileSequenceState == 's' || fileSequenceState == 'x') ) { // return true for a) no previous check available, // b) deviation from a privous check are found if( checkConsistency(*pIn, optStr, tablePath) ) qaExp.run(); } else qaExp.run(); // check existence of any data at all if( pIn->ncRecBeg == 0 && pIn->ncRecEnd == 0 ) { isCheckData=false; std::string key("6_15"); if( notes->inq( key, fileStr) ) { std::string capt("No records in the file") ; if( notes->operate(capt) ) { notes->setCheckStatus(n_data, n_fail ); setExitState( notes->getExitState() ) ; } } } if( isCheckData ) { if( !checkDataBody() ) { isCheckData = false; notes->setCheckStatus(n_data, n_fail); setExitState(2); // return true; } } if(isCheckTimeValues && !qaTime.isTime) notes->setCheckStatus(n_time, "FIXED"); if(isCheckTimeValues) { if( qaTime.isTime) { if( !checkDataBody(qaTime.name) ) { // time is defined, but there is no data qaTime.isTime = false; notes->setCheckStatus(n_time, n_fail); setExitState(2); } } } if(isCheckData || isCheckTimeValues) { notes->setConstraintFreq( qaExp.getFrequency() ); // enable detection of outlier and replicated records setProcessing(); // open netCDF for creating, continuation or resuming qa_<varname>.nc. // note that this must happen before checkMetaData which uses currQARec openQA_Nc(*pIn); if( isExit() || qaExp.isUseStrict || qaTime.isNoProgress ) { isCheckData=false; return true; } } if( isCheckData || isCheckTimeValues ) { // set pointer to function for operating tests // execPtr = &IObj::entry ; (void) entry(); } return true; // only meta-data check }
bool Block::isMainExit() const { return isMain() && isExit(); }
void LevelScene::onKeyboardPressedSDL(SDL_Keycode sdl_key, Uint16) { if(m_doExit || isExit()) return; if(m_isPauseMenu && (m_player1Controller->type() != Controller::type_keyboard)) m_pauseMenu.processKeyEvent(sdl_key); switch(sdl_key) { // Check which case SDLK_ESCAPE: case SDLK_RETURN: // Toggle pause mode case SDLK_AC_BACK: { if(m_isPauseMenu && (m_player1Controller->type() == Controller::type_keyboard)) m_pauseMenu.processKeyEvent(sdl_key); if(m_doExit || m_isPauseMenu) break; m_isPauseMenu = true; break; } case SDLK_BACKQUOTE: { PGE_Debugger::executeCommand(this); break; } default: //Keys allowed only in debug mode! if(PGE_Debugger::cheat_debugkeys) { switch(sdl_key) { case SDLK_1: { if(!m_itemsPlayers.empty()) launchEffect(1, m_itemsPlayers.front()->posX(), m_itemsPlayers.front()->posY(), 0, 2000, 0, 0, 0); } break; case SDLK_2: { if(!m_itemsPlayers.empty()) launchEffect(1, m_itemsPlayers.front()->posX(), m_itemsPlayers.front()->posY(), 0, 2000, 3, -6, 12); break; } case SDLK_3: { if(!m_itemsPlayers.empty()) { Scene_Effect_Phys p; p.decelerate_x = 0.02; p.max_vel_y = 12; LVL_Player *pl = m_itemsPlayers.front(); launchEffect(1, pl->posX(), pl->posY(), 0, 5000, -3, -6, 5, 0, p); launchEffect(1, pl->posX(), pl->posY(), 0, 5000, -4, -7, 5, 0, p); launchEffect(1, pl->posX(), pl->posY(), 0, 5000, 3, -6, 5, 0, p); launchEffect(1, pl->posX(), pl->posY(), 0, 5000, 4, -7, 5, 0, p); } break; } case SDLK_4: { if(!m_itemsPlayers.empty()) { Scene_Effect_Phys p; p.max_vel_y = 12; LVL_Player *pl = m_itemsPlayers.front(); launchEffect(11, pl->posX(), pl->posY(), 0, 5000, 0, -3, 12, 0, p); } break; } case SDLK_5: { if(!m_itemsPlayers.empty()) launchEffect(10, m_itemsPlayers.front()->posX(), m_itemsPlayers.front()->posY(), 1, 0, 0, 0, 0); break; } case SDLK_7: { if(!m_itemsPlayers.empty()) m_itemsPlayers[0]->setCharacterSafe(m_itemsPlayers[0]->characterID - 1, m_itemsPlayers[0]->stateID); break; } case SDLK_8: { if(!m_itemsPlayers.empty()) m_itemsPlayers[0]->setCharacterSafe(m_itemsPlayers[0]->characterID + 1, m_itemsPlayers[0]->stateID); break; } case SDLK_9: { if(m_itemsPlayers.size() >= 2) m_itemsPlayers[1]->setCharacterSafe(2, 1); if(!m_itemsPlayers.empty()) m_itemsPlayers[0]->setCharacterSafe(m_itemsPlayers[0]->characterID, m_itemsPlayers[0]->stateID - 1); break; } case SDLK_0: { if(m_itemsPlayers.size() >= 2) m_itemsPlayers[1]->setCharacterSafe(2, 2); else if(!m_itemsPlayers.empty()) m_itemsPlayers[0]->setCharacterSafe(m_itemsPlayers[0]->characterID, m_itemsPlayers[0]->stateID + 1); break; } case SDLK_F5: { PGE_Audio::playSoundByRole(obj_sound_role::PlayerMagic); m_isTimeStopped = !m_isTimeStopped; break; } case SDLK_F6: { PGE_Audio::playSoundByRole(obj_sound_role::CameraSwitch); m_debug_slowTimeMode = !m_debug_slowTimeMode; break; } case SDLK_F7: { PGE_Audio::playSoundByRole(obj_sound_role::WorldOpenPath); m_debug_oneStepMode = !m_debug_oneStepMode; break; } case SDLK_F8: { if(m_debug_oneStepMode) { PGE_Audio::playSoundByRole(obj_sound_role::WorldMove); m_debug_oneStepMode_doStep = true; } break; } default: break; }//switch(sdl_key) }//if(PGE_Debugger::cheat_debugkeys) }//switch(sdl_key) }