Advertisement
namereq

Untitled

Jun 17th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. enum Direction {
  5.     START,
  6.     UP,
  7.     DOWN,
  8.     LEFT,
  9.     RIGHT
  10. };
  11.  
  12. using MapData = std::vector<std::vector<int>>;
  13.  
  14. MapData gMapData =
  15. {
  16. { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
  17. { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
  18. { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
  19. { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
  20. { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
  21. { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
  22. { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
  23. { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
  24. { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
  25. { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
  26. };
  27.  
  28. void A(int x, int y);
  29. void B(int x, int y, int start, Direction dir);
  30. int main()
  31. {
  32.     A(5, 5);
  33.     for (size_t i = 0; i < gMapData.size(); i++)
  34.     {
  35.         for (size_t j = 0; j < gMapData.size(); j++)
  36.         {
  37.             std::cout << gMapData[i][j] << ',';
  38.         }
  39.         std::cout << std::endl;
  40.     }
  41.     return 0;
  42. }
  43.  
  44. void A(int x, int y)
  45. {
  46.     B(x, y, 0, START);
  47. }
  48. void B(int x, int y, int move, Direction dir)
  49. {
  50.     std::cout << move << std::endl;
  51.     std::cout << "(" << x << "," << y << ")" << std::endl;
  52.     gMapData[y][x] = move;
  53.     move++;
  54.  
  55.     int up = y + 1;
  56.     int down = y - 1;
  57.     int left = x - 1;
  58.     int right = x + 1;
  59.     if (dir != UP && down >= 0 && gMapData[down][x] == -1)
  60.     {
  61.         B(x, down, move, dir == START ? DOWN : dir);
  62.     }
  63.     if (dir != DOWN && up < (int)gMapData.size() && gMapData[up][x] == -1)
  64.     {
  65.         B(x, up, move, dir == START ? UP : dir);
  66.     }
  67.     if (dir != RIGHT && left >= 0 && gMapData[y][left] == -1)
  68.     {
  69.         B(left, y, move, dir == START ? LEFT : dir);
  70.     }
  71.     if (dir != LEFT && right < (int)gMapData[0].size() && gMapData[y][right] == -1)
  72.     {
  73.         B(right, y, move, dir == START ? RIGHT : dir);
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement