tterrag1098

Untitled

Dec 22nd, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. PriorityQueue<Node> search = new PriorityQueue<>(Comparator.comparingInt(Node::getTime));
  2. search.add(new Node(Tool.TORCH, 0, new Point(0, 0)));
  3. Set<Node> seen = new HashSet<>();
  4.  
  5. while (!search.isEmpty()) {
  6. Node head = search.poll();
  7. if (head.getPos().equals(target) && head.getTool() == Tool.TORCH) {
  8. return new Result(risk, head.getTime());
  9. }
  10. Type type = typeCache.get(head.getPos());
  11. Set<Node> validNext = new LinkedHashSet<>();
  12. Direction[] valid = Direction.valid(head.getPos());
  13. for (Direction d : valid) {
  14. Node next = head.move(d);
  15. Type t = typeCache.computeIfAbsent(next.getPos(), p -> getType(erosionCache, p.getX(), p.getY()));
  16. if (t.canUse(next.getTool())) {
  17. validNext.add(next);
  18. }
  19. }
  20. if (validNext.size() < valid.length) {
  21. for (Tool tool : Tool.values()) {
  22. if (tool != head.getTool() && type.canUse(tool)) {
  23. validNext.add(head.withTool(tool));
  24. }
  25. }
  26. }
  27. validNext.removeIf(seen::contains);
  28. validNext.removeIf(n -> n.getPos().getX() > target.getX() + 1000 && n.getPos().getY() > target.getY() + 1000);
  29. seen.addAll(validNext);
  30. search.addAll(validNext);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment