ParanoidPanda

Untitled

Nov 11th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int lab[6][10] = { { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  4. { 1, 2, 0, 0, 0, 1, 0, 0, 3, 1 },
  5. { 1, 0, 0, 0, 0, 1, 0, 0, 0, 1 },
  6. { 1, 0, 0, 0, 0, 1, 0, 0, 0, 1 },
  7. { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
  8. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }};
  9.  
  10. class PathFinder{
  11. private:
  12. int in_x, in_y, o_x, o_y, wave;
  13. int l_row = 10, l_col = 6;
  14. std::string savefile;
  15. public:
  16. PathFinder();
  17. void DoWave(int x, int y, int c_wave);
  18. void PrintIt();
  19. };
  20.  
  21. PathFinder::PathFinder(){
  22. for (int i = 0; i < l_col; i++){
  23. for (int j = 0; j < l_row; j++){
  24. if (lab[i][j] == 2){
  25. in_x = j;
  26. in_y = i;
  27. lab[i][j] = 0;
  28. }
  29. else if (lab[i][j] == 3){
  30. o_x = j;
  31. o_y = i;
  32. lab[i][j] = 0;
  33. }
  34. else if (lab[i][j] == 1){
  35. lab[i][j] = -1;
  36. }
  37. }
  38. }
  39. DoWave(in_y, in_x, 0);
  40. }
  41.  
  42. void PathFinder::DoWave(int x, int y, int c_wave){
  43. int s = 0;
  44. PrintIt();
  45. system("pause");
  46. lab[x][y] = c_wave;
  47. if (y + 1 < 10){
  48. if ((lab[x][y + 1] == 0) || ((lab[x][y + 1] != -1) && (lab[x][y + 1] > c_wave))){
  49. DoWave(x, y + 1, c_wave + 1);
  50. }
  51. }
  52. if (x + 1 < 6){
  53. if ((lab[x + 1][y] == 0) || ((lab[x + 1][y] != -1) && (lab[x + 1][y] > c_wave))){
  54. DoWave(x + 1, y, c_wave + 1);
  55. }
  56. }
  57. if (y - 1 >= 0){
  58. if ((lab[x][y - 1] == 0) || ((lab[x][y - 1] != -1) && (lab[x][y - 1] > c_wave))){
  59. DoWave(x, y - 1, c_wave + 1);
  60. }
  61. }
  62. if (x - 1 >= 0){
  63. if ((lab[x - 1][y] == 0) || ((lab[x - 1][y] != -1) && (lab[x - 1][y] > c_wave))){
  64. DoWave(x - 1, y, c_wave + 1);
  65. }
  66. }
  67. }
  68.  
  69. void PathFinder::PrintIt(){
  70. for (int i = 0; i < 6;i++){
  71. for (int j = 0; j < 10; j++){
  72. if (lab[i][j] == -1)
  73. std::cout << char(178) << char(178) << char(178);
  74. else
  75. if (lab[i][j]<10)
  76. std::cout << lab[i][j] << " ";
  77. else
  78. std::cout << lab[i][j] << " ";
  79. }
  80. std::cout << std::endl;
  81. }
  82. }
  83.  
  84. int main(){
  85. PathFinder test;
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment