Skip to content

Commit

Permalink
Re-included RANDOM loop, randomized this time
Browse files Browse the repository at this point in the history
  • Loading branch information
casals committed Jun 22, 2019
1 parent f06925c commit 00cefae
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ public BehaviorState modify(Actor actor, BehaviorState result) {

private WalkableBlock findRandomNearbyBlock(WalkableBlock startBlock) {
WalkableBlock currentBlock = startBlock;

WalkableBlock[] neighbors = currentBlock.neighbors;
List<WalkableBlock> existingNeighbors = Lists.newArrayList();
for (WalkableBlock neighbor : neighbors) {
if (neighbor != null) {
existingNeighbors.add(neighbor);
for (int i = 0; i < random.nextInt(10) + 1; i++) {
WalkableBlock[] neighbors = currentBlock.neighbors;
List<WalkableBlock> existingNeighbors = Lists.newArrayList();
for (WalkableBlock neighbor : neighbors) {
if (neighbor != null) {
existingNeighbors.add(neighbor);
}
}
if (existingNeighbors.size() > 0) {
currentBlock = existingNeighbors.get(random.nextInt(existingNeighbors.size()));
}
}
if (existingNeighbors.size() > 0) {
currentBlock = existingNeighbors.get(random.nextInt(existingNeighbors.size()));
}

logger.debug(String.format("Looking for a block: my block is %s, found destination %s", startBlock.getBlockPosition(), currentBlock.getBlockPosition()));
return currentBlock;
}
Expand Down

0 comments on commit 00cefae

Please sign in to comment.