algorithm.c
author viric@llimona
Sat, 17 Feb 2007 15:14:30 +0100
changeset 28 cd27cb410375
parent 26 95fccfcbd04c
permissions -rw-r--r--
Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
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>
28
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
     3
#include <stdlib.h>
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
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    15
#if 0 /*** THIS IS AN ERROR!!!  The box_will_be_blocked function doesn't work!*/
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    16
 Situation:
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    17
    
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    18
  ->@$ #
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    19
      $
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    20
*/
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    21
int box_will_be_blocked(const struct Map * m, const struct Position mov,
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    22
	const struct Position box_pos)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    23
{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    24
	struct Position next_pos2, tmp, tmp2[2];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    25
	int i;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    26
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    27
	next_pos2.x = box_pos.x + mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    28
	next_pos2.y = box_pos.y + mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    29
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    30
	tmp.x = next_pos2.x + mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    31
	tmp.y = next_pos2.y + mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    32
	tmp2[0].x = next_pos2.x + mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    33
	tmp2[0].y = next_pos2.y + mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    34
	tmp2[1].x = next_pos2.x - mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    35
	tmp2[1].y = next_pos2.y - mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    36
	for (i=0; i < 2; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    37
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    38
		if (m->man_moves[tmp.y][tmp.x] == WALL &&
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    39
			m->man_moves[tmp2[i].y][tmp2[i].x] == BOX)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    40
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    41
			return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    42
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    43
		else if (m->man_moves[tmp.y][tmp.x] == BOX &&
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    44
			m->man_moves[tmp2[i].y][tmp2[i].x] == WALL)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    45
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    46
			return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    47
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    48
		else if (m->man_moves[tmp.y][tmp.x] == BOX &&
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    49
			m->man_moves[tmp2[i].y][tmp2[i].x] == BOX)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    50
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    51
			return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    52
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    53
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    54
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    55
	return FALSE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    56
}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    57
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    58
int is_corner_area(const struct Map * m, const struct Position p,
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    59
	const struct Position box, const struct Position new_box)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    60
{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    61
	int NumMoves, NewMoves;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    62
	struct Position pos[MAX_MOVES];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    63
	struct Position new_pos[MAX_MOVES];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    64
	char corners[MAX_Y][MAX_X];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    65
	int i,j;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    66
	struct Position next_pos;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    67
	char *next_cell;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    68
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    69
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    70
	/* Blank the garden */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    71
	for (j = 0; j<m->SizeY; j++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    72
		for (i=0; i<m->SizeX; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    73
			corners[j][i] = m->Cells[j][i];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    74
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    75
	/* Let's put the boxes */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    76
	for (i = 0; i<m->NumBoxes; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    77
		corners[m->Box[i].y][m->Box[i].x] = BOX;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    78
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    79
	/* Let's put our box - it can be simply added */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    80
	corners[new_box.y][new_box.x] = BOX;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    81
	/* Let's remove the original box. */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    82
	corners[box.y][box.x] = BLANK;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    83
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    84
	NewMoves = 1;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    85
	new_pos[0] = p;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    86
	while (NewMoves > 0)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    87
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    88
		/* The before named "New Moves" become the moves we have
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    89
		   to analyze */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    90
		NumMoves = NewMoves;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    91
		for (i=0; i<NewMoves; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    92
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    93
			pos[i] = new_pos[i];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    94
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    95
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    96
		/* Search new positions for each position */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    97
		NewMoves = 0;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    98
		for (i=0; i<NumMoves; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
    99
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   100
			/* For each direction */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   101
			for (j=0; j<4; j++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   102
			{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   103
				next_pos.x = pos[i].x + move_vectors[j].x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   104
				next_pos.y = pos[i].y + move_vectors[j].y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   105
				next_cell = &corners[next_pos.y][next_pos.x];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   106
				if(*next_cell == BLANK ||
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   107
					*next_cell == PLATFORM)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   108
				{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   109
					return FALSE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   110
				}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   111
				else if(*next_cell == CORNER)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   112
				{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   113
					new_pos[NewMoves] = next_pos;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   114
					*next_cell = MANCANMOVE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   115
					NewMoves++;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   116
				}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   117
			}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   118
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   119
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   120
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   121
	return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   122
}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   123
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   124
int does_box_close_corners(const struct Map * m, const struct Position mov,
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   125
	const struct Position box_pos)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   126
{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   127
	struct Position p, p2;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   128
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   129
	p.x = box_pos.x + mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   130
	p.y = box_pos.y + mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   131
	
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   132
	/* Let's plan the checks */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   133
	/* The point will be marked with a MANCANMOVE */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   134
	p2.x = p.x + mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   135
	p2.y = p.y + mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   136
	if (m->Cells[p2.y][p2.x] == CORNER)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   137
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   138
		if (is_corner_area(m, p2, box_pos, p))
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   139
			return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   140
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   141
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   142
	p2.x = p.x + mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   143
	p2.y = p.y + mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   144
	if (m->Cells[p2.y][p2.x] == CORNER)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   145
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   146
		if (is_corner_area(m, p2, box_pos, p))
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   147
			return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   148
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   149
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   150
	p2.x = p.x - mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   151
	p2.y = p.y - mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   152
	if (m->Cells[p2.y][p2.x] == CORNER)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   153
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   154
		if (is_corner_area(m, p2, box_pos, p))
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   155
			return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   156
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   157
	return FALSE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   158
}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   159
#endif
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   160
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   161
/*
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   162
Catch the situation where a box is moved next to a corner, where the box
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   163
next to it will not be able to be moved.
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   164
*/
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   165
static int is_dead1(const struct Map * m, const struct Position mov,
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   166
	const struct Position new_pos)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   167
{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   168
	struct Position opposite1, opposite2;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   169
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   170
	/* The wall corners must exist */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   171
	opposite1.x = -mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   172
	opposite1.y = -mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   173
	opposite2.x = mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   174
	opposite2.y = mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   175
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   176
#ifdef DEBUG
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   177
	ShowMap(m);
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   178
#endif
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   179
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   180
	/* Test the first corner */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   181
	if (m->Cells[new_pos.y+mov.y+opposite1.y][new_pos.x+mov.x+opposite1.x]
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   182
		== WALL)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   183
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   184
		/* Test wall at opposites 1*/
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   185
		if (m->Cells[new_pos.y+opposite1.y][new_pos.x+opposite1.x]
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   186
			== WALL &&
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   187
			m->man_moves[new_pos.y+mov.y][new_pos.x+mov.x] == BOX)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   188
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   189
				return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   190
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   191
		else
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   192
		if (m->man_moves[new_pos.y+opposite1.y][new_pos.x+opposite1.x]
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   193
			== BOX &&
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   194
			m->Cells[new_pos.y+mov.y][new_pos.x+mov.x] == WALL)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   195
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   196
				return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   197
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   198
		/* Test wall at opposites 2 */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   199
		if (m->Cells[new_pos.y+opposite2.y][new_pos.x+opposite2.x]
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   200
			== WALL &&
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   201
			m->man_moves[new_pos.y+mov.y][new_pos.x+mov.x] == BOX)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   202
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   203
				return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   204
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   205
		else
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   206
		if (m->man_moves[new_pos.y+opposite2.y][new_pos.x+opposite2.x]
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   207
			== BOX &&
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   208
			m->Cells[new_pos.y+mov.y][new_pos.x+mov.x] == WALL)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   209
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   210
				return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   211
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   212
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   213
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   214
	/* Test the second corner */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   215
	if (m->Cells[new_pos.y+mov.y+opposite2.y][new_pos.x+mov.x+opposite2.x]
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   216
		== WALL)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   217
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   218
		/* Test wall at opposites 1*/
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   219
		if (m->Cells[new_pos.y+opposite1.y][new_pos.x+opposite1.x]
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   220
			== WALL &&
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   221
			m->man_moves[new_pos.y+mov.y][new_pos.x+mov.x] == BOX)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   222
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   223
				return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   224
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   225
		else
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   226
		if (m->man_moves[new_pos.y+opposite1.y][new_pos.x+opposite1.x]
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   227
			== BOX &&
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   228
			m->Cells[new_pos.y+mov.y][new_pos.x+mov.x] == WALL)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   229
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   230
				return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   231
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   232
		/* Test wall at opposites 2 */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   233
		if (m->Cells[new_pos.y+opposite2.y][new_pos.x+opposite2.x]
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   234
			== WALL &&
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   235
			m->man_moves[new_pos.y+mov.y][new_pos.x+mov.x] == BOX)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   236
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   237
				return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   238
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   239
		else
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   240
		if (m->man_moves[new_pos.y+opposite2.y][new_pos.x+opposite2.x]
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   241
			== BOX &&
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   242
			m->Cells[new_pos.y+mov.y][new_pos.x+mov.x] == WALL)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   243
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   244
				return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   245
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   246
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   247
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   248
	return FALSE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   249
}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   250
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   251
/*
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   252
Catch the situation where a corner gets surrounded by boxes.
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   253
*/
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   254
static int is_dead2(const struct Map * m, const struct Position mov,
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   255
	const struct Position new_pos)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   256
{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   257
	struct Position next, opposite1, opposite2;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   258
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   259
	next.x = new_pos.x+mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   260
	next.y = new_pos.y+mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   261
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   262
	/* The corner must exist */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   263
	if (m->Cells[next.y][next.x] != CORNER)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   264
		return FALSE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   265
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   266
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   267
	/* The wall corners must exist */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   268
	opposite1.x = next.x -mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   269
	opposite1.y = next.y -mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   270
	opposite2.x = next.x + mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   271
	opposite2.y = next.y + mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   272
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   273
	if (m->man_moves[opposite1.y][opposite1.x] == BOX)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   274
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   275
		if(m->Cells[opposite1.y+mov.y][opposite1.x+mov.x] == WALL
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   276
		   && m->Cells[opposite1.y-mov.y][opposite1.x-mov.x] == WALL)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   277
		   return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   278
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   279
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   280
	if (m->man_moves[opposite2.y][opposite2.x] == BOX)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   281
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   282
		if(m->Cells[opposite2.y+mov.y][opposite2.x+mov.x] == WALL
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   283
		   && m->Cells[opposite2.y-mov.y][opposite2.x-mov.x] == WALL)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   284
		   return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   285
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   286
	return FALSE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   287
}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   288
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   289
static int is_box_movable(const struct Map * m, const struct Position mov,
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   290
	const struct Position box_pos)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   291
{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   292
	struct Position next_pos2;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   293
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   294
	next_pos2.x = box_pos.x + mov.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   295
	next_pos2.y = box_pos.y + mov.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   296
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   297
	if((m->Cells[next_pos2.y][next_pos2.x] != BLANK &&
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   298
		m->Cells[next_pos2.y][next_pos2.x] != PLATFORM) ||
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   299
		m->man_moves[next_pos2.y][next_pos2.x] == BOX)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   300
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   301
		return FALSE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   302
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   303
	else if (is_dead1(m, mov, next_pos2) == TRUE)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   304
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   305
		return FALSE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   306
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   307
	else if (is_dead2(m, mov, next_pos2) == TRUE)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   308
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   309
		return FALSE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   310
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   311
	return TRUE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   312
}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   313
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   314
/* It modifies m->man_moves */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   315
static int get_box_movements(struct Map * m,
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   316
	struct BoxMove movements[])
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   317
{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   318
	struct Position pos[MAX_MOVES];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   319
	struct Position new_pos[MAX_MOVES];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   320
	int NumMoves, NewMoves;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   321
	int j, i;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   322
	struct Position next_pos;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   323
	char *next_cell;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   324
	int num_box_movements = 0;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   325
	
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   326
	/* Let's  the map with only walls in man_moves - other, blanks */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   327
	for (j = 0; j<m->SizeY; j++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   328
		for (i=0; i<m->SizeX; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   329
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   330
			if (m->Cells[j][i] == WALL)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   331
				m->man_moves[j][i] = WALL;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   332
			else
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   333
				m->man_moves[j][i] = BLANK;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   334
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   335
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   336
	/* Let's put the boxes */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   337
	for (i = 0; i<m->NumBoxes; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   338
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   339
		m->man_moves[m->Box[i].y][m->Box[i].x] = BOX;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   340
		m->cells_boxes[m->Box[i].y][m->Box[i].x] = i;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   341
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   342
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   343
	NewMoves = 1;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   344
	new_pos[0].x = m->Man.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   345
	new_pos[0].y = m->Man.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   346
	m->man_moves[m->Man.y][m->Man.x] = MANCANMOVE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   347
	while (NewMoves > 0)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   348
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   349
		/* The before named "New Moves" become the moves we have
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   350
		   to analyze */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   351
		NumMoves = NewMoves;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   352
		for (i=0; i<NewMoves; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   353
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   354
			pos[i] = new_pos[i];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   355
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   356
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   357
		/* Search new positions for each position */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   358
		NewMoves = 0;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   359
		for (i=0; i<NumMoves; i++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   360
		{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   361
			/* For each direction */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   362
			for (j=0; j<4; j++)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   363
			{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   364
				next_pos.x = pos[i].x + move_vectors[j].x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   365
				next_pos.y = pos[i].y + move_vectors[j].y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   366
				next_cell = &m->man_moves[next_pos.y][next_pos.x];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   367
				if(*next_cell == BLANK)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   368
				{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   369
					new_pos[NewMoves] = next_pos;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   370
					*next_cell = MANCANMOVE;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   371
					NewMoves++;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   372
				}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   373
				else if (*next_cell == BOX)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   374
				{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   375
						
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   376
					/* Check if the box is movable */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   377
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   378
					if (is_box_movable(m, move_vectors[j],
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   379
						next_pos ))
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   380
					{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   381
						{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   382
					movements[num_box_movements].box =
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   383
					m->cells_boxes[next_pos.y][next_pos.x];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   384
					movements[num_box_movements].dir =
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   385
					move_vectors[j];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   386
					num_box_movements++;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   387
						}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   388
					}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   389
					
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   390
				}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   391
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   392
			}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   393
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   394
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   395
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   396
	return num_box_movements;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   397
}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   398
10
9148590f009d I made variables explicitily const.
viric@llimona
parents: 8
diff changeset
   399
static void force_move_box(struct Map *m, const struct BoxMove move)
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   400
{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   401
	struct Position newpos;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   402
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   403
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   404
	/* Add coords */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   405
	newpos.x = m->Box[move.box].x + move.dir.x;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   406
	newpos.y = m->Box[move.box].y + move.dir.y;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   407
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   408
	/* Be certain the move can be done */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   409
	assert(m->Cells[newpos.y][newpos.x] != BOX);
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   410
	assert(m->Cells[newpos.y][newpos.x] != WALL);
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   411
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   412
	/* Control if we moved the box to a platform */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   413
	if(m->Cells[newpos.y][newpos.x] == PLATFORM)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   414
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   415
		m->NumBoxesInPlatform++;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   416
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   417
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   418
	/* Control if we moved the box from a platform */
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   419
	if (m->Cells[m->Box[move.box].y][m->Box[move.box].x] == PLATFORM)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   420
	{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   421
		m->NumBoxesInPlatform--;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   422
	}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   423
	m->Man = m->Box[move.box];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   424
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   425
	m->Box[move.box] = newpos;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   426
}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   427
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   428
28
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   429
static void update_depth_counters(const int depth)
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   430
{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   431
	if (depth > max_depth)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   432
		max_depth = depth;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   433
	if (depth > max_depth_period)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   434
		max_depth_period = depth;
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   435
	if (depth < min_depth_period)
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   436
		min_depth_period = depth;
28
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   437
}
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   438
28
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   439
struct Map *all_maps;
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   440
struct BoxMove *all_movements; /* DEPTH movements of MAX_MOVES */
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   441
int *all_mov_tries; /* The actual step in movements for every depth */
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   442
int *all_mov_max; /* Maximum of movements per all_movement element */
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   443
float *percent;
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   444
float *percent_part;
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   445
int depth;
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   446
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   447
int search_loop(const struct Map *origin)
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   448
{
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   449
	int found; /* bool */
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   450
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   451
	all_maps = malloc(sizeof(*all_maps) * (MAX_STEPS+1));
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   452
	all_movements = malloc(sizeof(*all_movements)*MAX_MOVES*(MAX_STEPS+1));
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   453
	all_mov_tries = malloc(sizeof(*all_mov_tries)*(MAX_STEPS+1));
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   454
	all_mov_max = malloc(sizeof(*all_mov_max)*(MAX_STEPS+1));
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   455
	percent = malloc(sizeof(*percent)*(MAX_STEPS+1));
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   456
	percent_part = malloc(sizeof(*percent)*(MAX_STEPS+1));
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   457
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   458
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   459
	if (load_state())
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   460
	{
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   461
		--depth;
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   462
		if (all_mov_tries[depth] != 0)
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   463
			all_mov_tries[depth] = 0;
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   464
	} else
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   465
	{
28
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   466
		depth = 0;
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   467
		CopyMap(&all_maps[0], origin);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   468
		all_mov_max[0] = get_box_movements(&all_maps[0], &all_movements[0]);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   469
		assert(all_mov_max[0] < MAX_MOVES);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   470
		assert(all_mov_max[0] > 0);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   471
		percent[0] = 0.;
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   472
		percent_part[0] = 100.;
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   473
		all_mov_tries[0] = 0;
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   474
	}
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   475
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   476
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   477
	found = 0;
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   478
	do
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   479
	{
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   480
		struct BoxMove *new_movements = &all_movements[(depth+1)*MAX_MOVES];
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   481
		struct BoxMove *movements = &all_movements[depth*MAX_MOVES];
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   482
		int num_movements = all_mov_max[depth];
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   483
		int *num_new_movements = &all_mov_max[depth+1];
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   484
		int *step = &all_mov_tries[depth];
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   485
		struct Map *new_map = &all_maps[depth+1];
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   486
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   487
		update_depth_counters(depth);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   488
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   489
		percent_part[depth+1] = percent_part[depth] / num_movements;
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   490
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   491
		CopyMap(new_map, &all_maps[depth]);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   492
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   493
		/* DEBUG */
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   494
#if DEBUG
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   495
		ShowMap(new_map);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   496
		show_tries(depth);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   497
		printf("Nummovs[%i]: %i\n", depth, num_movements);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   498
		printf("Step[%i]: %i\n", depth, *step);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   499
#endif
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   500
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   501
		/* Now four things can happen:
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   502
		 * - look for depth + 1
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   503
		 * - keep looking for movements in depth
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   504
		 * - go one depth back.
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   505
		 * - solve the puzle */
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   506
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   507
		/* Go one depth back */
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   508
		if (*step >= num_movements)
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   509
		{
28
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   510
			--depth;
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   511
			continue;
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   512
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   513
28
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   514
		force_move_box(new_map, movements[(*step)]);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   515
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   516
		++(*step);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   517
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   518
		/* Solve the puzzle */
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   519
		if (new_map->NumPlatforms == new_map->NumBoxesInPlatform)
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   520
		{
28
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   521
			PrintMoves(all_movements, all_mov_tries, depth+1);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   522
			actual_map = &all_maps[depth+1];
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   523
			show_percent_and_map();
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   524
			save_state();
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   525
			found = 1;
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   526
		}
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   527
		
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   528
		if (is_new_map(all_maps, depth+1))
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   529
		{
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   530
			*num_new_movements =
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   531
				get_box_movements(new_map, new_movements);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   532
			assert(*num_new_movements < MAX_MOVES);
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   533
		}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   534
		else
28
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   535
			*num_new_movements = 0;
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   536
28
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   537
		percent[depth] = percent[depth] + percent_part[depth+1];
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   538
		percent_to_show = percent[depth];
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   539
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   540
		/* Keep looking for movements in depth */
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   541
		if (*num_new_movements == 0)
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   542
		{
28
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   543
			depth_to_show = depth;
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   544
			actual_map = &all_maps[depth];
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   545
			continue;
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   546
		}
28
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   547
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   548
		/* Look for depth + 1*/
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   549
		if (depth+1 < MAX_STEPS)
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   550
		{
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   551
			percent[depth+1] = percent[depth];
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   552
			all_mov_tries[depth+1] = 0;
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   553
			++depth;
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   554
		}
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   555
	} while(!found && depth >= 0);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   556
	free(all_maps);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   557
	free(all_movements);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   558
	free(all_mov_tries);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   559
	free(all_mov_max);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   560
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   561
	return found;
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   562
}
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   563
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   564
26
95fccfcbd04c Less calls to libc. Profiling is much better now.
viric@llimona
parents: 25
diff changeset
   565
int solve_map(const struct Map *origin)
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   566
{
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   567
	struct BoxMove new_movements[MAX_MOVES];
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   568
	int num_new_movements;
26
95fccfcbd04c Less calls to libc. Profiling is much better now.
viric@llimona
parents: 25
diff changeset
   569
	int ret;
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   570
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   571
	init_os();
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   572
28
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   573
	ret = search_loop(origin);
cd27cb410375 Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
viric@llimona
parents: 26
diff changeset
   574
26
95fccfcbd04c Less calls to libc. Profiling is much better now.
viric@llimona
parents: 25
diff changeset
   575
	return ret;
6
bfbca2c0fc70 More file separation.
viric@llimona
parents:
diff changeset
   576
}