general.h
author viric@llimona
Sun, 07 May 2006 15:28:39 +0200
changeset 16 fe078fb2e8b4
parent 12 a2c334a71a6b
child 17 7c1e68c17c0e
permissions -rw-r--r--
Now I think the code works. There were some indexing mistakse, return instead of continue, etc.

#define BOX '$'
#define WALL '#'
#define MAN '@'
#define PLATFORM '.'
#define BOXINPLATFORM '*'
#define MANINPLATFORM 'E'
#define BLANK ' '
#define CORNER '-'
#define MANCANMOVE '+'

/*#define DEBUG */

enum
{
	ALARM_SECONDS=1,
	MAX_X=50,
	MAX_Y=50,
	MAX_MOVES=50,
	MAX_STEPS=50,
	MAX_BOXES=15
};


enum eBool
{
	TRUE=!0,
	FALSE=0
};
typedef enum eBool Bool;

struct Position
{
	int x;
	int y;
};

#define add_position2(a, b) {a.x += b.x; a.y += b.y;}
#define add_position3(dest, a, b) {(dest).x = (a).x + (b).x; \
				   (dest).y = (a).y + (b).y;}

enum box_freedom
{
	FREE=-1,
	BLOCKED=-2
};

struct tbox_free
{
	/* -1, without dependency in that direction. */
	/* -2, without dependency in that direction. */
	enum box_freedom dep_dir[4];
};

struct Map
{
	char Cells[MAX_Y][MAX_X]; /* Stores WALLs and PLATFORMs */
	char cells_boxes[MAX_Y][MAX_X]; /* Stores the box number in that cell */
					/* -1 is NO BOX there */
	char man_moves[MAX_Y][MAX_X]; /* Stores boxes, walls, MANCANMOVEs */
/*	int boxes[MAX_Y][MAX_X]; */
	int SizeX, SizeY;
	struct Position Man;
	int NumPlatforms;	/* This and the next determine when the game */
	int NumBoxesInPlatform;	/* finished */
	int NumBoxes;
	struct Position Box[MAX_BOXES];	/* The box positions */
	struct tbox_free box_deps[MAX_BOXES];	/* The dependencies for each
						box*/
};


enum e_direction
{
	DIR_DOWN,
	DIR_RIGHT,
	DIR_UP,
	DIR_LEFT
};

static const struct Position move_vectors[4] = {
	{0, 1},
	{1, 0},
	{0, -1},
	{-1, 0}};
#define OPPOSITE_DIR(a) ((a+2)%4)

struct BoxMove
{
	int box;
	struct Position dir;
};


/* Prototypes for map managing
 * map.c */
void CopyMap (struct Map *Mdest, const struct Map *Morig);
int is_new_map(const struct Map maps[], const int depth);

/* Prototypes for unix i/o, processes
 * os.c */
void ReadMap(struct Map *M, char *FileName);
void ShowMap (const struct Map *M);
void init_os();
void PrintMove(struct BoxMove b);
void show_percent_and_map();

/* Functions related to map solution
 * algorithm.c */
int solve_map(const struct Map origin);