void simulateStep(WorldPtr input, WorldPtr output) { output->clock = input->clock + 1; sendRecieveBorder(input); simulateStep1(input, output); // while waiting for input border sendRecieveBorderFinish(input); simulateStep2(input, output); // this needs input with border sendReceiveGhosts(output); resetWorld(input); // while waiting for ghost cell movement sendReceiveGhostsFinish(output); }
/* * Instructions on using this program: * * 'H' - hardware viewing and perspective transforms * 'O' - orthographic projection mode * 'P' - perspective projection mode * 'I' - reset to original setup * * In each mode, pressing the 'l', 'k', 'w' keys * makes the transformation in the 'forward' direction, * pressing 'h', 'j', 's' makes the transformation in the * 'reverse' direction. You are required to implement this * functionality. Look at the kbd() function to see how * the various functions are called. * */ void kbd(unsigned char key, int x, int y) { switch(key) { case 'q': /* quit */ case 27 : glutDestroyWindow(wd); exit (0); case 'I': /* reset */ cam = Camera(eye_pos0, gaze_dir0, top_dir0, zNear0, zFar0, fovy0); resetWorld(mode); setup_view(mode); transformWorld(mode); // TODO do the transform, including perspective transform in objects.cpp fprintf(stderr, "Reset!\n"); break; case 'H': mode = HARDWARE; init_viewcam(mode); reshape(screen_w, screen_h); fprintf(stderr, "Hardware transforms\n"); break; case 'O': mode = ORTHOGRAPHIC; init_viewcam(mode); reshape(screen_w, screen_h); fprintf(stderr, "Orthographic mode\n"); break; case 'P': mode = PERSPECTIVE; init_viewcam(mode); reshape(screen_w, screen_h); fprintf(stderr, "Perspective mode\n"); break; default: movecam(key, x, y); // TODO in transfomrs.cpp setup_view(mode); // TODO set up the viewing transformation in transforms.cpp transformWorld(mode); // TODO do the transform, including perspective transform in objects.cpp break; } glutPostRedisplay(); return; }
/** * doMove * * This function applies the command received from the Supervisor to the * world and returns the resulting sensor string * * @arg command An integer representing the command to complete * @return A pointer to char buffer containing the sensor string to return */ char* doMove(int command) { /* If the spot is empty, then it will contain a 0, else it will contain one of the two rewards. If a wall is there we won't move into it. So first we check for a wall in our destination. If free, we first gather the reward in the location (0,5,10) Then we add that to the running score, free our current location, and move into the destination square. */ g_reward = 0; // Reset here just in case a wall is in our way // Switch on the command that was received to update world appropriatelY switch(command) { // Left and Right just turn the Roomba case CMD_MOVE_N: if(!g_statsMode) printf("Move north...\n"); if(g_world[g_X][g_Y - 1] != V_E_WALL) { g_reward = g_world[g_X][g_Y - 1]; g_score += g_reward; g_world[g_X][g_Y] = V_E_EMPTY; g_Y--; g_world[g_X][g_Y] = V_E_AGENT; }//if else if(!g_statsMode) printf("Cannot complete command.\n"); break; case CMD_MOVE_S: if(!g_statsMode) printf("Move south...\n"); if(g_world[g_X][g_Y + 1] != V_E_WALL) { g_reward = g_world[g_X][g_Y + 1]; g_score += g_reward; g_world[g_X][g_Y] = V_E_EMPTY; g_Y++; g_world[g_X][g_Y] = V_E_AGENT; }//if else if(!g_statsMode) printf("Cannot complete command.\n"); break; case CMD_MOVE_E: if(!g_statsMode) printf("Move east...\n"); if(g_world[g_X + 1][g_Y] != V_E_WALL) { g_reward = g_world[g_X + 1][g_Y]; g_score += g_reward; g_world[g_X][g_Y] = V_E_EMPTY; g_X++; g_world[g_X][g_Y] = V_E_AGENT; }//if else if(!g_statsMode) printf("Cannot complete command.\n"); break; case CMD_MOVE_W: if(!g_statsMode) printf("Move west...\n"); if(g_world[g_X - 1][g_Y] != V_E_WALL) { g_reward = g_world[g_X - 1][g_Y]; g_score += g_reward; g_world[g_X][g_Y] = V_E_EMPTY; g_X--; g_world[g_X][g_Y] = V_E_AGENT; }//if else if(!g_statsMode) printf("Cannot complete command.\n"); break; case CMD_NO_OP: if(!g_statsMode) printf("No operation...\n"); break; case CMD_EATERS_RESET: printf("Reset Eaters environment...\n"); resetWorld(); break; default: if(!g_statsMode) printf("Invalid command: %i\n", command); break; }//switch g_numMoves++; //Print the reward for data collection if (g_statsMode) printf("%d\n", g_reward); if(!g_statsMode) displayWorld(); return setSenseString(command); }//doMove