Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4.  
  5. #define LEFT_WALL (1 << 0) //1
  6. #define BOTTOM_WALL (1 << 1) //2
  7. #define RIGHT_WALL (1 << 2) //4
  8. #define TOP_WALL (1 << 3) //8
  9.  
  10. #define TOP_LEFT_CORNER (TOP_WALL | LEFT_WALL)
  11. #define TOP_RIGHT_CORNER (TOP_WALL | RIGHT_WALL)
  12. #define BOTTOM_LEFT_CORNER (BOTTOM_WALL | LEFT_WALL)
  13. #define BOTTOM_RIGHT_CORNER (BOTTOM_WALL | RIGHT_WALL)
  14.  
  15. #define Nmax 100
  16.  
  17. int H[100][100];
  18.  
  19. struct vec2{short x, y;};
  20.  
  21. struct Room
  22. {
  23. vec2 topLeft;
  24. vec2 bottomleft;
  25. vec2 topRight;
  26. vec2 bottomRight;
  27. };
  28. using namespace std;
  29. std::vector<Room> rooms;
  30.  
  31. inline void CreateRoom(int x, int y)
  32. {
  33. Room room;
  34.  
  35. room.topLeft.x = x;
  36. room.topLeft.y = y;
  37.  
  38. std::cout << "Creating room at " << x<< " " << y << std::endl;
  39.  
  40. //top right
  41. int x_ = x;
  42. while(H[x_][y] != TOP_RIGHT_CORNER)
  43. {
  44. x_++;
  45. //cout << "topright" << std::endl;
  46. }
  47.  
  48.  
  49. room.topRight.x = x_;
  50. room.topRight.y = y;
  51.  
  52. //bottom left
  53. int y_ = y;
  54. while(H[x][y_] != BOTTOM_LEFT_CORNER){
  55. y_++;
  56. cout << "bottomleft" << std::endl;
  57. }
  58.  
  59. room.bottomleft.x = x;
  60. room.bottomleft.y = y_;
  61.  
  62. //bottom right
  63. x_ = x;
  64. while(H[x_][y_] != BOTTOM_RIGHT_CORNER){
  65. x_++;
  66. cout << "bottomright" << std::endl;
  67. }
  68.  
  69. room.bottomRight.x = x_;
  70. room.bottomRight.y = y_;
  71.  
  72. rooms.push_back(room);
  73. }
  74.  
  75. int main()
  76. {
  77. int c; //mode
  78. int n; //size
  79.  
  80. std::ifstream input("test");
  81. std::ofstream output("testoutput");
  82. input >> c;
  83. input >> n;
  84.  
  85. cout << "TOP_RIGHT = " << TOP_LEFT_CORNER <<endl;
  86.  
  87. if(n > 100)
  88. {
  89. std::cout << "halo nem szabad";
  90. return 0;
  91. }
  92.  
  93. for(int i =0 ; i < n ;i++)
  94. {
  95. for(int j =0 ; j < n ;j++)
  96. {
  97. input >> H[j][i];
  98. }
  99. }
  100.  
  101. for(int i =0 ; i < n ;i++)
  102. {
  103. for(int j =0 ; j < n ;j++)
  104. {
  105. if(H[i][j] & TOP_LEFT_CORNER)
  106. {
  107. CreateRoom(i,j);
  108. }
  109. }
  110. }
  111.  
  112.  
  113. if(c == 1)
  114. output << rooms.size();
  115.  
  116.  
  117. return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement