general.h
author viric@llimona
Sun, 07 May 2006 19:31:05 +0200
changeset 19 d46184674fe7
parent 17 7c1e68c17c0e
permissions -rw-r--r--
Added a variable managing the output file handle (stdout,stderr)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
     1
#define BOX '$'
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
     2
#define WALL '#'
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
     3
#define MAN '@'
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
     4
#define PLATFORM '.'
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
     5
#define BOXINPLATFORM '*'
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
     6
#define MANINPLATFORM 'E'
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
     7
#define BLANK ' '
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
     8
#define CORNER '-'
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
     9
#define MANCANMOVE '+'
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    10
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    11
/*#define DEBUG */
4
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    12
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    13
enum
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    14
{
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    15
	ALARM_SECONDS=1,
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    16
	MAX_X=50,
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    17
	MAX_Y=50,
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    18
	MAX_MOVES=50,
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    19
	MAX_STEPS=50,
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    20
	MAX_BOXES=15
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    21
};
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    22
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    23
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    24
enum eBool
4
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    25
{
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    26
	TRUE=!0,
8
b41a580b3abe The code compiles with pedantic without warnings.
viric@llimona
parents: 6
diff changeset
    27
	FALSE=0
4
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    28
};
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    29
typedef enum eBool Bool;
4
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    30
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    31
struct Position
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    32
{
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    33
	int x;
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    34
	int y;
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    35
};
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    36
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    37
#define add_position2(a, b) {a.x += b.x; a.y += b.y;}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    38
#define add_position3(dest, a, b) {(dest).x = (a).x + (b).x; \
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    39
				   (dest).y = (a).y + (b).y;}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    40
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    41
enum box_freedom
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    42
{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    43
	FREE=-1,
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    44
	BLOCKED=-2
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    45
};
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    46
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    47
struct tbox_free
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    48
{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    49
	/* -1, without dependency in that direction. */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    50
	/* -2, without dependency in that direction. */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    51
	enum box_freedom dep_dir[4];
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    52
};
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    53
4
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    54
struct Map
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    55
{
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    56
	char Cells[MAX_Y][MAX_X]; /* Stores WALLs and PLATFORMs */
17
7c1e68c17c0e Corrected some bugs. Now the algorithm should work for 1-level dependencies.
viric@llimona
parents: 12
diff changeset
    57
	int cells_boxes[MAX_Y][MAX_X]; /* Stores the box number in that cell */
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    58
					/* -1 is NO BOX there */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    59
	char man_moves[MAX_Y][MAX_X]; /* Stores boxes, walls, MANCANMOVEs */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    60
/*	int boxes[MAX_Y][MAX_X]; */
4
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    61
	int SizeX, SizeY;
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    62
	struct Position Man;
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    63
	int NumPlatforms;	/* This and the next determine when the game */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    64
	int NumBoxesInPlatform;	/* finished */
4
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    65
	int NumBoxes;
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    66
	struct Position Box[MAX_BOXES];	/* The box positions */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    67
	struct tbox_free box_deps[MAX_BOXES];	/* The dependencies for each
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    68
						box*/
4
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    69
};
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    70
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    71
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    72
enum e_direction
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    73
{
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    74
	DIR_DOWN,
4
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    75
	DIR_RIGHT,
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    76
	DIR_UP,
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    77
	DIR_LEFT
4
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    78
};
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    79
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    80
static const struct Position move_vectors[4] = {
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    81
	{0, 1},
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    82
	{1, 0},
4
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    83
	{0, -1},
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    84
	{-1, 0}};
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    85
#define OPPOSITE_DIR(a) ((a+2)%4)
4
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    86
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    87
struct BoxMove
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    88
{
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    89
	int box;
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    90
	struct Position dir;
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    91
};
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    92
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    93
9
622136ed6c62 Added description to general.h, from where the prototypes come from.
viric@mandarina
parents: 8
diff changeset
    94
/* Prototypes for map managing
622136ed6c62 Added description to general.h, from where the prototypes come from.
viric@mandarina
parents: 8
diff changeset
    95
 * map.c */
4
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
    96
void CopyMap (struct Map *Mdest, const struct Map *Morig);
10
9148590f009d I made variables explicitily const.
viric@llimona
parents: 9
diff changeset
    97
int is_new_map(const struct Map maps[], const int depth);
6
bfbca2c0fc70 More file separation.
viric@llimona
parents: 4
diff changeset
    98
9
622136ed6c62 Added description to general.h, from where the prototypes come from.
viric@mandarina
parents: 8
diff changeset
    99
/* Prototypes for unix i/o, processes
622136ed6c62 Added description to general.h, from where the prototypes come from.
viric@mandarina
parents: 8
diff changeset
   100
 * os.c */
4
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
   101
void ReadMap(struct Map *M, char *FileName);
d9259a605dec A cleaner version, split between different files.
viric@llimona
parents:
diff changeset
   102
void ShowMap (const struct Map *M);
6
bfbca2c0fc70 More file separation.
viric@llimona
parents: 4
diff changeset
   103
void init_os();
bfbca2c0fc70 More file separation.
viric@llimona
parents: 4
diff changeset
   104
void PrintMove(struct BoxMove b);
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   105
void show_percent_and_map();
6
bfbca2c0fc70 More file separation.
viric@llimona
parents: 4
diff changeset
   106
9
622136ed6c62 Added description to general.h, from where the prototypes come from.
viric@mandarina
parents: 8
diff changeset
   107
/* Functions related to map solution
622136ed6c62 Added description to general.h, from where the prototypes come from.
viric@mandarina
parents: 8
diff changeset
   108
 * algorithm.c */
6
bfbca2c0fc70 More file separation.
viric@llimona
parents: 4
diff changeset
   109
int solve_map(const struct Map origin);