# README for `output` library ## Overview The `output` library holds programs necessary to output to the console (ASCII UI and move updates) and the logfile (move updates and current avatar positions). It contains the following modules: * `gui` (graphical user interface methods) * `logfile` (used for printing to console and logfile) ## Implementation Strategy #### `gui` ```c typedef struct grid { char **matrix; int maze_width; int maze_height; int grid_width; int grid_height; int num_avatars; } grid_t; /**************** getter functions *****************/ int grid_get_maze_width(grid_t *grid); int grid_get_maze_height(grid_t *grid); /**************** other functions *****************/ grid_t *grid_new(int maze_width, int maze_height, int num_avatars); void grid_update(grid_t *grid, XYPos prev_location, XYPos new_location, int id); void grid_add_wall(grid_t *maze, XYPos maze_location, int direction); void print_separator(FILE *fp, grid_t *grid); bool valid_direction(int direction); bool vertical_direction(int direction); bool horizontal_direction(int direction); void grid_set_point(grid_t *grid, XYPos point, char filler); void grid_print(grid_t *maze, FILE *fp); bool point_within_maze(grid_t *grid, XYPos point); void grid_delete(grid_t *grid); XYPos get_adjacent_point(XYPos start, int direction); ``` The `gui` class contains all the methods necessary for making a graphical user interface. It includes the `grid_t` struct and a variety of helpful methods. See the header file for more information, but the following is a summary: * `grid_t`: holds a matrix to represent the grid, the maze height and width, and the grid height and width (because the grid also contains room for walls). The ASCII GUI relies on this for all functionality * `grid_get_maze_width`: returns the `maze_width` attribute of the provided grid or -1 if the grid is null * `grid_get_maze_height`: Returns the `maze_height` attribute of the provided grid or -1 if the grid is null * `grid_new`: Provided a maze width and height and the number of avatars, creates a grid structure with these values * `grid_update`: Updates the provided grid based on the provided current and last location of the avatar with the given id. * `grid_add_wall`: Provided a grid, a pointer to the XYPos for the place from which a move is being attempted (in maze coordinates), and the direction in which the move was attempted to be made, adds a wall (which will be drawn based on the direction that the attempted move was made in). * `print_separator`: Provided a grid, prints a line of `SEPARATOR_CHAR` (global variable) to separate different prints of the maze * `valid_direction`: Provided a direction, checks if it's a valid way in which one can move. If so, returns true; otherwise, returns false * `vertical_direction`: Returns true if the provided integer direction is vertical and false if not * `horizontal_direction`: Returns true if the provided integer direction is horizontal and false if not * `grid_set_point`: Provided a grid, a point converted to the grid coordinate system, and a character, sets the point in the grid to the character (if the point is inside of the grid) * `grid_print`: Prints the ASCII graphical user interface given the provided grid structure (which represents the maze) to the provided file * `point_within_maze`: Provided a grid and a point in maze coordinate form, checks if the point is inside of the grid by converting to maze coordinates and then calling `point_within_grid` * `grid_delete`: Provided a grid, deletes it by freeing each row of the double matrix and then freeing the entire grid structure * `get_adjacent_point`: Given a point and the direction in which the move should be made, returns the adjacent point to the provided point in the provided direction (used for finding wall locations in gui.c and for finding adjacent maze points in avatar.c) #### `logfile` ```c void write_action(char *log_file, Avatar *avatar, XYPos point, uint32_t last_move, grid_t *GRID); void write_positions (char *log_file, hashtable_t *discovered_paths, int n_avatars); void write_insert(char *log_file, int avatar_id, XYPos point, grid_t *grid); void write_maze_solved(char *log_file); void write_error(char *log_file, uint32_t message_type); ``` The `logfile` class contains the methods necessary to update the grid and print to `stdout` and the logfile. Its methods include: * `write_action`: Provided the name of the log file, the avatar that moved, the point to which it moved (converted to a usable format), the last move made, the hashtable of invalid points, and the grid, writes the action to the graphics and the log file * `write_positions`: Provided the name of the log file, a hashtable of discovered paths, and the number of avatars, writes the positions of each avatar to the log file. * `write_insert`: Provided the name of the log file, the id of the avatar that was inserted, the point at which it was inserted, and the graphics grid struct for the class, prints out messages stating that the avatar has been inserted, inserts the avatar into the grid, and prints the grid * `write_maze_solved`: Provided the name of the log file, writes a message to indicate that the maze is solved * `write_error`: Provided the name of the log file and a uint32_t for the message type, writes an error ## Compilation To build, run `make`. To clean up, run `make clean`.