Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. static Sq findUniquePredecessor(Model model, Sq end) {
  2. ArrayList<Sq> preds = new ArrayList<Sq>();
  3. for (int x = 0; x < model.width(); x++) {
  4. for (int y = 0; y < model.height(); y++) {
  5. Sq other = model.get(x, y);
  6. if (other.connectable(end)) {
  7. preds.add(other);
  8. }
  9. }
  10. }
  11.  
  12. if (preds.size() == 1) {
  13. if (preds.get(0).sequenceNum() > 0 && end.sequenceNum() > 0) {
  14. if (preds.get(0).sequenceNum() + 1 == end.sequenceNum()) {
  15. return preds.get(0);
  16. } else {
  17. return null;
  18. }
  19. }
  20. return preds.get(0);
  21. }
  22. return null;
  23. }
  24.  
  25. static Sq findUniqueSuccessor(Model model, Sq start) {
  26. ArrayList<Sq> succs = new ArrayList<Sq>();
  27. for (int x = 0; x < model.width(); x++) {
  28. for (int y = 0; y < model.height(); y++) {
  29. Sq other = model.get(x, y);
  30. if (start.connectable(other)) {
  31. succs.add(other);
  32. }
  33. }
  34. }
  35.  
  36. if (succs.size() > 0
  37. && succs.get(0).sequenceNum() > 0
  38. && start.sequenceNum() > 0) {
  39. return succs.get(0);
  40. }
  41.  
  42. if (succs.size() == 1) {
  43. return succs.get(0);
  44. }
  45. return null;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement