algorithm.c
author viric@llimona
Thu, 18 May 2006 23:33:03 +0200
changeset 22 d473e153a1de
parent 21 e73048967870
permissions -rw-r--r--
Added tag brute1 for changeset dcfe4d2d4387e3047e734c07c835b15b26a893bd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
     1
#include <assert.h>
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
     2
#include <string.h>
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
     3
#include <stdio.h> /**********************************PROVA */
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
     4
#include "general.h"
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
     5
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
     6
/* Variables related to the showing of information by os */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
     7
extern float percent_to_show;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
     8
extern int depth_to_show;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
     9
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    10
extern int max_depth;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    11
extern int min_depth_period;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    12
extern int max_depth_period;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    13
extern struct Map * actual_map;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    14
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    15
/* Prototipes */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    16
static Bool are_there_fixed_boxes(struct Map *m,
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    17
	struct BoxMove movements[MAX_MOVES], int *num_movements);
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    18
static void force_move_box(struct Map *m, const struct BoxMove move);
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    19
static Bool search_did_found(struct Map maps[], int depth,
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    20
	struct BoxMove movements[],
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    21
	int num_movements, float percent, float total_percent);
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    22
static void fill_deps(struct Map *m);
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
    23
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    24
#if 0 /*** THIS IS AN ERROR!!!  The box_will_be_blocked function doesn't work!*/
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    25
 Situation:
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    26
    
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    27
  ->@$ #
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    28
      $
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    29
*/
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    30
int box_will_be_blocked(const struct Map * m, const struct Position mov,
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    31
	const struct Position box_pos)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    32
{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    33
	struct Position next_pos2, tmp, tmp2[2];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    34
	int i;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    35
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    36
	next_pos2.x = box_pos.x + mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    37
	next_pos2.y = box_pos.y + mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    38
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    39
	tmp.x = next_pos2.x + mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    40
	tmp.y = next_pos2.y + mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    41
	tmp2[0].x = next_pos2.x + mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    42
	tmp2[0].y = next_pos2.y + mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    43
	tmp2[1].x = next_pos2.x - mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    44
	tmp2[1].y = next_pos2.y - mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    45
	for (i=0; i < 2; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    46
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    47
		if (m->man_moves[tmp.y][tmp.x] == WALL &&
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    48
			m->man_moves[tmp2[i].y][tmp2[i].x] == BOX)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    49
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    50
			return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    51
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    52
		else if (m->man_moves[tmp.y][tmp.x] == BOX &&
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    53
			m->man_moves[tmp2[i].y][tmp2[i].x] == WALL)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    54
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    55
			return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    56
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    57
		else if (m->man_moves[tmp.y][tmp.x] == BOX &&
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    58
			m->man_moves[tmp2[i].y][tmp2[i].x] == BOX)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    59
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    60
			return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    61
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    62
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    63
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    64
	return FALSE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    65
}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    66
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    67
int is_corner_area(const struct Map * m, const struct Position p,
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    68
	const struct Position box, const struct Position new_box)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    69
{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    70
	int NumMoves, NewMoves;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    71
	struct Position pos[MAX_MOVES];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    72
	struct Position new_pos[MAX_MOVES];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    73
	char corners[MAX_Y][MAX_X];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    74
	int i,j;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    75
	struct Position next_pos;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    76
	char *next_cell;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    77
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    78
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    79
	/* Blank the garden */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    80
	for (j = 0; j<m->SizeY; j++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    81
		for (i=0; i<m->SizeX; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    82
			corners[j][i] = m->Cells[j][i];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    83
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    84
	/* Let's put the boxes */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    85
	for (i = 0; i<m->NumBoxes; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    86
		corners[m->Box[i].y][m->Box[i].x] = BOX;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    87
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    88
	/* Let's put our box - it can be simply added */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    89
	corners[new_box.y][new_box.x] = BOX;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    90
	/* Let's remove the original box. */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    91
	corners[box.y][box.x] = BLANK;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    92
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    93
	NewMoves = 1;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    94
	new_pos[0] = p;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    95
	while (NewMoves > 0)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    96
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    97
		/* The before named "New Moves" become the moves we have
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    98
		   to analyze */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    99
		NumMoves = NewMoves;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   100
		for (i=0; i<NewMoves; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   101
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   102
			pos[i] = new_pos[i];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   103
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   104
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   105
		/* Search new positions for each position */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   106
		NewMoves = 0;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   107
		for (i=0; i<NumMoves; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   108
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   109
			/* For each direction */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   110
			for (j=0; j<4; j++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   111
			{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   112
				next_pos.x = pos[i].x + move_vectors[j].x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   113
				next_pos.y = pos[i].y + move_vectors[j].y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   114
				next_cell = &corners[next_pos.y][next_pos.x];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   115
				if(*next_cell == BLANK ||
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   116
					*next_cell == PLATFORM)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   117
				{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   118
					return FALSE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   119
				}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   120
				else if(*next_cell == CORNER)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   121
				{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   122
					new_pos[NewMoves] = next_pos;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   123
					*next_cell = MANCANMOVE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   124
					NewMoves++;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   125
				}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   126
			}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   127
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   128
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   129
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   130
	return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   131
}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   132
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   133
int does_box_close_corners(const struct Map * m, const struct Position mov,
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   134
	const struct Position box_pos)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   135
{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   136
	struct Position p, p2;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   137
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   138
	p.x = box_pos.x + mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   139
	p.y = box_pos.y + mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   140
	
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   141
	/* Let's plan the checks */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   142
	/* The point will be marked with a MANCANMOVE */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   143
	p2.x = p.x + mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   144
	p2.y = p.y + mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   145
	if (m->Cells[p2.y][p2.x] == CORNER)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   146
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   147
		if (is_corner_area(m, p2, box_pos, p))
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   148
			return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   149
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   150
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   151
	p2.x = p.x + mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   152
	p2.y = p.y + mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   153
	if (m->Cells[p2.y][p2.x] == CORNER)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   154
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   155
		if (is_corner_area(m, p2, box_pos, p))
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   156
			return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   157
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   158
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   159
	p2.x = p.x - mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   160
	p2.y = p.y - mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   161
	if (m->Cells[p2.y][p2.x] == CORNER)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   162
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   163
		if (is_corner_area(m, p2, box_pos, p))
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   164
			return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   165
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   166
	return FALSE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   167
}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   168
#endif
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   169
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   170
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   171
static void force_move_box(struct Map *m, const struct BoxMove move)
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   172
{
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   173
	struct Position newpos;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   174
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   175
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   176
	/* Add coords */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   177
	newpos.x = m->Box[move.box].x + move.dir.x;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   178
	newpos.y = m->Box[move.box].y + move.dir.y;
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   179
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   180
	/* Be certain the move can be done */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   181
	assert(m->Cells[newpos.y][newpos.x] != BOX);
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   182
	assert(m->Cells[newpos.y][newpos.x] != WALL);
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   183
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   184
	/* Control if we moved the box to a platform */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   185
	if(m->Cells[newpos.y][newpos.x] == PLATFORM)
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   186
	{
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   187
		m->NumBoxesInPlatform++;
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   188
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   189
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   190
	/* Control if we moved the box from a platform */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   191
	if (m->Cells[m->Box[move.box].y][m->Box[move.box].x] == PLATFORM)
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   192
	{
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   193
		m->NumBoxesInPlatform--;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   194
	}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   195
	m->Man = m->Box[move.box];
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   196
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   197
	m->Box[move.box] = newpos;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   198
}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   199
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   200
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   201
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   202
static Bool search_did_found(struct Map maps[], int depth,
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   203
	struct BoxMove movements[],
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   204
	int num_movements, float percent, float total_percent)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   205
{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   206
	struct BoxMove new_movements[MAX_MOVES];
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   207
	int num_new_movements;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   208
	struct Map *m; 
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   209
	int i;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   210
	float next_percent;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   211
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   212
	next_percent = percent / num_movements;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   213
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   214
	m = &maps[depth+1];
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   215
	if (depth > max_depth)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   216
		max_depth = depth;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   217
	if (depth > max_depth_period)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   218
		max_depth_period = depth;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   219
	if (depth < min_depth_period)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   220
		min_depth_period = depth;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   221
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   222
	for (i=0; i < num_movements; i++)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   223
	{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   224
		CopyMap(m, &maps[depth]);
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   225
		force_move_box(m, movements[i]);
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   226
		/* Let's see if we finished */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   227
		if (m->NumPlatforms == m->NumBoxesInPlatform)
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   228
		{
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   229
			PrintMove(movements[i]);
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   230
			actual_map = &maps[depth+1];
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   231
			show_percent_and_map();
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   232
			return TRUE;
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   233
		}
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   234
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   235
		if (is_new_map(maps, depth+1))
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   236
		{
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   237
			fill_deps(m);
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   238
			if (are_there_fixed_boxes(m,
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   239
				new_movements, &num_new_movements))
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   240
			{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   241
				/* That means that the map is illegal */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   242
				/* Maybe we could update the percent here... */
16
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   243
				continue;
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   244
			}
16
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   245
			actual_map = &maps[depth+1];
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   246
#ifdef DEBUG		/* to be out */
21
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   247
			actual_map = &maps[depth+1];
16
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   248
			show_percent_and_map();
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   249
#endif
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   250
			/* the assert should be IN the function before,
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   251
			   before OVERfilling new_movements */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   252
			assert(num_new_movements < MAX_MOVES);
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   253
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   254
		else
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   255
			num_new_movements = 0;
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   256
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   257
		if (num_new_movements == 0)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   258
		{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   259
			percent_to_show = total_percent + next_percent*i;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   260
			depth_to_show = depth;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   261
		}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   262
		else
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   263
		{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   264
			if (depth+1 < MAX_STEPS)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   265
			{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   266
				if(search_did_found(maps, depth+1, new_movements,
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   267
					num_new_movements, next_percent,
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   268
					total_percent + next_percent*i) == TRUE)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   269
				{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   270
					PrintMove(movements[i]);
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   271
					actual_map = &maps[depth+1];
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   272
					show_percent_and_map();
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   273
					return TRUE;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   274
				}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   275
			}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   276
		}
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   277
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   278
	return FALSE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   279
}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   280
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   281
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   282
/* It only fills the m->man_moves structure */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   283
static void paint_mancanmove(struct Map *m)
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   284
{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   285
	struct Position pos[MAX_MOVES];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   286
	struct Position new_pos[MAX_MOVES];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   287
	int NumMoves, NewMoves;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   288
	int j, i;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   289
	struct Position next_pos;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   290
	char *next_cell;
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   291
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   292
	/* Let's  the map with only walls in man_moves - other, blanks */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   293
	for (j = 0; j<m->SizeY; j++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   294
		for (i=0; i<m->SizeX; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   295
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   296
			if (m->Cells[j][i] == WALL)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   297
				m->man_moves[j][i] = WALL;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   298
			else
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   299
				m->man_moves[j][i] = BLANK;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   300
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   301
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   302
	/* Let's put the boxes */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   303
	for (i = 0; i<m->NumBoxes; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   304
	{
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   305
		m->man_moves[m->Box[i].y][m->Box[i].x] = WALL;
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   306
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   307
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   308
	NewMoves = 1;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   309
	new_pos[0].x = m->Man.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   310
	new_pos[0].y = m->Man.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   311
	m->man_moves[m->Man.y][m->Man.x] = MANCANMOVE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   312
	while (NewMoves > 0)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   313
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   314
		/* The before named "New Moves" become the moves we have
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   315
		   to analyze */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   316
		NumMoves = NewMoves;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   317
		for (i=0; i<NewMoves; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   318
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   319
			pos[i] = new_pos[i];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   320
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   321
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   322
		/* Search new positions for each position */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   323
		NewMoves = 0;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   324
		for (i=0; i<NumMoves; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   325
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   326
			/* For each direction */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   327
			for (j=0; j<4; j++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   328
			{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   329
				next_pos.x = pos[i].x + move_vectors[j].x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   330
				next_pos.y = pos[i].y + move_vectors[j].y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   331
				next_cell = &m->man_moves[next_pos.y][next_pos.x];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   332
				if(*next_cell == BLANK)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   333
				{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   334
					new_pos[NewMoves] = next_pos;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   335
					*next_cell = MANCANMOVE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   336
					NewMoves++;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   337
				}
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   338
			}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   339
		}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   340
	}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   341
}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   342
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   343
/* Returns TRUE if there are fixed boxes that should be moved, FALSE otherwise*/
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   344
/* For 'm' it modifies only m->boxes[][] */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   345
static Bool are_there_fixed_boxes(struct Map *m,
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   346
	struct BoxMove movements[MAX_MOVES], int *num_movements)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   347
{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   348
	int i,j;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   349
	enum e_direction d;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   350
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   351
	/* Box dependencies. The first depends on seconds. */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   352
	struct
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   353
	{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   354
		Bool box[MAX_BOXES][MAX_BOXES];
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   355
		int ndeps[MAX_BOXES];
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   356
	} dep;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   357
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   358
	/* Free boxes' arrays */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   359
	struct
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   360
	{
21
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   361
		Bool tag[MAX_BOXES]; /*This is only used in 'free' & 'blocked'*/
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   362
		int box[MAX_BOXES];
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   363
		int n;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   364
	} free,			/* List of all boxes free-to-move */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   365
		new_free,	/* List of boxes for the next loop (code) */
21
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   366
		tfree,	/* List of boxes of the loop (code) */
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   367
		new_blocked,
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   368
		tblocked,
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   369
		blocked;
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   370
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   371
	struct Position tpos;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   372
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   373
	Bool is_not_set_free;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   374
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   375
	/* Initialize to 0 the dependency structures */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   376
	memset((void *) &dep, 0, sizeof(dep));
16
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   377
	new_free.n=0;
21
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   378
	blocked.n=0;
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   379
	new_blocked.n=0;
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   380
	for(i=0; i<m->NumBoxes; i++)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   381
	{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   382
		new_free.box[i] = FALSE;
21
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   383
		blocked.tag[i] = FALSE;
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   384
		new_blocked.tag[i] = FALSE;
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   385
	}
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   386
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   387
	/* Let's fill the structure */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   388
	for(i=0; i<m->NumBoxes; i++)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   389
	{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   390
		/* See if the box is blocked. That could be
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   391
		   done in fill_deps */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   392
		if (m->box_deps[i].dep_dir[0] == BLOCKED &&
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   393
			m->box_deps[i].dep_dir[1] == BLOCKED &&
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   394
			m->box_deps[i].dep_dir[2] == BLOCKED &&
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   395
			m->box_deps[i].dep_dir[3] == BLOCKED )
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   396
		{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   397
			if (m->Cells[m->Box[i].y][m->Box[i].x] !=
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   398
				PLATFORM)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   399
				return TRUE;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   400
			else
21
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   401
			{
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   402
				blocked.tag[i] = TRUE;
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   403
				blocked.box[blocked.n++] = i;
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   404
				new_blocked.box[new_blocked.n++] = i;
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   405
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   406
				/* This is not used actually 
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   407
				m->boxes[m->Box[i].y][m->Box[i].x] =
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   408
					WALL;
21
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   409
				*/
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   410
				/* The dependencies are checked. All blocked.*/
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   411
				continue;
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   412
			}
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   413
		}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   414
		/* Let's take note of the dependencies */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   415
		is_not_set_free = TRUE;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   416
		for(d=0; d<4; d++)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   417
		{
17
7c1e68c17c0e Corrected some bugs. Now the algorithm should work for 1-level dependencies.
viric@llimona
parents: 16
diff changeset
   418
			if(m->box_deps[i].dep_dir[d] >= 0)
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   419
			{
16
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   420
				if (!dep.box[i][m->box_deps[i].dep_dir[d]])
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   421
				{
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   422
					dep.box[i][m->box_deps[i].dep_dir[d]] =
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   423
						TRUE;
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   424
					dep.ndeps[i]++;
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   425
				}
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   426
			} else
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   427
			if(m->box_deps[i].dep_dir[d] == FREE)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   428
			{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   429
				if (is_not_set_free)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   430
				{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   431
					new_free.box[new_free.n++] = i;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   432
					is_not_set_free = FALSE;
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   433
				}
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   434
			}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   435
		}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   436
	}
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   437
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   438
	/* Let's analyze if the free boxes can really be moved, and
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   439
	   set them as dependant, if they're dependant.
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   440
	   If some can be really moved, we should know _where to_. */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   441
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   442
	/* Paint MANCANMOVE at each cell the man can reach */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   443
	paint_mancanmove(m);
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   444
	
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   445
	/* For each free movable box, let's see if the man can reach them
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   446
	   fine. If we can, add it to the possible movements. */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   447
	*num_movements=0;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   448
	for(i=0; i<new_free.n; i++)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   449
	{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   450
		/* For each direction, try if the box can be moved */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   451
		for(d=0; d<4; d++)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   452
		{
16
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   453
			if(m->box_deps[new_free.box[i]].dep_dir[d] == FREE)
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   454
			{
16
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   455
				add_position3(tpos, m->Box[new_free.box[i]], move_vectors[OPPOSITE_DIR(d)])
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   456
				if (m->man_moves[tpos.y][tpos.x] == MANCANMOVE)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   457
				{
16
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   458
					movements[*num_movements].box =
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   459
						new_free.box[i];
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   460
					movements[*num_movements].dir =
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   461
						move_vectors[d];
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   462
					(*num_movements)++;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   463
				}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   464
				/* ELSE - we should catch those cases,
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   465
				where free boxes cannot be moved. Will they
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   466
				ever be movable? 
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   467
				THIS HAS TO BE IMPROVED */
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   468
			}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   469
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   470
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   471
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   472
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   473
	/* ---------------- The next possible movements have been calculated --
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   474
	We can still find that this map is illegal. We need to find
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   475
	further more if there are boxes unmovable (due to dependencies) */
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   476
21
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   477
	/* Let's block those boxes dependant on blocked boxes.
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   478
	   If some of those is not in a platform, the function exits TRUE. */
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   479
	/* The new_blocked and blocked structures are filled fine */
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   480
	while (new_blocked.n > 0)
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   481
	{
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   482
		/* Copy new_blocked into tblocked */
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   483
		tblocked.n = new_blocked.n;
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   484
		for(i=0; i<new_blocked.n; i++)
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   485
			tblocked.box[i] = new_blocked.box[i];
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   486
		new_blocked.n = 0;
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   487
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   488
		for(i=0; i<tblocked.n; i++)
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   489
		{
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   490
			for(j=0; j<m->NumBoxes; j++)
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   491
			{
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   492
				if(dep.box[j][tblocked.box[i]])
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   493
				{
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   494
				/* The next line depends on the multiple-
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   495
				   dependency improvement, still not done. */
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   496
				   	/* Look for the dep direction */
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   497
					for(d=0;d<4;d++)
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   498
					{
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   499
						if(m->box_deps[j].dep_dir[d]==
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   500
						tblocked.box[i])
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   501
							break;
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   502
					}
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   503
					/* d owns the dependency dir. */
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   504
					/* Look if the other directions are
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   505
					blocked */
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   506
					if(m->box_deps[j].dep_dir[(d+1)%4] !=
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   507
						BLOCKED ||
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   508
					m->box_deps[j].dep_dir[(d+3)%4] !=
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   509
						BLOCKED)
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   510
						continue;
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   511
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   512
					/* A dependancy on a blocked box found*/
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   513
					if (!blocked.tag[j])
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   514
					{
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   515
						/* If the box is not already
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   516
						known as blocked...*/
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   517
						if (m->Cells[m->Box[j].y][m->Box[j].x] != PLATFORM)
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   518
						{
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   519
							return TRUE;
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   520
						}
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   521
						else
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   522
						{
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   523
							new_blocked.box[new_blocked.n++]=j;
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   524
							/* The next line is not
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   525
							really used 
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   526
							blocked.box[blocked.n++]=j;
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   527
							*/
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   528
							blocked.tag[j]=TRUE;
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   529
						}
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   530
					}
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   531
				}
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   532
			}
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   533
		}
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   534
	}
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   535
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   536
	/* Let's take out all dependencies from 'free' boxes */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   537
	/* Prepare the 'free' list */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   538
	for(i=0; i<m->NumBoxes;i++)
21
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   539
		free.tag[i] = FALSE;
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   540
	free.n = new_free.n;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   541
	for(i=0; i<new_free.n; i++)
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   542
	{
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   543
		free.box[i] = new_free.box[i];
21
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   544
		free.tag[new_free.box[i]] = TRUE;
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   545
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   546
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   547
	/* KACXO-loop  */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   548
	while (new_free.n > 0)
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   549
	{
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   550
		/* Copy new_free into free */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   551
		tfree.n = new_free.n;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   552
		for(i=0; i<new_free.n; i++)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   553
			tfree.box[i] = new_free.box[i];
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   554
		new_free.n = 0;
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   555
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   556
		for(i=0; i<tfree.n; i++)
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   557
		{
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   558
			for(j=0; j<m->NumBoxes; j++)
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   559
			{
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   560
				/* The box j no more depends on
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   561
				   the box tfree[i] */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   562
				if(dep.box[j][tfree.box[i]])
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   563
				{
21
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   564
					/* Remove the dependency */
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   565
					dep.box[j][tfree.box[i]] = FALSE;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   566
					dep.ndeps[j]--;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   567
					assert(dep.ndeps[j] >= 0);
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   568
					if (dep.ndeps[j] == 0 &&
21
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   569
						!free.tag[j])
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   570
					{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   571
						new_free.box[new_free.n++]=j;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   572
						free.box[free.n++]=j;
21
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   573
						free.tag[j]=TRUE;
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   574
					}
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   575
				}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   576
			}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   577
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   578
	}
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   579
21
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   580
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   581
	/* Now are left only boxes which depend on others-non-free */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   582
	for(i=0; i<m->NumBoxes; i++)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   583
	{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   584
		for(j=0; j<m->NumBoxes; j++)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   585
		{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   586
			/* We only do one-level search !!! */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   587
			/* If the box only depends on another,
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   588
			   which also only depends on this... */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   589
			if (dep.box[i][j] && dep.ndeps[i] == 1
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   590
				&& dep.box[j][i] && dep.ndeps[j] == 1)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   591
			{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   592
				if (m->Cells[m->Box[i].y][m->Box[i].x]!=
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   593
					PLATFORM)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   594
				{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   595
					return TRUE;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   596
				}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   597
				/* We don't set any wall here, they're not
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   598
				   important */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   599
			}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   600
		}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   601
	}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   602
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   603
	return FALSE;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   604
}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   605
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   606
static void init_cell_boxes(struct Map *m)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   607
{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   608
	int i,j;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   609
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   610
	/* Let's  the map with only walls in man_moves - other, blanks */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   611
	for (j = 0; j<m->SizeY; j++)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   612
		for (i=0; i<m->SizeX; i++)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   613
			m->cells_boxes[j][i] = -1;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   614
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   615
	for(i=0; i<m->NumBoxes; i++)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   616
	{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   617
		m->cells_boxes[m->Box[i].y][m->Box[i].x] = i;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   618
	}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   619
}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   620
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   621
/* It fills only m->box_deps */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   622
static void fill_deps(struct Map *m)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   623
{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   624
	int i;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   625
	enum e_direction dir;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   626
	struct Position n; /* Position next to the box */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   627
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   628
	/* TO BE OPTIMIZED - get into force_move_box */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   629
	init_cell_boxes(m);
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   630
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   631
	for(i=0; i<m->NumBoxes; i++)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   632
	{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   633
		/* Initialize the move freedom */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   634
		for(dir=0;dir<4; dir++)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   635
		{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   636
			m->box_deps[i].dep_dir[dir] = FREE;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   637
		}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   638
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   639
		/* Limit the freedom */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   640
		for(dir=0;dir<4; dir++)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   641
		{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   642
			add_position3(n,m->Box[i],move_vectors[dir]);
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   643
			if(m->Cells[n.y][n.x] == WALL)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   644
			{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   645
				/* IMPROVEMENT: The fixed-box detection
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   646
				could be done here */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   647
				m->box_deps[i].dep_dir[dir] = BLOCKED;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   648
				m->box_deps[i].dep_dir[OPPOSITE_DIR(dir)] =
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   649
					BLOCKED;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   650
				continue;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   651
			}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   652
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   653
			/* if there is Wall limit, we don't want to set box
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   654
			   dependency */
21
e73048967870 Improvement, managing the case a box depends ONLY on a blocked box (it will therefore be considered as blocked)
viric@llimona
parents: 17
diff changeset
   655
			if(m->box_deps[i].dep_dir[dir] == BLOCKED)
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   656
				continue;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   657
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   658
			/* Put the box dependency in the list */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   659
			if(m->cells_boxes[n.y][n.x] >= 0)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   660
			{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   661
				m->box_deps[i].dep_dir[dir] =
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   662
					m->cells_boxes[n.y][n.x];
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   663
				/* If the other site is not limited by another
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   664
				   box, we set it up too. */
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   665
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   666
				/* *** MAYBE IT'S BETTER NOT TO SET IT */
16
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   667
				if(m->box_deps[i].dep_dir[OPPOSITE_DIR(dir)]
fe078fb2e8b4 Now I think the code works. There were some indexing mistakse,
viric@llimona
parents: 13
diff changeset
   668
					== FREE)
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   669
				{
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   670
				m->box_deps[i].dep_dir[OPPOSITE_DIR(dir)] =
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   671
					m->cells_boxes[n.y][n.x];
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   672
				}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   673
				continue;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   674
			}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   675
			if(m->Cells[n.y][n.x] == CORNER)
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   676
				m->box_deps[i].dep_dir[dir] = BLOCKED;
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   677
				
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   678
		}
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   679
	}
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   680
}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   681
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   682
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   683
int solve_map(const struct Map origin)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   684
{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   685
	struct Map maps[MAX_STEPS+1];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   686
	struct BoxMove new_movements[MAX_MOVES];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   687
	int num_new_movements;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   688
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   689
	CopyMap(&maps[0], &origin);
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   690
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   691
	fill_deps(&maps[0]);
13
c2b272938a1f actual_map is initialized at first, so almost never a SIGSEGV can happen.
viric@llimona
parents: 12
diff changeset
   692
	/* Initializing actual_map here AT LEAST gives protection against
c2b272938a1f actual_map is initialized at first, so almost never a SIGSEGV can happen.
viric@llimona
parents: 12
diff changeset
   693
	SIGSEGV */
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   694
	assert(!are_there_fixed_boxes(&maps[0], new_movements,
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   695
		&num_new_movements));
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   696
	search_did_found(maps, 0, new_movements, num_new_movements, 100, 0);
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   697
12
a2c334a71a6b A minimum working (hope so!) version of the algorithm is working, although
viric@llimona
parents: 10
diff changeset
   698
	return 0;
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   699
}