From 4231f3655c1b6aad9fb5da3790401f24f008f077 Mon Sep 17 00:00:00 2001 From: Patrick Stalcup Date: Wed, 13 Dec 2023 17:16:26 -0500 Subject: [PATCH] Handle empty lists of valid locations (#1773) --- packages/garbo-lib/package.json | 2 +- packages/garbo-lib/src/wanderer/freefight.ts | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/garbo-lib/package.json b/packages/garbo-lib/package.json index 16f55d1bc..f13d0de95 100644 --- a/packages/garbo-lib/package.json +++ b/packages/garbo-lib/package.json @@ -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", diff --git a/packages/garbo-lib/src/wanderer/freefight.ts b/packages/garbo-lib/src/wanderer/freefight.ts index 0345b92c2..9da5a39e6 100644 --- a/packages/garbo-lib/src/wanderer/freefight.ts +++ b/packages/garbo-lib/src/wanderer/freefight.ts @@ -86,16 +86,20 @@ export function freefightFactory( ); const locationValues = monsterValues(type === "yellow ray", options); - const bestZones = new Set([ - maxBy(validLocations, (l: Location) => locationValues.get(l) ?? 0), - ]); + const bestZones = new Set( + 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(