//---------------------------------------------- bool myDepthGenerator::update(){ if (!bUpdateXtion[thisNum]) return; bool isNewDataAvailable = false; if (depth_generator.IsNewDataAvailable()) { depth_generator.WaitAndUpdateData(); depth_generator.GetMetaData(dmd); generateCurrentDepth(); generateTexture(); generateRealWorld(realWorld); isNewDataAvailable = true; } checkSwitchMethods(); counter++; return isNewDataAvailable; }
int main(int argc, char *argv[]) { int realWorld[NOCOLS][NOROWS]; // Array of ints holding real world map int agentWorld[NOCOLS][NOROWS]; // Array of ints holding agents world map int x, y; // Counters struct coord currentCoord; // Current position coordinates struct coord start = {0, 0}; // Starting position // Initialize random number generator seed srand((unsigned int)time(0)); // Initialize both worlds to zero. for(y=0; y<NOROWS; y++){ for(x=0; x<NOCOLS; x++){ realWorld[x][y] = 0; agentWorld[x][y] = 0; } } // Generate realWorld. generateRealWorld(realWorld); // Generate agentWorld setFlag(agentWorld, start, CURRENT); // Initialy player is at (0,0) // Set current coordinates currentCoord = start; // Display real world puts("R E A L W O R L D"); displayWorldAll(realWorld); int count = 0; while(1){ printf("\n============================================================\n"); count++; // Update current coordinates currentCoord = getCurrentCoord(agentWorld); // If current field isn't visited, process sensor data if(testFlag(agentWorld, currentCoord, VISITED) == 0){ // Read sensors and update agents map of the world copyFlags(realWorld,agentWorld,currentCoord); // Check is cave or wumpus here, if it is then game over, else process sensors if(testFlag(agentWorld, currentCoord, CAVE)){ // Display agent world printf("\nA G E N T W O R L D (Step %d)\n",count); printf("Current position (%d,%d):\n", currentCoord.x, currentCoord.y); displayWorldAll(agentWorld); puts("\nWent down the cave. GAME OVER!"); break; } else if(testFlag(agentWorld,currentCoord,WUMPUS)){ // Display agent world printf("\nA G E N T W O R L D (Step %d)\n",count); printf("Current position (%d,%d):\n", currentCoord.x, currentCoord.y); displayWorldAll(agentWorld); puts("\nWumpus had a good meal. GAME OVER!"); break; } else if(testFlag(agentWorld,currentCoord,GLOW)){ // Display agent world printf("\nA G E N T W O R L D (Step %d)\n",count); printf("Current position (%d,%d):\n", currentCoord.x, currentCoord.y); displayWorldAll(agentWorld); puts("\nCongratulate! You have found gold! Nice!"); break; } else{ // Mark current coordinates as visited and remove safe setFlag(agentWorld, currentCoord, VISITED); // Evaluate neighbors and set appropriate flags evaluateNeighbors(agentWorld,currentCoord); } } // Display agent world printf("\nA G E N T W O R L D (Step %d)\n",count); printf("Current position (%d,%d):\n", currentCoord.x, currentCoord.y); displayWorldAll(agentWorld); if(takeGlowAction(agentWorld, currentCoord)){ printf("This move is recommended by takeGlowAction method!\n"); } else if(takeSafeAction(agentWorld, currentCoord)){ printf("This move is recommended by takeSafeAction method!\n"); } else if(takeRollTheDiceAction(agentWorld, currentCoord)){ printf("This move is recommended by takeRollTheDiceAction method!\n"); } else if(takeSuicideAction(agentWorld, currentCoord)){ printf("This move is recommended by takeSuicideAction method, situation was hopeless!\n"); } // sleep(2); myPause(); } myPause(); return EXIT_SUCCESS; }