Skip to content

Commit

Permalink
Handle empty lists of valid locations (#1773)
Browse files Browse the repository at this point in the history
  • Loading branch information
pstalcup authored Dec 13, 2023
1 parent da26d6c commit 4231f36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/garbo-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "garbo-lib",
"version": "0.0.4",
"version": "0.0.5",
"license": "MIT",
"repository": "https://github.com/loathers/garbage-collector.git",
"description": "A library for sequencing turns resource-optimally",
Expand Down
16 changes: 10 additions & 6 deletions packages/garbo-lib/src/wanderer/freefight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,20 @@ export function freefightFactory(
);
const locationValues = monsterValues(type === "yellow ray", options);

const bestZones = new Set<Location>([
maxBy(validLocations, (l: Location) => locationValues.get(l) ?? 0),
]);
const bestZones = new Set<Location>(
validLocations.length > 0
? [maxBy(validLocations, (l: Location) => locationValues.get(l) ?? 0)]
: [],
);
for (const unlockableZone of UnlockableZones) {
const extraLocations = Location.all().filter(
(l) => l.zone === unlockableZone.zone && !locationSkiplist.includes(l),
);
bestZones.add(
maxBy(extraLocations, (l: Location) => locationValues.get(l) ?? 0),
);
if (extraLocations.length > 0) {
bestZones.add(
maxBy(extraLocations, (l: Location) => locationValues.get(l) ?? 0),
);
}
}
if (bestZones.size > 0) {
return [...bestZones].map(
Expand Down

0 comments on commit 4231f36

Please sign in to comment.