algorithm.c
changeset 26 95fccfcbd04c
parent 25 b37843173279
child 28 cd27cb410375
equal deleted inserted replaced
25:b37843173279 26:95fccfcbd04c
   494 	}
   494 	}
   495 	return 1;
   495 	return 1;
   496 }
   496 }
   497 
   497 
   498 
   498 
   499 int solve_map(const struct Map origin)
   499 int solve_map(const struct Map *origin)
   500 {
   500 {
   501 	struct Map maps[MAX_STEPS+1];
   501 	struct Map *maps;
   502 	struct BoxMove new_movements[MAX_MOVES];
   502 	struct BoxMove new_movements[MAX_MOVES];
   503 	int num_new_movements;
   503 	int num_new_movements;
   504 
   504 	int ret;
   505 	CopyMap(&maps[0], &origin);
   505 
       
   506 	maps = malloc(sizeof(*maps) * (MAX_STEPS+1));
       
   507 
       
   508 	CopyMap(&maps[0], origin);
   506 
   509 
   507 	num_new_movements = get_box_movements(&maps[0], new_movements);
   510 	num_new_movements = get_box_movements(&maps[0], new_movements);
   508 	assert(num_new_movements < MAX_MOVES);
   511 	assert(num_new_movements < MAX_MOVES);
   509 	assert(num_new_movements > 0);
   512 	assert(num_new_movements > 0);
   510 
   513 
   511 	init_os();
   514 	init_os();
   512 
   515 
   513 	return search_depth(maps, 0, new_movements,
   516 	ret = search_depth(maps, 0, new_movements,
   514 		num_new_movements, 100. / num_new_movements,
   517 		num_new_movements, 100. / num_new_movements,
   515 		0);
   518 		0);
   516 
   519 	free(maps);
   517 }
   520 	return ret;
       
   521 }