aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/icefill
diff options
context:
space:
mode:
authorsyeyoung <42869671+cyoung06@users.noreply.github.com>2020-12-07 11:37:30 +0900
committersyeyoung <42869671+cyoung06@users.noreply.github.com>2020-12-07 11:37:30 +0900
commitf1c2c88c6fb0adbdd64df4c0bab13ba83a564264 (patch)
treea3809f3e4597a8090adec49f188a1334d1888469 /src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/icefill
parent8345651586a5c68cfb36f3f3eb1a2a97ceb3a4b7 (diff)
downloadSkyblock-Dungeons-Guide-f1c2c88c6fb0adbdd64df4c0bab13ba83a564264.tar.gz
Skyblock-Dungeons-Guide-f1c2c88c6fb0adbdd64df4c0bab13ba83a564264.tar.bz2
Skyblock-Dungeons-Guide-f1c2c88c6fb0adbdd64df4c0bab13ba83a564264.zip
message
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/icefill')
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/icefill/RoomProcessorIcePath2.java135
1 files changed, 135 insertions, 0 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/icefill/RoomProcessorIcePath2.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/icefill/RoomProcessorIcePath2.java
new file mode 100644
index 00000000..540092bc
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/icefill/RoomProcessorIcePath2.java
@@ -0,0 +1,135 @@
+package kr.syeyoung.dungeonsguide.roomprocessor.icefill;
+
+import kr.syeyoung.dungeonsguide.dungeon.data.OffsetPointSet;
+import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom;
+import kr.syeyoung.dungeonsguide.roomprocessor.GeneralRoomProcessor;
+import kr.syeyoung.dungeonsguide.roomprocessor.RoomProcessorGenerator;
+import kr.syeyoung.dungeonsguide.utils.RenderUtils;
+import net.minecraft.init.Blocks;
+import net.minecraft.util.BlockPos;
+
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.Queue;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+public class RoomProcessorIcePath2 extends GeneralRoomProcessor {
+ private boolean bugged = false;
+
+ private List<List<BlockPos>> solution = new CopyOnWriteArrayList<List<BlockPos>>();
+
+ private Queue<String> messageQueue = new ConcurrentLinkedQueue<String>();
+
+ public RoomProcessorIcePath2(DungeonRoom dungeonRoom) {
+
+ super(dungeonRoom);
+
+ String levels = (String) dungeonRoom.getDungeonRoomInfo().getProperties().get("levels");
+ if (levels == null) {
+ bugged = true;
+ return;
+ }
+
+ for (final String s : levels.split(",")) {
+ try {
+ OffsetPointSet level = (OffsetPointSet) dungeonRoom.getDungeonRoomInfo().getProperties().get(s + "-board");
+ String data = (String) dungeonRoom.getDungeonRoomInfo().getProperties().get(s + "-level");
+ final int width = Integer.parseInt(data.split(":")[0]);
+ final int height = Integer.parseInt(data.split(":")[1]);
+ final int startX = Integer.parseInt(data.split(":")[2]);
+ final int startY = Integer.parseInt(data.split(":")[3]);
+ final int endX = Integer.parseInt(data.split(":")[4]);
+ final int endY = Integer.parseInt(data.split(":")[5]);
+
+ final int[][] map = new int[height][width];
+ final BlockPos[][] map2 = new BlockPos[height][width];
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ map2[y][x] = level.getOffsetPointList().get(y * width + x).getBlockPos(dungeonRoom);
+ map[y][x] = level.getOffsetPointList().get(y * width + x).getBlock(dungeonRoom) == Blocks.air ? 0 : 1;
+ }
+ }
+
+ new Thread() {
+ public void run() {
+ messageQueue.add("§eDungeons Guide §7:: §eIcePath §7:: §fCalculating solution for floor "+s);
+ List<Point> hamiltonianPath = findFirstHamiltonianPath(map, startX, startY, endX, endY);
+ if (hamiltonianPath == null) {
+ messageQueue.add("§eDungeons Guide §7:: §eIcePath §7:: §cCouldn't find solution for floor "+s);
+ return;
+ }
+ messageQueue.add("§eDungeons Guide §7:: §eIcePath §7:: §fFound solution for floor "+s+"!");
+ hamiltonianPath.add(0,new Point(startX, startY));
+ List<BlockPos> poses = new LinkedList<BlockPos>();
+ for (int i = 0; i < hamiltonianPath.size(); i++) {
+ Point p = hamiltonianPath.get(i);
+ poses.add(map2[p.y][p.x]);
+ }
+ solution.add(poses);
+ }
+ }.start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+
+
+ @Override
+ public void drawWorld(float partialTicks) {
+ for (List<BlockPos> solution:this.solution)
+ RenderUtils.drawLines(solution, new Color(0,255,0, 255), partialTicks, true);
+ }
+
+ public static class Generator implements RoomProcessorGenerator<RoomProcessorIcePath2> {
+ @Override
+ public RoomProcessorIcePath2 createNew(DungeonRoom dungeonRoom) {
+ RoomProcessorIcePath2 defaultRoomProcessor = new RoomProcessorIcePath2(dungeonRoom);
+ return defaultRoomProcessor;
+ }
+ }
+
+ private static List<Point> findFirstHamiltonianPath(int[][] map, int startX, int startY, int endX, int endY) {
+ int emptySpace =0;
+ for (int y = 0; y < map.length; y++)
+ for (int x = 0; x < map[y].length; x++)
+ if (map[y][x] == 0) emptySpace++;
+
+ map[startY][startX] = 2;
+
+ return findHamiltonianPath(map, startX, startY, endX, endY, 0, emptySpace-1);
+ }
+
+
+ private static final List<Point> directions = Arrays.asList(new Point(0,-1), new Point(-1,0), new Point(1,0), new Point(0,1));
+ private static LinkedList<Point> findHamiltonianPath(int[][] map, int startX, int startY, int endX, int endY, int depth, int reqDepth) {
+ if (endX == startX && endY == startY) {
+ if (depth != reqDepth) return null;
+ LinkedList<Point> path = new LinkedList<Point>();
+ path.add(new Point(startX, startY));
+ return path;
+ }
+
+ for (Point p : directions) {
+ int y = p.y +startY,x=p.x + startX;
+ if (y <0 || y >= map.length || x <0 || x >= map[0].length || map[y][x] != 0) continue;
+
+ int[][] copiedMap = new int[map.length][map[0].length];
+ for (int y2 = 0; y2 < copiedMap.length; y2++)
+ copiedMap[y2] = map[y2].clone();
+ copiedMap[y][x] = 2;
+
+ LinkedList<Point> potentialRoute = findHamiltonianPath(copiedMap, x,y,endX,endY, depth +1, reqDepth);
+ if (potentialRoute != null) {
+ potentialRoute.addFirst(new Point(x,y));
+ return potentialRoute;
+ }
+ }
+ return null;
+ }
+}