general.h
changeset 12 a2c334a71a6b
parent 10 9148590f009d
child 17 7c1e68c17c0e
equal deleted inserted replaced
11:dcfe4d2d4387 12:a2c334a71a6b
     6 #define MANINPLATFORM 'E'
     6 #define MANINPLATFORM 'E'
     7 #define BLANK ' '
     7 #define BLANK ' '
     8 #define CORNER '-'
     8 #define CORNER '-'
     9 #define MANCANMOVE '+'
     9 #define MANCANMOVE '+'
    10 
    10 
    11 /* #define DEBUG */
    11 /*#define DEBUG */
    12 
    12 
    13 enum
    13 enum
    14 {
    14 {
    15 	ALARM_SECONDS=1,
    15 	ALARM_SECONDS=1,
    16 	MAX_X=50,
    16 	MAX_X=50,
    19 	MAX_STEPS=50,
    19 	MAX_STEPS=50,
    20 	MAX_BOXES=15
    20 	MAX_BOXES=15
    21 };
    21 };
    22 
    22 
    23 
    23 
    24 enum logic
    24 enum eBool
    25 {
    25 {
    26 	TRUE=1,
    26 	TRUE=!0,
    27 	FALSE=0
    27 	FALSE=0
    28 };
    28 };
       
    29 typedef enum eBool Bool;
    29 
    30 
    30 struct Position
    31 struct Position
    31 {
    32 {
    32 	int x;
    33 	int x;
    33 	int y;
    34 	int y;
    34 };
    35 };
    35 
    36 
       
    37 #define add_position2(a, b) {a.x += b.x; a.y += b.y;}
       
    38 #define add_position3(dest, a, b) {(dest).x = (a).x + (b).x; \
       
    39 				   (dest).y = (a).y + (b).y;}
       
    40 
       
    41 enum box_freedom
       
    42 {
       
    43 	FREE=-1,
       
    44 	BLOCKED=-2
       
    45 };
       
    46 
       
    47 struct tbox_free
       
    48 {
       
    49 	/* -1, without dependency in that direction. */
       
    50 	/* -2, without dependency in that direction. */
       
    51 	enum box_freedom dep_dir[4];
       
    52 };
       
    53 
    36 struct Map
    54 struct Map
    37 {
    55 {
    38 	char Cells[MAX_Y][MAX_X];
    56 	char Cells[MAX_Y][MAX_X]; /* Stores WALLs and PLATFORMs */
    39 	char cells_boxes[MAX_Y][MAX_X];
    57 	char cells_boxes[MAX_Y][MAX_X]; /* Stores the box number in that cell */
    40 	char man_moves[MAX_Y][MAX_X];
    58 					/* -1 is NO BOX there */
       
    59 	char man_moves[MAX_Y][MAX_X]; /* Stores boxes, walls, MANCANMOVEs */
       
    60 /*	int boxes[MAX_Y][MAX_X]; */
    41 	int SizeX, SizeY;
    61 	int SizeX, SizeY;
    42 	struct Position Man;
    62 	struct Position Man;
    43 	int NumPlatforms;
    63 	int NumPlatforms;	/* This and the next determine when the game */
    44 	int NumBoxesInPlatform;
    64 	int NumBoxesInPlatform;	/* finished */
    45 	struct Position Box[MAX_BOXES];
       
    46 	int NumBoxes;
    65 	int NumBoxes;
       
    66 	struct Position Box[MAX_BOXES];	/* The box positions */
       
    67 	struct tbox_free box_deps[MAX_BOXES];	/* The dependencies for each
       
    68 						box*/
    47 };
    69 };
    48 
       
    49 
    70 
    50 
    71 
    51 enum e_direction
    72 enum e_direction
    52 {
    73 {
    53 	DIR_LEFT,
    74 	DIR_DOWN,
    54 	DIR_RIGHT,
    75 	DIR_RIGHT,
    55 	DIR_DOWN,
    76 	DIR_UP,
    56 	DIR_UP
    77 	DIR_LEFT
    57 };
    78 };
    58 
    79 
    59 static const struct Position move_vectors[4] = {
    80 static const struct Position move_vectors[4] = {
    60 	{0, 1},
    81 	{0, 1},
       
    82 	{1, 0},
    61 	{0, -1},
    83 	{0, -1},
    62 	{1, 0},
       
    63 	{-1, 0}};
    84 	{-1, 0}};
       
    85 #define OPPOSITE_DIR(a) ((a+2)%4)
    64 
    86 
    65 struct BoxMove
    87 struct BoxMove
    66 {
    88 {
    67 	int box;
    89 	int box;
    68 	struct Position dir;
    90 	struct Position dir;
    78  * os.c */
   100  * os.c */
    79 void ReadMap(struct Map *M, char *FileName);
   101 void ReadMap(struct Map *M, char *FileName);
    80 void ShowMap (const struct Map *M);
   102 void ShowMap (const struct Map *M);
    81 void init_os();
   103 void init_os();
    82 void PrintMove(struct BoxMove b);
   104 void PrintMove(struct BoxMove b);
       
   105 void show_percent_and_map();
    83 
   106 
    84 /* Functions related to map solution
   107 /* Functions related to map solution
    85  * algorithm.c */
   108  * algorithm.c */
    86 int solve_map(const struct Map origin);
   109 int solve_map(const struct Map origin);