/* Set of functions to read and print a maze data structure */

#ifndef __MAZE_H__
#define __MAZE_H__

#include "position.h"


typedef /* Various states a maze cell may be in */
enum cell { OPEN, BLOCKED, VISITED, START, END }
  cell_t;

/* Maze structure with dimensions height x width. Maze cells are a height*width
   contiguous block of memory in row-major order (offset = width*row + col). */
typedef struct maze {
  int height;
  int width;
  position_t start;
  position_t end;
  cell_t* cells;
} maze_t;


/* Read a maze from the given file stream pointer.
   Produces: p_maze, pointer to a dynamically allocated maze_t 
   Pre-conditions:
     - stream != NULL
     - stream is open for reading and positioned at the beginning of a properly-
       formatted maze (see accompanying documentation).
   Post-conditions: 
     - p_maze refers to a maze with the configuration given by stream
     - No cell in p_maze->cells is marked VISITED.
     - p_maze == NULL when maze data in stream is improperly formatted
     - Prints an informative error to stderr and aborts the program when memory
       cannot be allocated for the maze and its cells.
   Practica
     - To reclaim the dynamically allocated memory, call freeMaze(p_maze)
*/
maze_t*
readMaze(FILE* stream);

/* Print a maze visualization to standard output
   Pre-condition: p_maze points to a valid maze_t structure
   Post-condition: 
     A p_maze->height x p_maze->width representation of the maze is printed to
     stdout, with the following cell->char mappings:
       open   ' '
       blocked X
       visited .
       start   @
       end     $
*/
void
printMaze(const maze_t* p_maze);

/* Free the dynamically allocated memory associated with a maze_t pointer.
   Pre-conditions: p_maze is a non-NULL value returned from readMaze.
   Post-conditions: All dynamically allocated memory used by p_maze is freed
*/
void
freeMaze(maze_t * p_maze);

#endif
