Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static Sq findUniquePredecessor(Model model, Sq end) {
- ArrayList<Sq> preds = new ArrayList<Sq>();
- for (int x = 0; x < model.width(); x++) {
- for (int y = 0; y < model.height(); y++) {
- Sq other = model.get(x, y);
- if (other.connectable(end)) {
- preds.add(other);
- }
- }
- }
- if (preds.size() == 1) {
- if (preds.get(0).sequenceNum() > 0 && end.sequenceNum() > 0) {
- if (preds.get(0).sequenceNum() + 1 == end.sequenceNum()) {
- return preds.get(0);
- } else {
- return null;
- }
- }
- return preds.get(0);
- }
- return null;
- }
- static Sq findUniqueSuccessor(Model model, Sq start) {
- ArrayList<Sq> succs = new ArrayList<Sq>();
- for (int x = 0; x < model.width(); x++) {
- for (int y = 0; y < model.height(); y++) {
- Sq other = model.get(x, y);
- if (start.connectable(other)) {
- succs.add(other);
- }
- }
- }
- if (succs.size() > 0
- && succs.get(0).sequenceNum() > 0
- && start.sequenceNum() > 0) {
- return succs.get(0);
- }
- if (succs.size() == 1) {
- return succs.get(0);
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement