Now I think the code works. There were some indexing mistakse,
authorviric@llimona
Sun, 07 May 2006 15:28:39 +0200
changeset 16 fe078fb2e8b4
parent 15 866013971139
child 17 7c1e68c17c0e
Now I think the code works. There were some indexing mistakse,
return instead of continue, etc.
algorithm.c
--- a/algorithm.c	Sun May 07 13:32:52 2006 +0200
+++ b/algorithm.c	Sun May 07 15:28:39 2006 +0200
@@ -234,18 +234,18 @@
 
 		if (is_new_map(maps, depth+1))
 		{
-			actual_map = &maps[depth+1];
-#ifdef DEBUG		/* to be out */
-			show_percent_and_map();
-#endif
 			fill_deps(m);
 			if (are_there_fixed_boxes(m,
 				new_movements, &num_new_movements))
 			{
 				/* That means that the map is illegal */
 				/* Maybe we could update the percent here... */
-				return FALSE;
+				continue;
 			}
+			actual_map = &maps[depth+1];
+#ifdef DEBUG		/* to be out */
+			show_percent_and_map();
+#endif
 			/* the assert should be IN the function before,
 			   before OVERfilling new_movements */
 			assert(num_new_movements < MAX_MOVES);
@@ -370,6 +370,7 @@
 
 	/* Initialize to 0 the dependency structures */
 	memset((void *) &dep, 0, sizeof(dep));
+	new_free.n=0;
 	for(i=0; i<m->NumBoxes; i++)
 	{
 		new_free.box[i] = FALSE;
@@ -400,9 +401,12 @@
 		{
 			if(m->box_deps[i].dep_dir[d] > 0)
 			{
-				dep.box[i][m->box_deps[i].dep_dir[d]] =
-					TRUE;
-				dep.ndeps[i]++;
+				if (!dep.box[i][m->box_deps[i].dep_dir[d]])
+				{
+					dep.box[i][m->box_deps[i].dep_dir[d]] =
+						TRUE;
+					dep.ndeps[i]++;
+				}
 			} else
 			if(m->box_deps[i].dep_dir[d] == FREE)
 			{
@@ -430,12 +434,13 @@
 		/* For each direction, try if the box can be moved */
 		for(d=0; d<4; d++)
 		{
-			if(m->box_deps[i].dep_dir[d] == FREE)
+			if(m->box_deps[new_free.box[i]].dep_dir[d] == FREE)
 			{
-				add_position3(tpos, m->Box[i], move_vectors[OPPOSITE_DIR(d)])
+				add_position3(tpos, m->Box[new_free.box[i]], move_vectors[OPPOSITE_DIR(d)])
 				if (m->man_moves[tpos.y][tpos.x] == MANCANMOVE)
 				{
-					movements[*num_movements].box = i;
+					movements[*num_movements].box =
+						new_free.box[i];
 					movements[*num_movements].dir =
 						move_vectors[d];
 					(*num_movements)++;
@@ -485,7 +490,7 @@
 					dep.ndeps[j]--;
 					assert(dep.ndeps[j] >= 0);
 					if (dep.ndeps[j] == 0 &&
-						!free.box_is_free[i])
+						!free.box_is_free[tfree.box[i]])
 					{
 						new_free.box[new_free.n++]=j;
 						free.box[free.n++]=j;
@@ -581,7 +586,8 @@
 				   box, we set it up too. */
 
 				/* *** MAYBE IT'S BETTER NOT TO SET IT */
-				if(m->box_deps[i].dep_dir[dir] == FREE)
+				if(m->box_deps[i].dep_dir[OPPOSITE_DIR(dir)]
+					== FREE)
 				{
 				m->box_deps[i].dep_dir[OPPOSITE_DIR(dir)] =
 					m->cells_boxes[n.y][n.x];
@@ -607,7 +613,6 @@
 	fill_deps(&maps[0]);
 	/* Initializing actual_map here AT LEAST gives protection against
 	SIGSEGV */
-	actual_map = &maps[0];
 	assert(!are_there_fixed_boxes(&maps[0], new_movements,
 		&num_new_movements));
 	search_did_found(maps, 0, new_movements, num_new_movements, 100, 0);