Skip to content

Commit

Permalink
Improve legacy code
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Oct 10, 2024
1 parent f4fcd9f commit 14602c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@
import com.soulfiremc.server.pathfinding.execution.WorldAction;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
@ToString
@AllArgsConstructor
public class MinecraftRouteNode implements Comparable<MinecraftRouteNode> {
Expand Down Expand Up @@ -56,30 +53,24 @@ public class MinecraftRouteNode implements Comparable<MinecraftRouteNode> {
*/
private double totalRouteScore;

private List<MinecraftRouteNode> children;

public MinecraftRouteNode(NodeState node, MinecraftRouteNode parent, List<WorldAction> actions,
double sourceCost, double totalRouteScore) {
this.node = node;
this.parent = parent;
this.actions = actions;
this.sourceCost = sourceCost;
this.totalRouteScore = totalRouteScore;
this.children = new ArrayList<>();
}

public MinecraftRouteNode(NodeState node, List<WorldAction> actions,
double sourceCost, double totalRouteScore) {
this.node = node;
this.parent = null;
this.actions = actions;
this.sourceCost = sourceCost;
this.totalRouteScore = totalRouteScore;
this.children = new ArrayList<>();
}

@Override
public int compareTo(MinecraftRouteNode other) {
return Double.compare(this.totalRouteScore, other.totalRouteScore);
}

public void setBetterParent(MinecraftRouteNode parent, List<WorldAction> actions, double sourceCost, double totalRouteScore) {
this.parent = parent;
this.actions = actions;
this.sourceCost = sourceCost;
this.totalRouteScore = totalRouteScore;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ public List<WorldAction> findRoute(NodeState from, boolean requiresRepositioning

// If we found a better route to this node, update it
if (newSourceCost < v.sourceCost()) {
v.parent(current);
v.actions(worldActions);
v.sourceCost(newSourceCost);
v.totalRouteScore(newTotalRouteScore);
v.setBetterParent(
current,
worldActions,
newSourceCost,
newTotalRouteScore);

log.debug("Found a better route to node: {}", instructionNode);

Expand Down

0 comments on commit 14602c7

Please sign in to comment.