From f1c2c88c6fb0adbdd64df4c0bab13ba83a564264 Mon Sep 17 00:00:00 2001 From: syeyoung <42869671+cyoung06@users.noreply.github.com> Date: Mon, 7 Dec 2020 11:37:30 +0900 Subject: message --- .../roomprocessor/ProcessorFactory.java | 1 + .../roomprocessor/RoomProcessorIcePath2.java | 125 ------------------- .../roomprocessor/RoomProcessorRiddle.java | 2 +- .../roomprocessor/RoomProcessorTrivia.java | 6 +- .../boxpuzzle/RoomProcessorBoxSolver.java | 4 +- .../icefill/RoomProcessorIcePath2.java | 135 +++++++++++++++++++++ 6 files changed, 142 insertions(+), 131 deletions(-) delete mode 100644 src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorIcePath2.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/icefill/RoomProcessorIcePath2.java (limited to 'src/main/java/kr') diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/ProcessorFactory.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/ProcessorFactory.java index 44bc9fb6..118d92b7 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/ProcessorFactory.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/ProcessorFactory.java @@ -1,6 +1,7 @@ package kr.syeyoung.dungeonsguide.roomprocessor; import kr.syeyoung.dungeonsguide.roomprocessor.boxpuzzle.RoomProcessorBoxSolver; +import kr.syeyoung.dungeonsguide.roomprocessor.icefill.RoomProcessorIcePath2; import kr.syeyoung.dungeonsguide.roomprocessor.waterpuzzle.RoomProcessorWaterPuzzle; import java.util.HashMap; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorIcePath2.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorIcePath2.java deleted file mode 100644 index 65485ea0..00000000 --- a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorIcePath2.java +++ /dev/null @@ -1,125 +0,0 @@ -package kr.syeyoung.dungeonsguide.roomprocessor; - -import kr.syeyoung.dungeonsguide.dungeon.data.OffsetPoint; -import kr.syeyoung.dungeonsguide.dungeon.data.OffsetPointSet; -import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; -import kr.syeyoung.dungeonsguide.utils.RenderUtils; -import kr.syeyoung.dungeonsguide.utils.TextUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.init.Blocks; -import net.minecraft.util.BlockPos; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.IChatComponent; - -import java.awt.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; -import java.util.regex.Pattern; - -public class RoomProcessorIcePath2 extends GeneralRoomProcessor { - private boolean bugged = false; - - private List> solution = new ArrayList>(); - - public RoomProcessorIcePath2(DungeonRoom dungeonRoom) { - - super(dungeonRoom); - - String levels = (String) dungeonRoom.getDungeonRoomInfo().getProperties().get("levels"); - if (levels == null) { - bugged = true; - return; - } - - for (String s : levels.split(",")) { - try { - OffsetPointSet level = (OffsetPointSet) dungeonRoom.getDungeonRoomInfo().getProperties().get(s + "-board"); - String data = (String) dungeonRoom.getDungeonRoomInfo().getProperties().get(s + "-level"); - int width = Integer.parseInt(data.split(":")[0]); - int height = Integer.parseInt(data.split(":")[1]); - int startX = Integer.parseInt(data.split(":")[2]); - int startY = Integer.parseInt(data.split(":")[3]); - int endX = Integer.parseInt(data.split(":")[4]); - int endY = Integer.parseInt(data.split(":")[5]); - - int[][] map = new int[height][width]; - 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; - } - } - - List hamiltonianPath = findFirstHamiltonianPath(map, startX, startY, endX, endY); - if (hamiltonianPath == null) continue; - hamiltonianPath.add(0,new Point(startX, startY)); - List poses = new LinkedList(); - for (int i = 0; i < hamiltonianPath.size(); i++) { - Point p = hamiltonianPath.get(i); - poses.add(map2[p.y][p.x]); - } - solution.add(poses); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - - - @Override - public void drawWorld(float partialTicks) { - for (List solution:this.solution) - RenderUtils.drawLines(solution, new Color(0,255,0, 255), partialTicks, true); - } - - public static class Generator implements RoomProcessorGenerator { - @Override - public RoomProcessorIcePath2 createNew(DungeonRoom dungeonRoom) { - RoomProcessorIcePath2 defaultRoomProcessor = new RoomProcessorIcePath2(dungeonRoom); - return defaultRoomProcessor; - } - } - - private static List 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 directions = Arrays.asList(new Point(0,-1), new Point(-1,0), new Point(1,0), new Point(0,1)); - private static LinkedList 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 path = new LinkedList(); - 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 potentialRoute = findHamiltonianPath(copiedMap, x,y,endX,endY, depth +1, reqDepth); - if (potentialRoute != null) { - potentialRoute.addFirst(new Point(x,y)); - return potentialRoute; - } - } - return null; - } -} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorRiddle.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorRiddle.java index 800b34f7..35b32094 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorRiddle.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorRiddle.java @@ -52,7 +52,7 @@ public class RoomProcessorRiddle extends GeneralRoomProcessor { } } if (foundMatch) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide :::: "+ch2.split(":")[0].trim()+" §fhas the reward!")); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §eRiddle §7:: "+ch2.split(":")[0].trim()+" §fhas the reward!")); final String name = TextUtils.stripColor(ch2.split(":")[0]).replace("[NPC] ","").toLowerCase(); final BlockPos low = getDungeonRoom().getMin(); final BlockPos high = getDungeonRoom().getMax(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorTrivia.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorTrivia.java index 05d236e1..d5b60845 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorTrivia.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorTrivia.java @@ -97,11 +97,11 @@ public class RoomProcessorTrivia extends GeneralRoomProcessor { String theRealAnswer = match(question, answerA, answerB, answerC); if (theRealAnswer == null) - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide :::: §cCouldn't determine the answer! (no question found)")); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §eTrivia §7:: §cCouldn't determine the answer! (no question found)")); else if (theRealAnswer.length() >1) - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide :::: §cCouldn't determine the answer! ("+theRealAnswer+")")); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §eTrivia §7:: §cCouldn't determine the answer! ("+theRealAnswer+")")); else - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide :::: §6"+theRealAnswer+"§f is the correct answer!")); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §eTrivia §7:: "+theRealAnswer+"§f is the correct answer!")); correctAnswer = theRealAnswer; } String correctAnswer; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/boxpuzzle/RoomProcessorBoxSolver.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/boxpuzzle/RoomProcessorBoxSolver.java index e907671a..9b45b4a9 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/boxpuzzle/RoomProcessorBoxSolver.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/boxpuzzle/RoomProcessorBoxSolver.java @@ -121,7 +121,7 @@ public class RoomProcessorBoxSolver extends GeneralRoomProcessor { if (calcDone2) { BoxPuzzleSolvingThread.Route semi_solution = puzzleSolvingThread.solution; if (semi_solution == null) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide :::: §cCouldn't find solution involving less than 20 box moves within 3m concurrent possibility")); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §eBox Solver §7:: §cCouldn't find solution involving less than 20 box moves within 3m concurrent possibility")); step = 0; calcDone2 = false; pathFindReq = true; @@ -131,7 +131,7 @@ public class RoomProcessorBoxSolver extends GeneralRoomProcessor { return; } else{ solution = semi_solution.boxMoves; - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide :::: Solution Found!")); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §eBox Solver §7:: Solution Found!")); } step = 0; lastState = currboard; 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> solution = new CopyOnWriteArrayList>(); + + private Queue messageQueue = new ConcurrentLinkedQueue(); + + 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 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 poses = new LinkedList(); + 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 solution:this.solution) + RenderUtils.drawLines(solution, new Color(0,255,0, 255), partialTicks, true); + } + + public static class Generator implements RoomProcessorGenerator { + @Override + public RoomProcessorIcePath2 createNew(DungeonRoom dungeonRoom) { + RoomProcessorIcePath2 defaultRoomProcessor = new RoomProcessorIcePath2(dungeonRoom); + return defaultRoomProcessor; + } + } + + private static List 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 directions = Arrays.asList(new Point(0,-1), new Point(-1,0), new Point(1,0), new Point(0,1)); + private static LinkedList 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 path = new LinkedList(); + 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 potentialRoute = findHamiltonianPath(copiedMap, x,y,endX,endY, depth +1, reqDepth); + if (potentialRoute != null) { + potentialRoute.addFirst(new Point(x,y)); + return potentialRoute; + } + } + return null; + } +} -- cgit