author | viric@llimona |
Thu, 18 May 2006 23:33:03 +0200 | |
changeset 22 | d473e153a1de |
parent 21 | e73048967870 |
permissions | -rw-r--r-- |
6 | 1 |
#include <assert.h> |
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 | 4 |
#include "general.h" |
5 |
||
6 |
/* Variables related to the showing of information by os */ |
|
7 |
extern float percent_to_show; |
|
8 |
extern int depth_to_show; |
|
9 |
||
10 |
extern int max_depth; |
|
11 |
extern int min_depth_period; |
|
12 |
extern int max_depth_period; |
|
13 |
extern struct Map * actual_map; |
|
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 | 24 |
#if 0 /*** THIS IS AN ERROR!!! The box_will_be_blocked function doesn't work!*/ |
25 |
Situation: |
|
26 |
||
27 |
->@$ # |
|
28 |
$ |
|
29 |
*/ |
|
30 |
int box_will_be_blocked(const struct Map * m, const struct Position mov, |
|
31 |
const struct Position box_pos) |
|
32 |
{ |
|
33 |
struct Position next_pos2, tmp, tmp2[2]; |
|
34 |
int i; |
|
35 |
||
36 |
next_pos2.x = box_pos.x + mov.x; |
|
37 |
next_pos2.y = box_pos.y + mov.y; |
|
38 |
||
39 |
tmp.x = next_pos2.x + mov.x; |
|
40 |
tmp.y = next_pos2.y + mov.y; |
|
41 |
tmp2[0].x = next_pos2.x + mov.y; |
|
42 |
tmp2[0].y = next_pos2.y + mov.x; |
|
43 |
tmp2[1].x = next_pos2.x - mov.y; |
|
44 |
tmp2[1].y = next_pos2.y - mov.x; |
|
45 |
for (i=0; i < 2; i++) |
|
46 |
{ |
|
47 |
if (m->man_moves[tmp.y][tmp.x] == WALL && |
|
48 |
m->man_moves[tmp2[i].y][tmp2[i].x] == BOX) |
|
49 |
{ |
|
50 |
return TRUE; |
|
51 |
} |
|
52 |
else if (m->man_moves[tmp.y][tmp.x] == BOX && |
|
53 |
m->man_moves[tmp2[i].y][tmp2[i].x] == WALL) |
|
54 |
{ |
|
55 |
return TRUE; |
|
56 |
} |
|
57 |
else if (m->man_moves[tmp.y][tmp.x] == BOX && |
|
58 |
m->man_moves[tmp2[i].y][tmp2[i].x] == BOX) |
|
59 |
{ |
|
60 |
return TRUE; |
|
61 |
} |
|
62 |
} |
|
63 |
||
64 |
return FALSE; |
|
65 |
} |
|
66 |
||
67 |
int is_corner_area(const struct Map * m, const struct Position p, |
|
68 |
const struct Position box, const struct Position new_box) |
|
69 |
{ |
|
70 |
int NumMoves, NewMoves; |
|
71 |
struct Position pos[MAX_MOVES]; |
|
72 |
struct Position new_pos[MAX_MOVES]; |
|
73 |
char corners[MAX_Y][MAX_X]; |
|
74 |
int i,j; |
|
75 |
struct Position next_pos; |
|
76 |
char *next_cell; |
|
77 |
||
78 |
||
79 |
/* Blank the garden */ |
|
80 |
for (j = 0; j<m->SizeY; j++) |
|
81 |
for (i=0; i<m->SizeX; i++) |
|
82 |
corners[j][i] = m->Cells[j][i]; |
|
83 |
||
84 |
/* Let's put the boxes */ |
|
85 |
for (i = 0; i<m->NumBoxes; i++) |
|
86 |
corners[m->Box[i].y][m->Box[i].x] = BOX; |
|
87 |
||
88 |
/* Let's put our box - it can be simply added */ |
|
89 |
corners[new_box.y][new_box.x] = BOX; |
|
90 |
/* Let's remove the original box. */ |
|
91 |
corners[box.y][box.x] = BLANK; |
|
92 |
||
93 |
NewMoves = 1; |
|
94 |
new_pos[0] = p; |
|
95 |
while (NewMoves > 0) |
|
96 |
{ |
|
97 |
/* The before named "New Moves" become the moves we have |
|
98 |
to analyze */ |
|
99 |
NumMoves = NewMoves; |
|
100 |
for (i=0; i<NewMoves; i++) |
|
101 |
{ |
|
102 |
pos[i] = new_pos[i]; |
|
103 |
} |
|
104 |
||
105 |
/* Search new positions for each position */ |
|
106 |
NewMoves = 0; |
|
107 |
for (i=0; i<NumMoves; i++) |
|
108 |
{ |
|
109 |
/* For each direction */ |
|
110 |
for (j=0; j<4; j++) |
|
111 |
{ |
|
112 |
next_pos.x = pos[i].x + move_vectors[j].x; |
|
113 |
next_pos.y = pos[i].y + move_vectors[j].y; |
|
114 |
next_cell = &corners[next_pos.y][next_pos.x]; |
|
115 |
if(*next_cell == BLANK || |
|
116 |
*next_cell == PLATFORM) |
|
117 |
{ |
|
118 |
return FALSE; |
|
119 |
} |
|
120 |
else if(*next_cell == CORNER) |
|
121 |
{ |
|
122 |
new_pos[NewMoves] = next_pos; |
|
123 |
*next_cell = MANCANMOVE; |
|
124 |
NewMoves++; |
|
125 |
} |
|
126 |
} |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
return TRUE; |
|
131 |
} |
|
132 |
||
133 |
int does_box_close_corners(const struct Map * m, const struct Position mov, |
|
134 |
const struct Position box_pos) |
|
135 |
{ |
|
136 |
struct Position p, p2; |
|
137 |
||
138 |
p.x = box_pos.x + mov.x; |
|
139 |
p.y = box_pos.y + mov.y; |
|
140 |
||
141 |
/* Let's plan the checks */ |
|
142 |
/* The point will be marked with a MANCANMOVE */ |
|
143 |
p2.x = p.x + mov.x; |
|
144 |
p2.y = p.y + mov.y; |
|
145 |
if (m->Cells[p2.y][p2.x] == CORNER) |
|
146 |
{ |
|
147 |
if (is_corner_area(m, p2, box_pos, p)) |
|
148 |
return TRUE; |
|
149 |
} |
|
150 |
||
151 |
p2.x = p.x + mov.y; |
|
152 |
p2.y = p.y + mov.x; |
|
153 |
if (m->Cells[p2.y][p2.x] == CORNER) |
|
154 |
{ |
|
155 |
if (is_corner_area(m, p2, box_pos, p)) |
|
156 |
return TRUE; |
|
157 |
} |
|
158 |
||
159 |
p2.x = p.x - mov.y; |
|
160 |
p2.y = p.y - mov.x; |
|
161 |
if (m->Cells[p2.y][p2.x] == CORNER) |
|
162 |
{ |
|
163 |
if (is_corner_area(m, p2, box_pos, p)) |
|
164 |
return TRUE; |
|
165 |
} |
|
166 |
return FALSE; |
|
167 |
} |
|
168 |
#endif |
|
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 | 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 | 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 | 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 | 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 | 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 | 188 |
} |
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 | 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 | 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 | 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 | 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 | 253 |
} |
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 | 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 | 277 |
} |
278 |
return FALSE; |
|
279 |
} |
|
280 |
||
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 | 284 |
{ |
285 |
struct Position pos[MAX_MOVES]; |
|
286 |
struct Position new_pos[MAX_MOVES]; |
|
287 |
int NumMoves, NewMoves; |
|
288 |
int j, i; |
|
289 |
struct Position next_pos; |
|
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 | 292 |
/* Let's the map with only walls in man_moves - other, blanks */ |
293 |
for (j = 0; j<m->SizeY; j++) |
|
294 |
for (i=0; i<m->SizeX; i++) |
|
295 |
{ |
|
296 |
if (m->Cells[j][i] == WALL) |
|
297 |
m->man_moves[j][i] = WALL; |
|
298 |
else |
|
299 |
m->man_moves[j][i] = BLANK; |
|
300 |
} |
|
301 |
||
302 |
/* Let's put the boxes */ |
|
303 |
for (i = 0; i<m->NumBoxes; i++) |
|
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 | 306 |
} |
307 |
||
308 |
NewMoves = 1; |
|
309 |
new_pos[0].x = m->Man.x; |
|
310 |
new_pos[0].y = m->Man.y; |
|
311 |
m->man_moves[m->Man.y][m->Man.x] = MANCANMOVE; |
|
312 |
while (NewMoves > 0) |
|
313 |
{ |
|
314 |
/* The before named "New Moves" become the moves we have |
|
315 |
to analyze */ |
|
316 |
NumMoves = NewMoves; |
|
317 |
for (i=0; i<NewMoves; i++) |
|
318 |
{ |
|
319 |
pos[i] = new_pos[i]; |
|
320 |
} |
|
321 |
||
322 |
/* Search new positions for each position */ |
|
323 |
NewMoves = 0; |
|
324 |
for (i=0; i<NumMoves; i++) |
|
325 |
{ |
|
326 |
/* For each direction */ |
|
327 |
for (j=0; j<4; j++) |
|
328 |
{ |
|
329 |
next_pos.x = pos[i].x + move_vectors[j].x; |
|
330 |
next_pos.y = pos[i].y + move_vectors[j].y; |
|
331 |
next_cell = &m->man_moves[next_pos.y][next_pos.x]; |
|
332 |
if(*next_cell == BLANK) |
|
333 |
{ |
|
334 |
new_pos[NewMoves] = next_pos; |
|
335 |
*next_cell = MANCANMOVE; |
|
336 |
NewMoves++; |
|
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 | 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 | 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 | 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 | 468 |
} |
469 |
} |
|
470 |
} |
|
471 |
||
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 | 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 | 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 | 545 |
} |
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 | 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 | 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 | 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 | 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 | 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 | 575 |
} |
576 |
} |
|
577 |
} |
|
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 | 680 |
} |
681 |
||
682 |
||
683 |
int solve_map(const struct Map origin) |
|
684 |
{ |
|
685 |
struct Map maps[MAX_STEPS+1]; |
|
686 |
struct BoxMove new_movements[MAX_MOVES]; |
|
687 |
int num_new_movements; |
|
688 |
||
689 |
CopyMap(&maps[0], &origin); |
|
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 | 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 | 699 |
} |