// Pantea Aria // Robot Explorer – Space Station Adventure // A large program to help with assignment 1 // starter code #include // Provided Constants #define INVALID_INDEX -1 #define MAP_ROWS 8 #define MAP_COLUMNS 8 // User defined constants go here // Provided enums and structs enum floor_type { SAFE, RADIATION }; enum item_type { EMPTY, ENERGY }; struct location { enum item_type item; enum floor_type floor; }; // User defined enums and structs // Provided function prototypes void initialise_station(struct location station[MAP_ROWS][MAP_COLUMNS]); void print_station( struct location station[MAP_ROWS][MAP_COLUMNS], int robot_row, int robot_col, int energy_count, int damage_count ); void print_location(struct location location, int floor_layer, int print_robot); void print_floor_type(enum floor_type floor); void print_item_type(enum item_type item); // User defined function prototypes int main(void) { struct location station[MAP_ROWS][MAP_COLUMNS]; initialise_station(station); print_station(station, INVALID_INDEX, INVALID_INDEX, 0, 0); printf("Enter robot starting location: "); // TODO: scan in starting position printf("\nExplore the station and collect energy cells!\n"); // TODO: movement loop printf("System shutting down...\n"); return 0; } // STARTER FUNCTIONS BELOW THIS POINT ////////////////////////// // Initialises the station with empty items and safe floors // Hard codes some energy cells and radiation void initialise_station(struct location station[MAP_ROWS][MAP_COLUMNS]) { int row = 0; while (row < MAP_ROWS) { int col = 0; while (col < MAP_COLUMNS) { station[row][col].floor = SAFE; station[row][col].item = EMPTY; col++; } row++; } // Hard-coded items and hazards station[0][1].item = ENERGY; station[1][1].item = ENERGY; station[7][7].item = ENERGY; station[5][1].item = ENERGY; station[0][1].floor = RADIATION; station[7][6].floor = RADIATION; station[0][2].floor = RADIATION; station[0][3].floor = RADIATION; } // Prints the station map and game statistics // Each row prints two lines: // top line shows robot or item // bottom line shows floor type void print_station( struct location station[MAP_ROWS][MAP_COLUMNS], int robot_row, int robot_col, int energy_count, int damage_count ) { printf("==== Robot Explorer ====\n"); printf("========================\n"); for (int row = 0; row < MAP_ROWS * 2; row++) { for (int col = 0; col < MAP_COLUMNS; col++) { int print_robot = 0; if (robot_row == row / 2 && robot_col == col) { print_robot = 1; } print_location(station[row / 2][col], row % 2, print_robot); } printf("\n"); } printf("========================\n"); printf("Energy: %2d Damage: %2d\n", energy_count, damage_count); printf("========================\n\n"); } // Prints a single location (used by print_station) void print_location( struct location location, int floor_print, int print_robot ) { if (floor_print) { print_floor_type(location.floor); } else { if (print_robot) { printf("(R)"); } else { print_item_type(location.item); } } } // Prints the floor type void print_floor_type(enum floor_type floor) { if (floor == SAFE) { printf(" . "); } else if (floor == RADIATION) { printf(" X "); } else { printf(" ? "); } } // Prints the item type void print_item_type(enum item_type item) { if (item == EMPTY) { printf(" "); } else if (item == ENERGY) { printf(" E "); } else { printf(" ? "); } }