/* CITS1210 1st Project 2008 Name: Student number: Date: */ #error Did you fill in your name and student number? #include "valetpark.h" // ----------------------------------------------------------------- // Global variable definitions // You should not need to add to this list CARPARK carpark; // ----------------------------------------------------------------- // Functions /* isValidLocation(l) returns true iff l represents a location within the bounds of the carpark. */ static bool isValidLocation(LOCATION l) { return true; } /* isValidCarparkEntry(c) returns true iff c is a valid character that can appear in the "grid part" of a carpark-file. */ static bool isValidCarparkEntry(char c) { return true; } /* trimLine(line) removes any trailing new-line or carriage-return characters from the end of line. */ static void trimLine(char line[]) { } /* readCarparkFile(filename) reads the contents of the file named filename as a carpark-file, "filling" the global carpark variable with information read from the file. The function exits the program with EXIT_FAILURE if the file is an invalid carpark-file or if the corresponding grid would be too large to store in the global carpark variable. */ static void readCarparkFile(char filename[]) { } /* getValue(l) returns the character representing the car segment occupying location l in the carpark. The function terminates the program if the location is not valid (i.e. outside the bounds of the carpark). */ static char getValue(LOCATION l) { return EMPTY; } /* setValue(l, value) sets location l in the carpark to value. The function exits the program with EXIT_FAILURE if the location is invalid (i.e. outside the bounds of the carpark). Additionally, unless the function is used to "free-up" the location (set the location to EMPTY), the function also exits the program with EXIT_FAILURE if the location is already occupied by another car. */ static void setValue(LOCATION l, char value) { } /* printCarpark(void) prints the current contents of the carpark, printing the rectangular grid of characters held in the global carpark variable. */ static void printCarpark(void) { /* Your printCarpark() function only has to print the carpark as text, but if developing in CSSE Lab 2.01 you may like to use this code: #if defined(__APPLE__) carparkGUI(); #endif */ } /* isEmpty(l) returns true iff location l is empty (i.e. no car segment resides at that location in the grid). */ static bool isEmpty(LOCATION l) { return true; } /* moveCarOneBay(car, d, c) attempts to move the indicated car in indicated direction by one bay, returning true iff the car was able to successfully complete the move. The requested move is performed (and the carpark updated to reflect the move) iff the car can move in the given direction, the movement does not take the car outside the bounds of the carpark, and there is no other car at the destination location. */ static bool moveCarOneBay(char car, DIRECTION d, CARINFO c) { return false; } /* findCar(car) locates car within the carpark, returning information about the location, orientation, and length of the car. The function terminates the program if the car is not located within the carpark. */ static CARINFO findCar(char car) { CARINFO thiscar; return thiscar; } /* moveCar(car, d, amount) attempts to move the car in direction d by the indicated amount, returning the actual number of bays the car is able to move in that direction. The requested movement is performed (and the carpark updated to reflect the movement) iff the corresponding car can perform the requested move, otherwise no movement of the car is performed (and zero is returned). The requested movement is also constrained to ensure the car does not collide with any other car and that the car remains within the bounds of the carpark. */ static int moveCar(char car, DIRECTION d, int amount) { return 0; } /* hasExited(void) returns true iff my car has exited (i.e. any segment of my car is at the exit location). */ static bool hasExited(void) { return false; } // This function is provided - no need to modify it static void printPrompt(void) { if(isatty(0)) { static int n=0; printf("move %d> ", ++n); fflush(stdout); } } /* processMoves(void) reads movement commands, processing each command, in turn, to move the corresponding car within the carpark. Each movement command is constrained to ensure the corresponding car does not collide with any other car and that the car remains within the bounds of the carpark. A movement command is performed (and the carpark updated to reflect the movement) iff the corresponding car can move in the given direction. At the completion of each movement command (regardless of whether the command lead to actual movement), the current state of the carpark is printed. The function completes immediately if a movement command leads to my car exiting. The function exits the program with EXIT_FAILURE if any command is invalid. */ static void processMoves(void) { } // ----------------------------------------------------------------- // The main function - no need to change this int main(int argc, char *argv[]) { /* Exit with an error if the the number of arguments (including the program's name) is not 2 */ if(argc != 2) { fprintf(stderr, "Usage: %s carpark-file\n", argv[0]); exit(EXIT_FAILURE); } else { // Read the initial configuration of the carpark from file readCarparkFile(argv[1]); // Print the contents of the carpark printf("The initial carpark from '%s' is:\n", argv[1]); printCarpark(); /* Process user-provided moves, updating the carpark after each valid move */ processMoves(); // Print the contents of the final carpark printf("The final carpark is:\n"); printCarpark(); // Finished successfully! exit(EXIT_SUCCESS); } /* NOTE: all of the required functions have been defined as 'static', meaning that they may not be accessed from outside of this file. Because of this, gcc complains if we don't actually call each function. This 'silly' bit of code, below, appears to call every required function (although it will never actually execute). When *your* code eventually calls each required function, you should remove this bit of code. */ if(false) { LOCATION nowhere; CARINFO thiscar; char line[1]; isValidLocation( nowhere ); isValidCarparkEntry('?'); trimLine(line); getValue( nowhere ); setValue( nowhere , '?'); isEmpty( nowhere ); moveCarOneBay('?', NORTH, thiscar); moveCar('?', NORTH, 0); hasExited(); printPrompt(); } return 0; }