Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Direction visibility_age_of_direction(MapLocation current_location, Map& planet_map) {
- std::vector<int> total_visibility_age(8);
- std::vector<std::vector<Square> > squares = planet_map.get_squares();
- int current_x = current_location.get_x();
- int current_y = current_location.get_y();
- for (int y = 0; y<squares.size(); y++) {
- for (int x = 0; x<squares.size(); x++) {
- //if not passable, don't count
- if (!planet_map.get_square_at(x, y).is_passable) { continue; }
- int d_y = y - current_y;
- int d_x = x - current_x;
- if (d_x == 0) {
- if (d_y > 0) {
- total_visibility_age[0] += 1;
- continue;
- }
- else {
- total_visibility_age[4] += 1;
- continue;
- }
- }
- if (d_x == 0) {
- d_y = 0.0000001;
- }
- float ratio = d_y / (double)d_x;
- double pi = 3.1415926535897;
- if (ratio <= tan(pi*22.5 / 180) and ratio >= -1 * tan(pi*22.5 / 180)) {
- if (d_x > 0) {
- total_visibility_age[2] += 1;
- continue;
- }
- else {
- total_visibility_age[6] += 1;
- continue;
- }
- }
- else if (ratio <= tan(pi*67.5 / 180) and ratio >= 1 * tan(pi*22.5 / 180)) {
- if (d_x > 0) {
- total_visibility_age[1] += 1;
- continue;
- }
- else {
- total_visibility_age[5] += 1;
- continue;
- }
- }
- else {
- if (d_x > 0) {
- total_visibility_age[3] += 1;
- continue;
- }
- else {
- total_visibility_age[7] += 1;
- continue;
- }
- }
- }
- }
- Planet this_planet = current_location.get_planet();
- while (total_visibility_age.size() != 0) {
- int max_age = total_visibility_age[0];
- int max_idx = 0;
- for (int i = 1; i<total_visibility_age.size(); i++) {
- if (total_visibility_age[i] > max_age) {
- max_age = total_visibility_age[i];
- max_idx = i;
- }
- }
- switch (max_idx) {
- case 0:
- if (planet_map.get_square_at(current_x, current_y+1).is_passable and coordinate_is_on_map(current_x, current_y+1, planet_map)) {
- return (Direction)max_idx;
- }
- break;
- case 1:
- if (planet_map.get_square_at(current_x+1, current_y+1).is_passable and coordinate_is_on_map(current_x+1, current_y+1, planet_map)) {
- return (Direction)max_idx;
- }
- break;
- case 2:
- if (planet_map.get_square_at(current_x+1, current_y).is_passable and coordinate_is_on_map(current_x+1, current_y, planet_map)) {
- return (Direction)max_idx;}
- break;
- case 3:
- if (planet_map.get_square_at(current_x+1, current_y-1).is_passable and coordinate_is_on_map(current_x+1, current_y-1, planet_map)) {
- return (Direction)max_idx;
- }
- break;
- case 4:
- if (planet_map.get_square_at(current_x, current_y-1).is_passable and coordinate_is_on_map(current_x, current_y-1, planet_map)) {
- return (Direction)max_idx;
- }
- break;
- case 5:
- if (planet_map.get_square_at(current_x-1, current_y-1).is_passable and coordinate_is_on_map(current_x-1, current_y-1, planet_map)) {
- return (Direction)max_idx;
- }
- break;
- case 6:
- if (planet_map.get_square_at(current_x-1, current_y).is_passable and coordinate_is_on_map(current_x-1, current_y, planet_map)) {
- return (Direction)max_idx;
- }
- break;
- case 7:
- if (planet_map.get_square_at(current_x-1, current_y+1).is_passable and coordinate_is_on_map(current_x-1, current_y+1, planet_map)) {
- return (Direction)max_idx;
- }
- break;
- default:
- break;
- }
- total_visibility_age.erase(total_visibility_age.begin()+max_idx);
- }
- Direction smth_is_very_wrong = Center;
- return smth_is_very_wrong;
- //return total_visibility_age;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement