/*
 * grid.h	This file defines the grid data structures for 1down.
 *
 * Copyright (C) 1990 Rob Mayoff.
 */

#define	G_MAX_WIDTH	30
#define G_REAL_WIDTH	(G_MAX_WIDTH+3)
#define G_MAX_HEIGHT	30
#define G_REAL_HEIGHT	(G_MAX_HEIGHT+2)
extern
int	G_WIDTH, G_HEIGHT;

/* Some nice, reasonably large number. */
#define MAXWORDS	200

/* Possible grid contents. */
#define SPACE		' '
#define BLOCK		'.'
 
/*
 * First, of course, we must store the characters in the grid.  Hence, an
 * array of characters.  Make each line 1 wider than it needs to be and
 * put a NULL there, so that dbx can print out the array easily (empty
 * squares will have blanks in them, and black boxes will be @'s).
 * Also, we need two spaces on each side so we don't have to worry about
 * boundary checking (we'll fill them with @'s).
 * Hence, the upper left corner of the usable part of the grid is at
 * grid[1][1], not grid[0][0].  The lower right corner is at
 * grid[G_HEIGHT][G_WIDTH], not grid[G_HEIGHT-1][G_WIDTH-1].
 */
typedef	char	grid_t[G_REAL_HEIGHT][G_REAL_WIDTH];

/*
 * grid.c will define the beginning contents of the grid (i.e., where the
 * black boxes are.
 */
extern
grid_t	grid;

/*
 * We will also need to know how many across and down word-spaces there are in
 * the grid, the length of each one, and where it is located.  We can
 * generate this information from the initial contents of the grid.
 * Yes, we could dynamically allocate the across[] and down[] arrays, but I
 * don't feel like it right now.
 */
typedef struct
{
  int	length;			/* Length of this word-space. */
  int	x, y;			/* Position of the beginning of this w-s. */
  int	number;			/* Clue number of this space. */
}	wordSpace_t;
extern
int	numAcross, numDown;
extern
wordSpace_t	across[MAXWORDS], down[MAXWORDS];

/*
 * It would also be useful to have direct lookup to what across- and down-
 * wordspaces "own" each cell of the grid.  We'll have two more grid_t's
 * containing those id's.
 */
extern
grid_t	acrossID, downID;

/*
 * We will have a stack of all spaces in the grid, going out from the upper
 * left corner.
 */
typedef struct
{
  int x, y;
  int acrossID, downID;
  char	order[26];	/* Order in which to place letters into grid. */
}	stackElement_t;
typedef stackElement_t	stack_t[G_MAX_WIDTH*G_MAX_HEIGHT];
extern
stack_t	stack;
extern
int	stackTop;

/*
 * initGrid initializes the grid by filling in the wordSpace arrays; the
 * contents of the grid structure is already filled in (compiled in, to be
 * precise).  It sorts each array in order of word-space length.
 */
extern
void	initGrid(char *fn);
