Guest User

Untitled

a guest
Oct 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8.  
  9. namespace Lines
  10. {
  11. class Wave
  12. {
  13. private int[][] mas;
  14. private Point start;
  15. private Point finish;
  16. private Size size;
  17. private List<Point> short_path = new List<Point>();
  18. public Wave(int[][] mas_1, Point start_1, Point finish_1)
  19. {
  20. mas = mas_1;
  21. start = finish_1;
  22. finish = start_1;
  23. size = new Size(mas.Length, mas.First().Length);
  24. MessageBox.Show(mas[start.X][start.Y].ToString());
  25. }
  26. public void SetParameters(int[][] mas_1, Point start_1, Point finish_1)
  27. {
  28. mas = mas_1;
  29. start = finish_1;
  30. finish = start_1;
  31. size = new Size(mas.Length, mas[0].Length);
  32. }
  33. public Point[] GetPath()
  34. {
  35. for (int i = -1; NextStep(i); ++i) ;
  36. return short_path.ToArray();
  37. }
  38. private bool NextStep(int step)
  39. {
  40. for (int i = 0; i != size.Width; ++i)
  41. {
  42. for (int j = 0; j != size.Height; ++j)
  43. {
  44. if (mas[i][j] == -2)
  45. {
  46. short_path.Add(new Point(i, j));
  47. for (; step != -3; --step)
  48. {
  49. if (short_path.Last().X != 0)
  50. if (mas[short_path.Last().X - 1][short_path.Last().Y] == step)
  51. short_path.Add(new Point(short_path.Last().X - 1, short_path.Last().Y));
  52. if (short_path.Last().Y != size.Width - 1)
  53. if (mas[short_path.Last().X][short_path.Last().Y + 1] == step)
  54. short_path.Add(new Point(short_path.Last().X, short_path.Last().Y + 1));
  55. if (short_path.Last().X != size.Height - 1)
  56. if (mas[short_path.Last().X + 1][short_path.Last().Y] == step)
  57. short_path.Add(new Point(short_path.Last().X + 1, short_path.Last().Y));
  58. if (short_path.Last().Y != 0)
  59. if (mas[short_path.Last().X][short_path.Last().Y - 1] == step)
  60. short_path.Add(new Point(short_path.Last().X, short_path.Last().Y - 1));
  61. }
  62. return false;
  63. }
  64. if (mas[i][j] == step)
  65. {
  66. if (i != 0)
  67. if (mas[i - 1][j] == 0)
  68. mas[i - 1][j] = step + 1;
  69. if (j != size.Width - 1)
  70. if (mas[i][j + 1] == 0)
  71. mas[i][j + 1] = step + 1;
  72. if (i != size.Height - 1)
  73. if (mas[i + 1][j] == 0)
  74. mas[i + 1][j] = step + 1;
  75. if (j != 0)
  76. if (mas[i][j - 1] == 0)
  77. mas[i][j - 1] = step + 1;
  78. }
  79. }
  80. }
  81. return false;
  82. }
  83. }
  84. }
Add Comment
Please, Sign In to add comment