int execGame(World w) { printWorld(&w); while (1) { sleepMillis(100); step(&w); printWorld(&w); printf("\x1B[2J"); // Escape-Sequenz (Löscht den Bildschirm) } }
int main(int argc, char* argv){ memset(world,0,sizeof(world)); int i; char c; rNum = 0; int trash = scanf("%d %d\n",&maxX,&maxY); while ((trash = scanf("%d %d %c\n", &x, &y, &orientation)) != -1){ rNum++; bool result = performAction(orientation); c = getchar(); while (c != '\n' && c != EOF && result){ result = performAction(c); c = getchar(); } if (c != '\n' && c != EOF) flushLine(); if (!result){ printf("%d %d %c LOST\n",x,y, orientation); } else { printf("%d %d %c\n",x,y,orientation); } } printWorld(); return 0; }
/* MAIN */ int main(int argc, char **argv){ if(argc < 6){ printf("ERROR: too few arguments.\n"); fflush(stdout); /* force it to go out */ exit(1); } FILE* input = fopen(argv[1], "r"); if(input == NULL){ printf("ERROR: file does not exist.\n"); fflush(stdout); /* force it to go out */ exit(1); } wolfBreedingPeriod = atoi(argv[2]); squirrelBreedingPeriod = atoi(argv[3]); wolfStarvationPeriod = atoi(argv[4]); int noOfGenerations = atoi(argv[5]); loadWorld(input); // fprintf(stdout, "Initial world configuration after loading from file:\n"); // fflush(stdout); /* force it to go out */ // printWorld2d(stdout); /* pressEntertoContinue(); */ worldLoop(noOfGenerations); printWorld(); fclose(input); return 0; }
// Start writing data to files, set up ncurses // if necessary, and print simulation details // if verbose is enabled void Sim::initializeIO() { static bool initialized = false; if( !initialized ) { initialized = true; // Take an initial census writeCensus(); // Set the time for the most recent progress report // printout to "a long time ago and well overdue" // (i.e., never). lastProgressUpdate = 0; if( o->gui == Options::GUI_NCURSES ) { #ifdef HAVE_NCURSES // Initialize ncurses initscr(); // Print extra information about the simulation if( o->verbose ) { screen << "Press Ctrl-c to quit." << std::endl; screen << "------" << std::endl; printEles( &screen ); screen << std::endl; printRxns( &screen ); screen << std::endl; printExtincts( &screen ); screen << "------" << std::endl; } scrX = 0; scrY = 0; getyx( stdscr, scrY, scrX ); printWorld(); #endif } else { // Print extra information about the simulation if( o->verbose ) { std::cout << "Press Ctrl-c to quit." << std::endl; std::cout << "------" << std::endl; printEles( &std::cout ); std::cout << std::endl; printRxns( &std::cout ); std::cout << std::endl; printExtincts( &std::cout ); std::cout << "------" << std::endl; } } } }
/* * Main */ int main(int argc, char *argv[]) { // Parse command line if(!optparse(argc, argv)) abort(); /* Nanosleep Setup */ int milisec = 250; // length of time to sleep, in miliseconds struct timespec req = {0}; req.tv_sec = 0; req.tv_nsec = milisec * 1000000L; // Initialisieren der Welt und den Zellen world_t world; /* Allocate Memory */ allocateMemory(&world); /* Welt befüllen */ if(path) { read_world(&world, path); } else if (!create_world(&world)) { printf("error creating world\n"); exit(-2); } else { fillWorld(&world); } /* Welt ausgeben */ printWorld(&world); /* * Nächster Schritt ausführen * TODO: Beenden der Schleife wenn sich nichts mehr ändert */ while (true) { (automode) ? nanosleep(&req, (struct timespec *)NULL) : bwait(); nextStep(&world); printWorld(&world); } return 0; }
/** Author: Joel Denke Description: Init the world by loading map and players */ void initWorld() { int i; mapLoad(&gameWorld, MAP_FILE); drawGraphics(); for (i = 0; i < no_players; i++) { initPlayer(i, connection); } printWorld(); state = gRunning; }
int main(){ if ((blocks = getNumberOfBlocks()) == 0) return 0; initializeWorld(); int params_read, a, b; char cmd[4], cmd2[4]; int initial_r,initial_c; while ((params_read = scanf("%s %d %s %d\n",cmd,&a,cmd2,&b)) > 0){ if (params_read == 1 && strcmp(cmd,"quit")) break; else if (a != b && !inSameStack(a,b)){ int command = getCommand(cmd,cmd2); switch (command){ case MOVE_ONTO: find(b,&initial_r,&initial_c); if (returnBlocks(a) != 0) return 1; if (returnBlocks(b) != 0) return 2; if (move(a,b,initial_r,initial_c) != 0) return 3; break; case MOVE_OVER: find(b,&initial_r,&initial_c); if (returnBlocks(a) != 0) return 1; if (move(a,b,initial_r,initial_c) != 0) return 3; break; case PILE_ONTO: find(b,&initial_r,&initial_c); if (returnBlocks(b) != 0) return 1; if (move(a,b,initial_r,initial_c) != 0) return 3; break; case PILE_OVER: find(b,&initial_r,&initial_c); if (move(a,b,initial_r,initial_c) != 0) return 3; break; default: break; } } } printWorld(); return 0; }
int main(void) { char mORs, yesNo; struct wmpCaveST wmpCave[DUODEC + 1]; struct wmpHntrST wmpHntr; system("clear"); progSalutatn('S', "Hunt The Wumpus"); srand((unsigned) time(NULL)); #if DEBUG_MODE printf("---------- DEBUG_MODE: ON ---------------\n\n"); #endif printf("Welcome to my lair!\n"); printf("Would you like to play a game (y or n)? "); scanf(" %c", &yesNo); if (yesNo != 'y') { printf("Coward! Begone then.\n"); goto leave; }//if while (true) { //user want to play printf("Would you like a game description (y or n)> "); scanf(" %c", &yesNo); if (yesNo == 'y') { wumpusDescription(); }//if user wants instructions initWumpusGame(wmpCave, &wmpHntr); printf("\nStart new game.\n"); printf("-----------------------------------------------\n"); while (true) { //game is in progress printf("You are in cave %d\n", wmpHntr.hntrCaveSV); printf("There are tunnels to caves %d %d %d\n", wmpCave[wmpHntr.hntrCaveSV].wmpTunnlsSV[0], wmpCave[wmpHntr.hntrCaveSV].wmpTunnlsSV[1], wmpCave[wmpHntr.hntrCaveSV].wmpTunnlsSV[2]); if (pitNearby(wmpCave, &wmpHntr)) { printf("It's drafty here!\n"); }//if printf("move (m) or shoot (s)> "); scanf(" %c", &mORs); if (mORs == 'm') { if (processMove(wmpCave, &wmpHntr)) { continue; }//if hunter did not die else { break; }//else hunter killed }//if move //------------ Debug: printWorld() on 'p' press -------- #if DEBUG_MODE else if (mORs == 'p'){ printWorld(wmpCave); continue; } #endif //------------------------------------------------------ else { if (processShoot(wmpCave, &wmpHntr)) { continue; }//if hunter or wumpus did not die else { break; }//else either hunter or wumpus died }//else shoot }//while game in progress printf("\n"); printf("Would you like to play again? (y or n)> "); scanf(" %c", &yesNo); if (yesNo == 'y') { continue; }//if user want to play again else { break; }//else user does not want to play again }//while user wants to play leave: printf("\n"); progSalutatn('E', "Hunt The Wumpus"); double anyNmbr; printf("Enter any number to exit> "); scanf("%lf", &anyNmbr); system("clear"); }//main()
std::string Viewer::printWorld(const Maze &maze,const Mouse *mouse) const{ return printWorld(maze,mouse,std::vector<MazeCellNode *>()); }
int main(int argc, char **argv) { #ifdef USE_MPI MPI_Init(&argc, &argv); #endif if (argc != 5) { LOG_ERROR("I want width, height, zombies, iterations.\n"); #ifdef USE_MPI MPI_Finalize(); #endif exit(1); } int width = atoi(argv[1]); int height = atoi(argv[2]); int people = (int) (width * height * INITIAL_DENSITY); int zombies = atoi(argv[3]); int iters = atoi(argv[4]); initRandom(0); WorldPtr input, output; double ratio = divideWorld(&width, &height, &input, &output); // there should not be any output prior to this point #ifdef REDIRECT initRedirectToFiles(input); #endif LOG_DEBUG("World size is %d x %d at position [%d, %d] of %d x %d\n", input->localWidth, input->localHeight, input->globalX, input->globalY, input->globalColumns, input->globalRows); if (input->globalX == 0 && input->globalY == 0) { randomDistribution(input, people * ratio, zombies, 0); } else { // no zombies elsewhere randomDistribution(input, people * ratio, 0, 0); } #ifndef NIMAGES printWorld(input, false); #endif Timer timer = startTimer(); Stats cumulative = NO_STATS; for (int i = 0; i < iters; i++) { simulateStep(input, output); output->stats.clock = cumulative.clock = output->clock; Stats stats = output->stats; mergeStats(&cumulative, stats, false); printStatistics(output, cumulative); WorldPtr temp = input; input = output; output = temp; input->stats = stats; } double elapsedTime = getElapsedTime(timer); #ifdef _OPENMP int numThreads = omp_get_max_threads(); #else int numThreads = 1; #endif LOG_TIME("Simulation took %f milliseconds with %d threads\n", elapsedTime, numThreads); // this is a clean up // we destroy both worlds destroyWorld(input); destroyWorld(output); destroyRandom(); #ifdef REDIRECT finishRedirectToFiles(); #endif #ifdef USE_MPI MPI_Finalize(); #endif }