22 final Deque<Position>
path =
new LinkedList<>();
38 int[][] via =
new int[104][104];
39 int[][] cost =
new int[104][104];
44 int destX = target.
getX() - regionX;
45 int destY = target.
getY() - regionY;
46 List<Integer> tileQueueX =
new ArrayList<>(9000);
47 List<Integer> tileQueueY =
new ArrayList<>(9000);
54 boolean foundPath =
false;
55 int pathLength = 4096;
57 while (tail != tileQueueX.size() && tileQueueX.size() < pathLength) {
59 curX = tileQueueX.get(tail);
60 curY = tileQueueY.get(tail);
62 int curAbsX = regionX + curX;
63 int curAbsY = regionY + curY;
65 if (curX == destX && curY == destY) {
76 int thisCost = cost[curX][curY] + 1 + 1;
77 tail = (tail + 1) % pathLength;
79 if (curY > 0 && via[curX][curY - 1] == 0
82 tileQueueY.add(curY - 1);
83 via[curX][curY - 1] = 1;
84 cost[curX][curY - 1] = thisCost;
87 if (curX > 0 && via[curX - 1][curY] == 0
89 tileQueueX.add(curX - 1);
91 via[curX - 1][curY] = 2;
92 cost[curX - 1][curY] = thisCost;
95 if (curY < 104 - 1 && via[curX][curY + 1] == 0
98 tileQueueY.add(curY + 1);
99 via[curX][curY + 1] = 4;
100 cost[curX][curY + 1] = thisCost;
103 if (curX < 104 - 1 && via[curX + 1][curY] == 0
105 tileQueueX.add(curX + 1);
106 tileQueueY.add(curY);
107 via[curX + 1][curY] = 8;
108 cost[curX + 1][curY] = thisCost;
111 if (curX > 0 && curY > 0 && via[curX - 1][curY - 1] == 0
115 tileQueueX.add(curX - 1);
116 tileQueueY.add(curY - 1);
117 via[curX - 1][curY - 1] = 3;
118 cost[curX - 1][curY - 1] = thisCost;
121 if (curX > 0 && curY < 104 - 1 && via[curX - 1][curY + 1] == 0
125 tileQueueX.add(curX - 1);
126 tileQueueY.add(curY + 1);
127 via[curX - 1][curY + 1] = 6;
128 cost[curX - 1][curY + 1] = thisCost;
131 if (curX < 104 - 1 && curY > 0 && via[curX + 1][curY - 1] == 0
135 tileQueueX.add(curX + 1);
136 tileQueueY.add(curY - 1);
137 via[curX + 1][curY - 1] = 9;
138 cost[curX + 1][curY - 1] = thisCost;
141 if (curX < 104 - 1 && curY < 104 - 1 && via[curX + 1][curY + 1] == 0
145 tileQueueX.add(curX + 1);
146 tileQueueY.add(curY + 1);
147 via[curX + 1][curY + 1] = 12;
148 cost[curX + 1][curY + 1] = thisCost;
153 int hippo_max = 1_000;
154 int thisCost = 100 + 1;
157 for (
int x = destX - init_x; x <= destX + init_x; x++) {
158 for (
int y = destY - init_x; y <= destY + init_x; y++) {
159 if (x >= 0 && y >= 0 && x < 104 && y < 104 && cost[x][y] < 100 && cost[x][y] != 0) {
163 }
else if (x > destX + source.
width() - 1) {
164 dx = x - (destX + source.
width() - 1);
169 }
else if (y > destY + source.
length() - 1) {
170 dy = y - (destY + source.
length() - 1);
172 int hippo = dx * dx + dy * dy;
173 if (hippo < hippo_max || hippo == hippo_max && cost[x][y] < thisCost && cost[x][y] != 0) {
175 thisCost = cost[x][y];
183 if (hippo_max == 1000) {
184 return new Path(
null);
189 tileQueueX.set(tail, curX);
190 tileQueueY.set(tail++, curY);
193 for (
int nextVia = vurVia = via[curX][curY]; curX != source.
getPosition().getLocalX() || curY != source.
getPosition().
getLocalY(); nextVia = via[curX][curY]) {
194 if (nextVia != vurVia) {
196 tileQueueX.set(tail, curX);
197 tileQueueY.set(tail++, curY);
199 if ((nextVia & 2) != 0) {
201 }
else if ((nextVia & 8) != 0) {
204 if ((nextVia & 1) != 0) {
206 }
else if ((nextVia & 4) != 0) {
212 int pathX = (regionX) + tileQueueX.get(tail);
213 int pathY = (regionY) + tileQueueY.get(tail);
217 for (
int i = 1; i < s; i++) {
219 pathX = (regionX) + tileQueueX.get(tail);
220 pathY = (regionY) + tileQueueY.get(tail);