Skip to content

Commit

Permalink
Support delayed support choices (#1840)
Browse files Browse the repository at this point in the history
* Delay unsupportedchoices in garbo-lib and add Ice Hotel choice

* Delay quartet choice too

* Bump for breaking changes to garbo-lib

* Set unsupportedChoices to private and use getter

* Reconsider getChoices change a bit

* Avoid calculating location twice when getting wanderer choices

* Restructure to make garbo-lib more useful in niche cases

* Do not spend turns for profit when wandering for spikolodon spike charges in yachtzee mode

* Better calculation for value of a turn we're considering using on an NC

* move adventure logic into unsupportedChoices

---------

Co-authored-by: horrible little slime <[email protected]>
  • Loading branch information
gausie and horrible-little-slime authored Apr 23, 2024
1 parent cd674e2 commit 1ee3573
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 85 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.6",
"version": "1.0.0",
"license": "MIT",
"repository": "https://github.com/loathers/garbage-collector.git",
"description": "A library for sequencing turns resource-optimally",
Expand Down
186 changes: 117 additions & 69 deletions packages/garbo-lib/src/wanderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ import {
print,
totalTurnsPlayed,
} from "kolmafia";
import { $familiar, $items, $location, get, maxBy } from "libram";
import {
$familiar,
$item,
$items,
$location,
Delayed,
get,
getActiveEffects,
maxBy,
sum,
undelay,
} from "libram";
import { guzzlrFactory } from "./guzzlr";
import {
canAdventureOrUnlock,
Expand Down Expand Up @@ -135,74 +146,90 @@ const defaultWanderOptions = {
};

export class WandererManager {
quartetChoice = get("lastQuartetRequest") || 4;
unsupportedChoices = new Map<Location, { [choice: number]: number | string }>(
private unsupportedChoices = new Map<
Location,
Delayed<
{ [choice: number]: number | string },
[options: WandererFactoryOptions, valueOfTurn: number]
>
>([
[$location`The Spooky Forest`, { 502: 2, 505: 2 }],
[$location`Guano Junction`, { 1427: 1 }],
[$location`The Hidden Apartment Building`, { 780: 6, 1578: 6 }],
[$location`The Black Forest`, { 923: 1, 924: 1 }],
[$location`LavaCo™ Lamp Factory`, { 1091: 9 }],
[$location`The Haunted Laboratory`, { 884: 6 }],
[$location`The Haunted Nursery`, { 885: 6 }],
[$location`The Haunted Storage Room`, { 886: 6 }],
[
[$location`The Spooky Forest`, { 502: 2, 505: 2 }],
[$location`Guano Junction`, { 1427: 1 }],
[$location`The Hidden Apartment Building`, { 780: 6, 1578: 6 }],
[$location`The Black Forest`, { 923: 1, 924: 1 }],
[$location`LavaCo™ Lamp Factory`, { 1091: 9 }],
[$location`The Haunted Laboratory`, { 884: 6 }],
[$location`The Haunted Nursery`, { 885: 6 }],
[$location`The Haunted Storage Room`, { 886: 6 }],
[$location`The Haunted Ballroom`, { 90: 3, 106: this.quartetChoice }], // Skip, and Choose currently playing song, or skip
[$location`The Haunted Library`, { 163: 4, 888: 5, 889: 5 }],
[$location`The Haunted Gallery`, { 89: 6, 91: 2 }],
[$location`The Hidden Park`, { 789: 6 }],
[
$location`A Mob of Zeppelin Protesters`,
{ 1432: 1, 856: 2, 857: 3, 858: 2 },
],
[$location`A-Boo Peak`, { 1430: 2 }],
[$location`Sloppy Seconds Diner`, { 919: 6 }],
[$location`VYKEA`, { 1115: 6 }],
[
$location`The Castle in the Clouds in the Sky (Basement)`,
{
669: 1,
670: 4,
671: 4,
},
],
[
$location`The Haunted Bedroom`,
{
876: 1, // old leather wallet, 500 meat
877: 1, // old coin purse, 500 meat
878: 1, // 400-600 meat
879: 2, // grouchy spirit
880: 2, // a dumb 75 meat club
},
],
[$location`The Copperhead Club`, { 855: 4 }],
[$location`The Haunted Bathroom`, { 882: 2 }], // skip; it's the towel adventure but we don't want towels
[
$location`The Castle in the Clouds in the Sky (Top Floor)`,
{
1431: 1,
675: 4, // Go to Steampunk choice
676: 4, // Go to Punk Rock choice
677: 1, // Fight Steam Punk Giant
678: 3, // Go to Steampunk choice
},
],
[
$location`The Castle in the Clouds in the Sky (Ground Floor)`,
{
672: 3, // Skip
673: 3, // Skip
674: 3, // Skip
1026: 3, // Skip
},
],
[$location`The Hidden Office Building`, { 786: 6 }],
[$location`Cobb's Knob Barracks`, { 522: 2 }], // skip
[$location`The Penultimate Fantasy Airship`, { 178: 2, 182: 1 }], // Skip, and Fight random enemy
[$location`The Haiku Dungeon`, { 297: 3 }], // skip
[$location`Frat House`, { 1425: 4 }], // fight eXtreme Sports Orcs
$location`The Haunted Ballroom`,
// Skip, and Choose currently playing song, or skip
() => ({ 90: 3, 106: get("lastQuartetRequest") || 4 }),
],
);
[$location`The Haunted Library`, { 163: 4, 888: 5, 889: 5 }],
[$location`The Haunted Gallery`, { 89: 6, 91: 2 }],
[$location`The Hidden Park`, { 789: 6 }],
[
$location`A Mob of Zeppelin Protesters`,
{ 1432: 1, 856: 2, 857: 3, 858: 2 },
],
[$location`A-Boo Peak`, { 1430: 2 }],
[$location`Sloppy Seconds Diner`, { 919: 6 }],
[$location`VYKEA`, { 1115: 6 }],
[
$location`The Ice Hotel`,
(options, valueOfTurn) => {
const valueOfCertificates = get("_iceHotelRoomsRaided")
? 0
: options.itemValue($item`Wal-Mart gift certificate`) * 3;
return { 1116: valueOfCertificates > valueOfTurn ? 5 : 6 };
},
],
[
$location`The Castle in the Clouds in the Sky (Basement)`,
{
669: 1,
670: 4,
671: 4,
},
],
[
$location`The Haunted Bedroom`,
{
876: 1, // old leather wallet, 500 meat
877: 1, // old coin purse, 500 meat
878: 1, // 400-600 meat
879: 2, // grouchy spirit
880: 2, // a dumb 75 meat club
},
],
[$location`The Copperhead Club`, { 855: 4 }],
[$location`The Haunted Bathroom`, { 882: 2 }], // skip; it's the towel adventure but we don't want towels
[
$location`The Castle in the Clouds in the Sky (Top Floor)`,
{
1431: 1,
675: 4, // Go to Steampunk choice
676: 4, // Go to Punk Rock choice
677: 1, // Fight Steam Punk Giant
678: 3, // Go to Steampunk choice
},
],
[
$location`The Castle in the Clouds in the Sky (Ground Floor)`,
{
672: 3, // Skip
673: 3, // Skip
674: 3, // Skip
1026: 3, // Skip
},
],
[$location`The Hidden Office Building`, { 786: 6 }],
[$location`Cobb's Knob Barracks`, { 522: 2 }], // skip
[$location`The Penultimate Fantasy Airship`, { 178: 2, 182: 1 }], // Skip, and Fight random enemy
[$location`The Haiku Dungeon`, { 297: 3 }], // skip
[$location`Frat House`, { 1425: 4 }], // fight eXtreme Sports Orcs
]);
equipment = new Map<Location, Item[]>([
...Location.all()
.filter((l) => l.zone === "The 8-Bit Realm")
Expand Down Expand Up @@ -247,8 +274,29 @@ export class WandererManager {
: $location`Drunken Stupor`;
}

getChoices(wanderer: WanderDetails): { [choice: number]: string | number } {
return this.unsupportedChoices.get(this.getTarget(wanderer)) ?? {};
/**
* Get choice map for the upcoming wander
* @param target Description of the wander or location in which to wander
* @param takeTurnForProfit Should the choices include any that would make a profit from your valueOfAdventure
* @returns Map of choice numbers to decisions
*/
getChoices(
target: WanderDetails | Location,
takeTurnForProfit = this.options.takeTurnForProfit,
): {
[choice: number]: string | number;
} {
const location =
target instanceof Location ? target : this.getTarget(target);
const valueOfTurn = takeTurnForProfit
? (this.options.valueOfAdventure ?? 0) +
sum(getActiveEffects(), (e) => this.options.effectValue(e, 1))
: Infinity;
return undelay(
this.unsupportedChoices.get(location) ?? {},
this.options,
valueOfTurn,
);
}

clear(): void {
Expand Down
2 changes: 2 additions & 0 deletions packages/garbo-lib/src/wanderer/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export type WandererFactoryOptions = {
plentifulMonsters: Monster[];
prioritizeCappingGuzzlr: boolean;
digitzesRemaining?: (turns: number) => number;
valueOfAdventure?: number;
takeTurnForProfit?: boolean;
};

export type WandererFactory = (
Expand Down
5 changes: 3 additions & 2 deletions packages/garbo/src/embezzler/staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ export class EmbezzlerFightRunOptions implements RunOptions {
wanderer: this.configOptions.draggable,
allowEquipment: false,
};
propertyManager.setChoices(wanderer().getChoices(wanderOptions));
return wanderer().getTarget(wanderOptions);
const targetLocation = wanderer().getTarget(wanderOptions);
propertyManager.setChoices(wanderer().getChoices(targetLocation));
return targetLocation;
}
return suggestion ?? $location`Noob Cave`;
}
Expand Down
20 changes: 10 additions & 10 deletions packages/garbo/src/fights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1334,11 +1334,9 @@ function latteFight(
!Latte.ingredientsUnlocked().includes(ingredient) &&
canAdventure(Latte.locationOf(ingredient)),
(runSource: ActionSource) => {
const location = Latte.locationOf(ingredient);
propertyManager.setChoices(
wanderer().unsupportedChoices.get(location) ?? {},
);
garboAdventure(location, runSource.macro);
const targetLocation = Latte.locationOf(ingredient);
propertyManager.setChoices(wanderer().getChoices(targetLocation));
garboAdventure(targetLocation, runSource.macro);
},
{
spec: { equip: $items`latte lovers member's mug` },
Expand Down Expand Up @@ -1663,8 +1661,8 @@ const freeRunFightSources = [
get("_hipsterAdv") < 7 &&
(have($familiar`Mini-Hipster`) || have($familiar`Artistic Goth Kid`)),
(runSource: ActionSource) => {
propertyManager.setChoices(wanderer().getChoices("backup"));
const targetLocation = wanderer().getTarget("backup");
propertyManager.setChoices(wanderer().getChoices(targetLocation));
garboAdventure(
targetLocation,
Macro.if_(
Expand Down Expand Up @@ -2132,7 +2130,8 @@ export function doSausage(): void {
freeFightOutfit({ equip: $items`Kramco Sausage-o-Matic™` }).dress();
const currentSausages = get("_sausageFights");
do {
propertyManager.setChoices(wanderer().getChoices("wanderer"));
const targetLocation = wanderer().getTarget("wanderer");
propertyManager.setChoices(wanderer().getChoices(targetLocation));
const goblin = $monster`sausage goblin`;
freeFightOutfit(
{
Expand All @@ -2141,7 +2140,7 @@ export function doSausage(): void {
{ wanderOptions: "wanderer" },
).dress();
garboAdventureAuto(
wanderer().getTarget("wanderer"),
targetLocation,
Macro.if_(goblin, Macro.basicCombat())
.ifHolidayWanderer(Macro.basicCombat())
.abortWithMsg(`Expected ${goblin} but got something else.`),
Expand Down Expand Up @@ -2373,8 +2372,9 @@ function voidMonster(): void {
},
{ wanderOptions: "wanderer" },
).dress();
propertyManager.setChoices(wanderer().getChoices("wanderer"));
garboAdventure(wanderer().getTarget("wanderer"), Macro.basicCombat());
const targetLocation = wanderer().getTarget("wanderer");
propertyManager.setChoices(wanderer().getChoices(targetLocation));
garboAdventure(targetLocation, Macro.basicCombat());
postCombatActions();
}

Expand Down
2 changes: 2 additions & 0 deletions packages/garbo/src/garboWanderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export function wanderer(): WandererManager {
? $monsters`sausage goblin`
: []),
],
valueOfAdventure: get("valueOfAdventure"),
takeTurnForProfit: true,
});
}
return _wanderer;
Expand Down
6 changes: 3 additions & 3 deletions packages/garbo/src/yachtzee/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,19 @@ export function useSpikolodonSpikes(): void {
}).dress();
cliExecute("parka spikolodon");

const targetZone = canJelly
const targetLocation = canJelly
? $location`Pirates of the Garbage Barges`
: $location`Sloppy Seconds Diner`;
const macro = Macro.familiarActions()
.skill($skill`Launch spikolodon spikes`)
.step(run.macro);
const startingSpikes = get("_spikolodonSpikeUses");

const ncSkipper = wanderer().unsupportedChoices.get(targetZone);
const ncSkipper = wanderer().getChoices(targetLocation, false);
if (ncSkipper) propertyManager.setChoices(ncSkipper);

do {
garboAdventureAuto(targetZone, macro);
garboAdventureAuto(targetLocation, macro);
} while (get("_spikolodonSpikeUses") === startingSpikes);

postCombatActions();
Expand Down

0 comments on commit 1ee3573

Please sign in to comment.