int main( int argc, char **argv){ int c_height,c_width; map_t *map; map = NULL; c_height = 0; c_width = 0; if(argc < 4){ printf("Usage: mars <map> <court width> <court height> \n"); }else{ c_height = atoi(argv[3]); c_width = atoi(argv[2]); map = ld_map_img(argv[1]); } map->c_width = c_width; map->c_height = c_height; map->min = map_min(map); map->max = map_max(map); map->count = count(map); /*if(chk_slope_map(map)){ printf("Yay, it's right!\n"); }*/ int k; map_t *best; map_t *current; best = new_map(map->side); best->cost = 1000000; //find_best(map); for(k=1; k<256; k++){ current = test_pos(map,k,13,509); current->cost = cost(map,current); printf("%ld\t%d\n",current->cost,k); if(current->cost < best->cost){ free_map(best); best = current; best->cost = cost(map,best); best->h = k; } } printf("%ld (%d,%d,%d)\n",best->cost,best->x,best->y,best->h); exit(1); }
map_t map_remove(map_t map, key_t key){ if (map == NULL) printf("The map is already empty!"); else { if (string_less(key,map->key)) map->leftnode = map_remove(map->leftnode, key); else if (string_less(map->key, key)) map->rightnode = map_remove(map->rightnode, key); else { if(map->leftnode == NULL && map->rightnode == NULL){ string_destroy(map->key); string_destroy(map->value); free(map); map = NULL; } else if (map->leftnode == NULL){ map_t mapaux = map; map = map->rightnode; string_destroy(mapaux->key); string_destroy(mapaux->value); free(mapaux); mapaux = NULL; } else if (map->rightnode == NULL){ map_t mapaux = map; map = map->leftnode; string_destroy(mapaux->key); string_destroy(mapaux->value); free(mapaux); mapaux = NULL; } else { map_t mapmin = map_min(map->rightnode); map_t mapaux = map; string_destroy(map->value); string_destroy(map->key); mapmin->leftnode = map->leftnode; map = map->rightnode; free(mapaux); } } } return map; }
map_t map_min(map_t map){ if (map->leftnode != NULL) { map = map_min(map->leftnode); } return map; }