Skip to content

Commit

Permalink
Added shortest path potion sorting option (hex-agon#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
Notloc authored Oct 30, 2024
1 parent d8d59f9 commit eb462f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Comparator;

public class PotionComparators {

// Sort by modifier, in the order CRYSTALISED > HOMOGENOUS > CONCENTRATED
// And then by PotionType name alphabetically
public static Comparator<PotionOrder> byStation() {
Expand All @@ -21,4 +20,19 @@ public static Comparator<PotionOrder> byStation() {
})
.thenComparing(order -> order.potionType().name());
}

public static Comparator<PotionOrder> shortestPath() {
return Comparator.comparing(order -> {
switch (order.potionModifier()) {
case CRYSTALISED:
return 1;
case CONCENTRATED:
return 2;
case HOMOGENOUS:
return 3;
default:
throw new IllegalStateException("Unexpected value: " + order.potionModifier().toString());
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

public enum PotionOrderSorting {
VANILLA("Vanilla (random)", null),
BY_STATION("By station", PotionComparators.byStation());
BY_STATION("By station", PotionComparators.byStation()),
SHORTEST_PATH("Shortest Path", PotionComparators.shortestPath());

private final String name;
private final Comparator<PotionOrder> comparator;
Expand Down

0 comments on commit eb462f3

Please sign in to comment.