// DFS, walk the game-tree: bool tryNextPiece(int depth) { char *word[]={"plain","flip","rot","rotFlip"}; Piece piece; int i,dir=0; #ifdef VERBOSE printf("Try depth(%d)\n",depth); #endif if (stackEmpty()) { // we've won! recurse-out answer printf("Winning!\n"); printf("BoardState:\n"); printPiece(board); printf("--~~~--\nunwinding solution:\n"); return true; } piece = popPiece(); i=tryDir(piece,5,depth); // Horizontal bits if (i>=0) goto weWin; //flip piece dir++; i=tryDir(flip(piece),5,depth); if (i>=0) goto weWin; // rot: dir++; i=tryDir(rot(piece),1,depth); if (i>=0) goto weWin; // rotFlip: dir++; i=tryDir(flipRot(piece),1,depth); if (i>=0) goto weWin; // not sure about this returning pieces bussiness... pushPiece(piece); // but each piece gotta be somewhere // so it makes somekindof sense... return false; weWin: printf("uw [%d]\n",depth); switch (dir){ case 0: printPiece(piece<<(5*i)); break; case 1: printPiece(flip(piece)<<(5*i)); break; case 2: printPiece(rot(piece)<<i); break; case 3: printPiece(flipRot(piece)<<i); break; } printf("Direction: %s, offset: %d\n",word[dir],i); return true; }
/* * This function is lifted from Simple Directmedia Layer (SDL): * http://www.libsdl.org/ */ static void tryDir(const char *d, PHYSFS_StringCallback callback, void *data) { BDirectory dir; dir.SetTo(d); if (dir.InitCheck() != B_NO_ERROR) return; dir.Rewind(); BEntry entry; while (dir.GetNextEntry(&entry) >= 0) { BPath path; const char *name; entry_ref e; if (entry.GetPath(&path) != B_NO_ERROR) continue; name = path.Path(); if (entry.GetRef(&e) != B_NO_ERROR) continue; if (entry.IsDirectory()) { if (strcmp(e.name, "floppy") != 0) tryDir(name, callback, data); } /* if */ else { bool add_it = false; int devfd; device_geometry g; if (strcmp(e.name, "raw") == 0) /* ignore partitions. */ { int devfd = open(name, O_RDONLY); if (devfd >= 0) { if (ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0) { if (g.device_type == B_CD) { char *mntpnt = getMountPoint(name); if (mntpnt != NULL) { callback(data, mntpnt); allocator.Free(mntpnt); /* !!! FIXME: lose this malloc! */ } /* if */ } /* if */ } /* if */ } /* if */ } /* if */ close(devfd); } /* else */ } /* while */ } /* tryDir */
/* * This function is lifted from Simple Directmedia Layer (SDL): * https://www.libsdl.org/ ... this is zlib-licensed code, too. */ static void tryDir(const char *d, PHYSFS_StringCallback callback, void *data) { BDirectory dir; dir.SetTo(d); if (dir.InitCheck() != B_NO_ERROR) return; dir.Rewind(); BEntry entry; while (dir.GetNextEntry(&entry) >= 0) { BPath path; const char *name; entry_ref e; if (entry.GetPath(&path) != B_NO_ERROR) continue; name = path.Path(); if (entry.GetRef(&e) != B_NO_ERROR) continue; if (entry.IsDirectory()) { if (strcmp(e.name, "floppy") != 0) tryDir(name, callback, data); continue; } /* if */ const int devfd = open(name, O_RDONLY); if (devfd < 0) continue; device_geometry g; const int rc = ioctl(devfd, B_GET_GEOMETRY, &g, sizeof (g)); close(devfd); if (rc < 0) continue; if (g.device_type != B_CD) continue; char mntpnt[B_FILE_NAME_LENGTH]; if (getMountPoint(name, mntpnt, sizeof (mntpnt))) callback(data, mntpnt); } /* while */ } /* tryDir */
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data) { tryDir("/dev/disk", cb, data); } /* __PHYSFS_platformDetectAvailableCDs */
int sc_main(int argc, char ** argv){ sc_report_handler::set_actions("/IEEE_Std_1666/deprecated", SC_DO_NOTHING); system("set SC_SIGNAL_WRITE_CHECK=\"DISABLE\""); printHeader(); for (int i = 1; i< argc; i++) { string args = string(argv[i]); if (args == "-f") { i++; if (i<argc && argv[i][0] !='-') ga_configPath = string(argv[i]); else { cout << "Argument to '-f' is missing" << endl; return 0; } } else if (args == "-e") { i++; if (i<argc && argv[i][0] !='-') ga_elfPath = string(argv[i]); else { cout << "Argument to '-e' is missing" << endl; return 0; } } else{ cout << args <<" Recognized option" << endl; return 0; } } char nirgamHomeTempStr[100]; g_nirgamHome = rwDirInLinuxStyl(string(getcwd(nirgamHomeTempStr, 100))); g_configHome = getDirOfFile(ga_configPath); if(loadConfig(ga_configPath) == false) return 1; if(checkConfig() == false) return 1; printConfig(cout); tryDir(gc_resultHome); g_clkPeriod = 1/gc_simFreq; g_simPeriod = g_clkPeriod * gc_simNum; g_clock = new sc_clock("NW_CLOCK",g_clkPeriod, SC_NS); g_a = analyze(gc_topoFile, cout); if(g_a == NULL){ cout << "Error occurred. Exit Simulation" << endl; return 1; } g_tileNum = g_a->nodeNum; if (gc_simMode == 1) initStandardMode(); else if (gc_simMode == 2) initDebugMode(); else if (gc_simMode == 3) initSelfcheckMode(); NoC noc("noc", g_a); noc.switch_cntrl(*g_clock); g_tracker = new Tracker(); g_tracker->addProbes(noc); g_tracker->printRouteTables(); ////////////////////////////////////////////////////////////////////////// // soclib tile #ifdef SL_TILE if (gc_tileType == 1){ cerr << "SLNIRGAM is used for soclib IP" << endl; return 1; } sc_start(sc_time(0, SC_NS)); g_resetN = false; sc_start(sc_time(1, SC_NS)); g_resetN = true; #else if (gc_tileType == 2){ cerr << "NIRGAM is used for generic IP" << endl; return 1; } #endif ////////////////////////////////////////////////////////////////////////// if (gc_simMode == 1) doStandardMode(); else if (gc_simMode == 2) doDebugMode(); else if (gc_simMode == 3) doSelfcheckMode(); if (gc_simMode == 1) finaStandardMode(); else if (gc_simMode == 2) finaDebugMode(); else if (gc_simMode == 3) finaSelfcheckMode(); }
void CEngine::parseEvent() { print_debug(DEBUG_ANALYZER, "in parseEvent()"); if (event.movementBlocker) { // notify renderer to remove all the unnecessary line drawn commandQueue.dequeue(); toggle_renderer_reaction(); return; } if (event.name != "") { print_debug(DEBUG_ANALYZER, "Converting Room Name to ascii format"); latinToAscii( event.name); last_name = event.name; } if (event.desc != "") { print_debug(DEBUG_ANALYZER, "Converting Description to ascii format"); latinToAscii( event.desc ); last_desc = event.desc; } if (event.exits != "") { last_exits = event.exits; } if (event.terrain != -1) { last_terrain = event.terrain; } setMgoto( false ); /* if we get a new room data incoming, mgoto has to go away */ print_debug(DEBUG_ANALYZER, "Entering the main part of the function"); print_debug(DEBUG_ANALYZER, "ANALYZER Event. \r\nNAME %s\r\nDESC %s\r\nEXITS %s\r\nBLIND %i, MOVEMENT %i SCOUT %i", (const char *) event.name, (const char *) event.desc, (const char *) event.exits /*(const char *) event.prompt*/, event.blind, event.movement, event.scout); if (event.scout) { print_debug(DEBUG_ANALYZER, "SCOUT flag is set. Dropping event"); return; } if (event.name.indexOf("It is pitch black...") == 0) { print_debug(DEBUG_ANALYZER, "NO light BLIND set"); event.blind = true; } if (event.name == "" && event.movement == true) { print_debug(DEBUG_ANALYZER, "NAME is empty and Movement is true. Assuming BLIND"); event.blind = true; } if (event.name == "" && event.blind == false) { print_debug(DEBUG_ANALYZER, "EMPTY name and no blind set. Assuming addedroom-data update incoming."); if (addedroom) { addedroom->setTerrain(last_terrain); resetAddedRoomVar(); toggle_renderer_reaction(); } return; } if (event.movement == true) { last_movement = event.dir; if (event.dir =="") { tryAllDirs(); // command's queue is useless then, no? commandQueue.clear(); } else { tryDir(); } } else { if (event.name != "") tryLook(); } swap(); if (stacker.amount() == 0) resync(); print_debug(DEBUG_ANALYZER, "Done. Sending an event to the Renderer"); toggle_renderer_reaction(); }