Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. Direction visibility_age_of_direction(MapLocation current_location, Map& planet_map) {
  2.  
  3. std::vector<int> total_visibility_age(8);
  4.  
  5. std::vector<std::vector<Square> > squares = planet_map.get_squares();
  6. int current_x = current_location.get_x();
  7. int current_y = current_location.get_y();
  8.  
  9. for (int y = 0; y<squares.size(); y++) {
  10. for (int x = 0; x<squares.size(); x++) {
  11. //if not passable, don't count
  12. if (!planet_map.get_square_at(x, y).is_passable) { continue; }
  13. int d_y = y - current_y;
  14. int d_x = x - current_x;
  15. if (d_x == 0) {
  16. if (d_y > 0) {
  17. total_visibility_age[0] += 1;
  18. continue;
  19. }
  20. else {
  21. total_visibility_age[4] += 1;
  22. continue;
  23. }
  24. }
  25. if (d_x == 0) {
  26. d_y = 0.0000001;
  27. }
  28. float ratio = d_y / (double)d_x;
  29. double pi = 3.1415926535897;
  30.  
  31. if (ratio <= tan(pi*22.5 / 180) and ratio >= -1 * tan(pi*22.5 / 180)) {
  32. if (d_x > 0) {
  33. total_visibility_age[2] += 1;
  34. continue;
  35. }
  36. else {
  37. total_visibility_age[6] += 1;
  38. continue;
  39. }
  40. }
  41. else if (ratio <= tan(pi*67.5 / 180) and ratio >= 1 * tan(pi*22.5 / 180)) {
  42. if (d_x > 0) {
  43. total_visibility_age[1] += 1;
  44. continue;
  45. }
  46. else {
  47. total_visibility_age[5] += 1;
  48. continue;
  49. }
  50. }
  51. else {
  52. if (d_x > 0) {
  53. total_visibility_age[3] += 1;
  54. continue;
  55. }
  56. else {
  57. total_visibility_age[7] += 1;
  58. continue;
  59. }
  60. }
  61. }
  62. }
  63. Planet this_planet = current_location.get_planet();
  64. while (total_visibility_age.size() != 0) {
  65. int max_age = total_visibility_age[0];
  66. int max_idx = 0;
  67.  
  68. for (int i = 1; i<total_visibility_age.size(); i++) {
  69. if (total_visibility_age[i] > max_age) {
  70. max_age = total_visibility_age[i];
  71. max_idx = i;
  72. }
  73. }
  74.  
  75. switch (max_idx) {
  76. case 0:
  77. 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)) {
  78. return (Direction)max_idx;
  79. }
  80. break;
  81. case 1:
  82. 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)) {
  83. return (Direction)max_idx;
  84. }
  85. break;
  86. case 2:
  87. 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)) {
  88. return (Direction)max_idx;}
  89.  
  90. break;
  91. case 3:
  92. 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)) {
  93. return (Direction)max_idx;
  94. }
  95. break;
  96. case 4:
  97. 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)) {
  98. return (Direction)max_idx;
  99. }
  100. break;
  101. case 5:
  102. 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)) {
  103. return (Direction)max_idx;
  104. }
  105. break;
  106. case 6:
  107. 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)) {
  108. return (Direction)max_idx;
  109. }
  110. break;
  111. case 7:
  112. 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)) {
  113. return (Direction)max_idx;
  114. }
  115. break;
  116. default:
  117. break;
  118. }
  119. total_visibility_age.erase(total_visibility_age.begin()+max_idx);
  120. }
  121. Direction smth_is_very_wrong = Center;
  122. return smth_is_very_wrong;
  123. //return total_visibility_age;
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement