Advertisement
skatsner

Untitled

Apr 27th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. /* Map.cpp
  2. *
  3. * Created on : Apr 21, 2017
  4. * Author : skatsner
  5. */
  6.  
  7.  
  8. #include <iostream>
  9. #include "Map.h"
  10. #include <string>
  11.  
  12. /** this module contain the map.h and all the functions that changes elements of the map
  13. and move the robot along the map by changing the robots vectors.
  14. is uses robotDB.h to access the robots vectors, and to change them acording to the moves, and uses printer.h to print
  15. the new location. **/
  16.  
  17.  
  18. using namespace std;
  19.  
  20. #define S_HIGH (7) // define the numbers of rows
  21. #define S_WIDTH (7) // define the numbers of columns
  22.  
  23. //this is the map that contains the wall and the pathes
  24. int gmap[S_HIGH][S_WIDTH] =
  25. {
  26. { 0 , 1 , 1 , 1 , 1 , 1 , 1 },
  27. { 1 , 0 , 0 , 0 , 1 , 0 , 1 },
  28. { 0 , 0 , 1 , 1 , 1 , 0 , 1 },
  29. { 1 , 0 , 0 , 0 , 0 , 0 , 1 },
  30. { 1 , 1 , 1 , 0 , 1 , 0 , 1 },
  31. { 1 , 0 , 0 , 0 , 0 , 0 , 1 },
  32. { 1 , 0 , 1 , 1 , 1 , 1 , 1 }
  33. };
  34.  
  35. /**
  36. * ###################### Module functions ######################
  37. */
  38. /** a function to add a dirt anywhere in the location (x,y) on the map**/
  39. void addDirt(const int x, const int y)
  40. {
  41. if (isRobot(x, y)) {
  42. if (inMapLimit(x, y)) {
  43. gmap[x][y] = 1;
  44. }
  45. }
  46.  
  47. }
  48. /** a help function to check if is robot in location (x,y) on the map**/
  49. bool isRobot(const int x, const int y) {
  50. vector<int> *R_X, *R_Y;
  51. R_X = getX();
  52. R_Y = getY();
  53. for (int i = 0; i < R_X->size(); i++) {
  54. if (R_X->at(i) == x && R_Y->at(i) == y) {
  55. return false;
  56. }
  57. }
  58. return true;
  59. }
  60.  
  61. //####################################################################################################
  62.  
  63.  
  64. bool inMapLimit(const int x, const int y)
  65. {
  66. if (x >= 0 && x<S_HIGH && y >= 0 && y<S_WIDTH)
  67. return true;
  68. else
  69. return false;
  70. }
  71.  
  72.  
  73. /** a function to clean anywhere in the location (x,y) on the map**/
  74.  
  75.  
  76. void Clean(const string RobotName)
  77. {
  78. vector<string> Rnames;
  79. vector<int> *R_X, *R_Y, *Ranks1, *Tanks1;
  80. getNames(Rnames);
  81. R_X = getX();
  82. R_Y = getY();
  83. Ranks1 = getRanks();
  84. Tanks1 = getTanks();
  85. for (int i = 0; i < Rnames.size(); i++) {
  86. string name = Rnames[i];
  87. if (name == RobotName)
  88. if (inMapLimit((R_X->at(i)), (R_Y->at(i)))) {
  89. if (Tanks1->at(i) == 5) {
  90. R_X->at(i) = 0;
  91. R_Y->at(i) = 0;
  92. Tanks1->at(i) = 0;
  93. }
  94. if ((gmap[R_Y->at(i)][R_X->at(i)]) == 0) {
  95. Tanks1->at(i)++;
  96. PrintClean(Rnames[i], R_X->at(i), R_Y->at(i));
  97. }
  98. if ((gmap[R_Y->at(i)][R_X->at(i)]) == 1) {
  99. Tanks1->at(i)++;
  100. Ranks1->at(i)++;
  101. gmap[R_Y->at(i)][R_X->at(i)] = 0;
  102. PrintClean(Rnames[i], R_X->at(i), R_Y->at(i));
  103. }
  104. }
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement