os.c
changeset 25 b37843173279
parent 10 9148590f009d
child 26 95fccfcbd04c
equal deleted inserted replaced
24:bb3bb8584190 25:b37843173279
    11 int depth_to_show = 0;
    11 int depth_to_show = 0;
    12 
    12 
    13 int max_depth = 0;
    13 int max_depth = 0;
    14 int min_depth_period = 0;
    14 int min_depth_period = 0;
    15 int max_depth_period = 0;
    15 int max_depth_period = 0;
    16 struct Map * actual_map;
    16 struct Map * actual_map = NULL;
    17 
    17 
    18 
    18 
    19 void ReadMap(struct Map *M, char *FileName)
    19 void ReadMap(struct Map *M, char *FileName)
    20 {
    20 {
    21 	FILE *Fitxer;
    21 	FILE *Fitxer;
   121 			printf("%c", Temp.ManMoves[j][i]);
   121 			printf("%c", Temp.ManMoves[j][i]);
   122 		printf("\n");
   122 		printf("\n");
   123 	}
   123 	}
   124 #endif
   124 #endif
   125 
   125 
   126 	printf("Man is at (%i,%i)\n", Temp.Man.x, Temp.Man.y);
   126 	fprintf(stderr,"Man is at (%i,%i)\n", Temp.Man.x, Temp.Man.y);
   127 	printf("Platforms: %i, BoxesInPlatform: %i\n", Temp.NumPlatforms,
   127 	fprintf(stderr,"Platforms: %i, BoxesInPlatform: %i\n", Temp.NumPlatforms,
   128 			Temp.NumBoxesInPlatform);
   128 			Temp.NumBoxesInPlatform);
   129 
   129 
   130 }
   130 }
   131 
   131 
   132 void PrintMove(const struct BoxMove b)
   132 void PrintMove(const struct BoxMove b)
   133 {
   133 {
   134 	printf("Box: %i, Direction: {%i,%i}\n", b.box, b.dir.x, b.dir.y);
   134 	fprintf(stderr,"Box: %i, Direction: {%i,%i}\n", b.box, b.dir.x, b.dir.y);
       
   135 }
       
   136 
       
   137 void show_percent_and_map()
       
   138 {
       
   139 	fprintf(stderr, "Percent: %2.12f, depth: %i-%i\n", percent_to_show,
       
   140 		min_depth_period, max_depth_period);
       
   141 	if(actual_map != NULL)
       
   142 		ShowMap(actual_map);
       
   143 	fflush(stderr);
       
   144 	min_depth_period = MAX_STEPS;
       
   145 	max_depth_period = 0;
   135 }
   146 }
   136 
   147 
   137 static void show_percent_callback(const int parameter)
   148 static void show_percent_callback(const int parameter)
   138 {
   149 {
   139 	fprintf(stderr, "Percent: %2.12f, depth: %i-%i\n", percent_to_show,
   150 	show_percent_and_map();
   140 		min_depth_period, max_depth_period);
       
   141 	ShowMap(actual_map);
       
   142 	fflush(stderr);
       
   143 	min_depth_period = MAX_STEPS;
       
   144 	max_depth_period = 0;
       
   145 #ifndef DEBUG
       
   146 	alarm(ALARM_SECONDS);
   151 	alarm(ALARM_SECONDS);
   147 #endif
       
   148 }
   152 }
   149 
   153 
   150 static void program_alarm()
   154 static void program_alarm()
   151 {
   155 {
   152         struct sigaction my_action;
   156         struct sigaction my_action;
   162 	alarm(1);
   166 	alarm(1);
   163 }
   167 }
   164 
   168 
   165 void init_os()
   169 void init_os()
   166 {
   170 {
       
   171 #ifndef DEBUG
   167 	program_alarm();
   172 	program_alarm();
       
   173 #endif
   168 }
   174 }
       
   175