end of an era. stop randomizing movements
This commit is contained in:
parent
e16bc5eca4
commit
15fa12fe08
@ -39,7 +39,6 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The actual A* pathfinding
|
* The actual A* pathfinding
|
||||||
@ -50,8 +49,6 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
|||||||
|
|
||||||
private final Optional<HashSet<BetterBlockPos>> favoredPositions;
|
private final Optional<HashSet<BetterBlockPos>> favoredPositions;
|
||||||
|
|
||||||
private final Random random = new Random();
|
|
||||||
|
|
||||||
public AStarPathFinder(BlockPos start, Goal goal, Optional<Collection<BetterBlockPos>> favoredPositions) {
|
public AStarPathFinder(BlockPos start, Goal goal, Optional<Collection<BetterBlockPos>> favoredPositions) {
|
||||||
super(start, goal);
|
super(start, goal);
|
||||||
this.favoredPositions = favoredPositions.map(HashSet::new); // <-- okay this is epic
|
this.favoredPositions = favoredPositions.map(HashSet::new); // <-- okay this is epic
|
||||||
@ -107,8 +104,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
|||||||
logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered");
|
logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered");
|
||||||
return Optional.of(new Path(startNode, currentNode, numNodes, goal));
|
return Optional.of(new Path(startNode, currentNode, numNodes, goal));
|
||||||
}
|
}
|
||||||
Movement[] possibleMovements = getConnectedPositions(currentNodePos, calcContext);//movement that we could take that start at currentNodePos, in random order
|
Movement[] possibleMovements = getConnectedPositions(currentNodePos, calcContext);//movement that we could take that start at currentNodePos
|
||||||
shuffle(possibleMovements);
|
|
||||||
for (Movement movementToGetToNeighbor : possibleMovements) {
|
for (Movement movementToGetToNeighbor : possibleMovements) {
|
||||||
if (movementToGetToNeighbor == null) {
|
if (movementToGetToNeighbor == null) {
|
||||||
continue;
|
continue;
|
||||||
@ -248,14 +244,4 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
|||||||
MovementParkour.generate(pos, EnumFacing.SOUTH, calcContext),
|
MovementParkour.generate(pos, EnumFacing.SOUTH, calcContext),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> void shuffle(T[] list) {
|
|
||||||
int len = list.length;
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
int j = random.nextInt(len);
|
|
||||||
T t = list[j];
|
|
||||||
list[j] = list[i];
|
|
||||||
list[i] = t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user