Slight change to heuristic(no args)

This commit is contained in:
ZacSharp 2020-10-16 01:30:04 +02:00
parent 3cdbc4cb83
commit 9393192036
No known key found for this signature in database
GPG Key ID: 9453647B005083A3
2 changed files with 6 additions and 8 deletions

View File

@ -58,16 +58,15 @@ public class GoalNear implements Goal, IGoalRenderPos {
public double heuristic() {// TODO less hacky solution public double heuristic() {// TODO less hacky solution
int range = (int) Math.ceil(Math.sqrt(rangeSq)); int range = (int) Math.ceil(Math.sqrt(rangeSq));
HashSet<Double> maybeAlwaysInside = new HashSet<>(); HashSet<Double> maybeAlwaysInside = new HashSet<>();
HashSet<Double> sometimesOutside = new HashSet<>(); double minOutside = Double.POSITIVE_INFINITY;
for (int dx = -range; dx <= range; dx++) { for (int dx = -range; dx <= range; dx++) {
for (int dy = -range; dy <= range; dy++) { for (int dy = -range; dy <= range; dy++) {
for (int dz = -range; dz <= range; dz++) { for (int dz = -range; dz <= range; dz++) {
double h = heuristic(x + dx, y + dy, z + dz); double h = heuristic(x + dx, y + dy, z + dz);
if (!sometimesOutside.contains(h) && isInGoal(x + dx, y + dy, z + dz)) { if (h < minOutside && isInGoal(x + dx, y + dy, z + dz)) {
maybeAlwaysInside.add(h); maybeAlwaysInside.add(h);
} else { } else {
maybeAlwaysInside.remove(h); minOutside = Math.min(minOutside, h);
sometimesOutside.add(h);
} }
} }
} }

View File

@ -101,16 +101,15 @@ public class GoalRunAway implements Goal {
maxZ = Math.max(minZ, p.getZ() + distance); maxZ = Math.max(minZ, p.getZ() + distance);
} }
HashSet<Double> maybeAlwaysInside = new HashSet<>(); HashSet<Double> maybeAlwaysInside = new HashSet<>();
HashSet<Double> sometimesOutside = new HashSet<>(); double minOutside = Double.POSITIVE_INFINITY;
for (int x = minX; x <= maxX; x++) { for (int x = minX; x <= maxX; x++) {
for (int y = minY; y <= maxY; y++) { for (int y = minY; y <= maxY; y++) {
for (int z = minZ; z <= maxZ; z++) { for (int z = minZ; z <= maxZ; z++) {
double h = heuristic(x, y, z); double h = heuristic(x, y, z);
if (!sometimesOutside.contains(h) && isInGoal(x, y, z)) { if (h < minOutside && isInGoal(x, y, z)) {
maybeAlwaysInside.add(h); maybeAlwaysInside.add(h);
} else { } else {
maybeAlwaysInside.remove(h); minOutside = Math.min(minOutside, h);
sometimesOutside.add(h);
} }
} }
} }