1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
/*
* Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod
* Copyright (C) 2021 cyoung06
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package kr.syeyoung.dungeonsguide.roomprocessor.icefill;
import kr.syeyoung.dungeonsguide.config.Config;
import kr.syeyoung.dungeonsguide.config.types.AColor;
import kr.syeyoung.dungeonsguide.dungeon.data.OffsetPointSet;
import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom;
import kr.syeyoung.dungeonsguide.features.FeatureRegistry;
import kr.syeyoung.dungeonsguide.roomprocessor.GeneralRoomProcessor;
import kr.syeyoung.dungeonsguide.roomprocessor.RoomProcessorGenerator;
import kr.syeyoung.dungeonsguide.utils.RenderUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
import java.awt.*;
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 final List<List<BlockPos>> solution = new CopyOnWriteArrayList<List<BlockPos>>();
private final Queue<String> messageQueue = new ConcurrentLinkedQueue<String>();
public RoomProcessorIcePath2(DungeonRoom dungeonRoom) {
super(dungeonRoom);
String levels = (String) dungeonRoom.getDungeonRoomInfo().getProperties().get("levels");
if (levels == null) {
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() {
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;
}
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 tick() {
super.tick();
if (!FeatureRegistry.SOLVER_ICEPATH.isEnabled()) return;
while (!messageQueue.isEmpty()){
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(messageQueue.poll()));
}
}
@Override
public void drawWorld(float partialTicks) {
if (!FeatureRegistry.SOLVER_ICEPATH.isEnabled()) return;
for (List<BlockPos> solution:this.solution)
RenderUtils.drawLines(solution, FeatureRegistry.SOLVER_ICEPATH.getLineColor(),FeatureRegistry.SOLVER_ICEPATH.getLineWidth(), 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;
}
}
|