Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. protected bool Wave(ESubject subject)
  2. {
  3. int countRow = WorldModel.countRow;
  4. int countColumn = WorldModel.countColumn;
  5. int[,] grid = new int[countRow, countColumn];
  6. Queue<Indices> queue = new Queue<Indices>();
  7. queue.Enqueue(new Indices(model.Y, model.X));
  8. bool found = false;
  9. int step = 1;
  10. Indices end = new Indices();
  11. while (queue.Count > 0 && !found)
  12. {
  13. Indices i = queue.Dequeue();
  14. grid[i.I, i.J] = step;
  15. for (int j = 0; j < 4; j++)
  16. {
  17. i.I += dy[j];
  18. i.J += dx[j];
  19. if (i.I < 0 || i.I >= countRow || i.J < 0 || i.J >= countColumn || grid[i.I,i.J] > 0)
  20. continue;
  21. if (WorldModel.world[i.I, i.J].IsPassable)
  22. {
  23. queue.Enqueue(i);
  24. grid[i.I, i.J] = step + 1;
  25. }
  26. else
  27. {
  28. found = WorldModel.world[i.I, i.J].GetTile == subject;
  29. if (found)
  30. {
  31. end.I = i.I;
  32. end.J = i.J;
  33. grid[i.I, i.J] = step + 1;
  34. break;
  35. }
  36. }
  37. }
  38. step++;
  39. }
  40. return found;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement