Porting from sokoban/caixes the show_map changes.
authorviric@llimona
Sun, 07 May 2006 13:34:25 +0200
changeset 25 b37843173279
parent 24 bb3bb8584190
child 26 95fccfcbd04c
Porting from sokoban/caixes the show_map changes. Corrects possible sigsegv because of actual_map. Better separation of sigalarm display / not-signal display.
algorithm.c
general.h
os.c
--- a/algorithm.c	Sun May 07 13:33:25 2006 +0200
+++ b/algorithm.c	Sun May 07 13:34:25 2006 +0200
@@ -453,6 +453,8 @@
 		if (m->NumPlatforms == m->NumBoxesInPlatform)
 		{
 			PrintMove(movements[i]);
+			actual_map = &maps[depth+1];
+			show_percent_and_map();
 			return 0;
 		}
 
@@ -470,7 +472,7 @@
 			depth_to_show = depth;
 			actual_map = &maps[depth];
 #ifdef DEBUG		/* to be out */
-			show_percent_callback(0);
+			show_percent_and_map();
 #endif
 	
 		}
@@ -483,6 +485,8 @@
 					total_percent + next_percent*i) == 0)
 				{
 					PrintMove(movements[i]);
+					actual_map = &maps[depth+1];
+					show_percent_and_map();
 					return 0;
 				}
 			}
--- a/general.h	Sun May 07 13:33:25 2006 +0200
+++ b/general.h	Sun May 07 13:34:25 2006 +0200
@@ -80,6 +80,7 @@
 void ShowMap (const struct Map *M);
 void init_os();
 void PrintMove(struct BoxMove b);
+void show_percent_and_map();
 
 /* Functions related to map solution
  * algorithm.c */
--- a/os.c	Sun May 07 13:33:25 2006 +0200
+++ b/os.c	Sun May 07 13:34:25 2006 +0200
@@ -13,7 +13,7 @@
 int max_depth = 0;
 int min_depth_period = 0;
 int max_depth_period = 0;
-struct Map * actual_map;
+struct Map * actual_map = NULL;
 
 
 void ReadMap(struct Map *M, char *FileName)
@@ -123,28 +123,32 @@
 	}
 #endif
 
-	printf("Man is at (%i,%i)\n", Temp.Man.x, Temp.Man.y);
-	printf("Platforms: %i, BoxesInPlatform: %i\n", Temp.NumPlatforms,
+	fprintf(stderr,"Man is at (%i,%i)\n", Temp.Man.x, Temp.Man.y);
+	fprintf(stderr,"Platforms: %i, BoxesInPlatform: %i\n", Temp.NumPlatforms,
 			Temp.NumBoxesInPlatform);
 
 }
 
 void PrintMove(const struct BoxMove b)
 {
-	printf("Box: %i, Direction: {%i,%i}\n", b.box, b.dir.x, b.dir.y);
+	fprintf(stderr,"Box: %i, Direction: {%i,%i}\n", b.box, b.dir.x, b.dir.y);
+}
+
+void show_percent_and_map()
+{
+	fprintf(stderr, "Percent: %2.12f, depth: %i-%i\n", percent_to_show,
+		min_depth_period, max_depth_period);
+	if(actual_map != NULL)
+		ShowMap(actual_map);
+	fflush(stderr);
+	min_depth_period = MAX_STEPS;
+	max_depth_period = 0;
 }
 
 static void show_percent_callback(const int parameter)
 {
-	fprintf(stderr, "Percent: %2.12f, depth: %i-%i\n", percent_to_show,
-		min_depth_period, max_depth_period);
-	ShowMap(actual_map);
-	fflush(stderr);
-	min_depth_period = MAX_STEPS;
-	max_depth_period = 0;
-#ifndef DEBUG
+	show_percent_and_map();
 	alarm(ALARM_SECONDS);
-#endif
 }
 
 static void program_alarm()
@@ -164,5 +168,8 @@
 
 void init_os()
 {
+#ifndef DEBUG
 	program_alarm();
+#endif
 }
+