Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outline of pizza cube maximizer #2149

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions packages/garbo/src/resources/worksheds.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import {
autosellPrice,
descToItem,
Effect,
handlingChoice,
Item,
mallPrice,
runChoice,
toSlot,
visitUrl,
} from "kolmafia";
import {
$item,
$items,
$monsters,
$slot,
arrayEquals,
get,
maxBy,
Expand All @@ -21,6 +26,7 @@ import { candyFactoryValue } from "../lib";
import { garboAverageValue, garboValue } from "../garboValue";
import { estimatedGarboTurns } from "../turns";
import { copyTargetCount } from "../target";
import { Potion } from "../potions";

const GOOD_TRAIN_STATIONS = [
{ piece: TrainSet.Station.GAIN_MEAT, value: () => 900 },
Expand Down Expand Up @@ -157,3 +163,62 @@ export function grabMedicine(): void {
}
if (handlingChoice()) visitUrl("main.php");
}

// Function to calculate the value for each item
function calculateItemValue(item: Item, effect: Effect): number {
return (
new Potion($item`diabolic pizza`, {
effect: effect,
duration: Math.sqrt(autosellPrice(item)),
}).gross(copyTargetCount()) -
mallPrice(item) +
(toSlot(item) === $slot`familiar`
? mallPrice($item`box of Familiar Jacks`)
: 0) +
Comment on lines +175 to +177
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't get multiple jacks from having multiple familiar items unfortunately

item.name.length / 10
);
}

// Consolidated function to get the best item for a given letter
function bestPizzaItemForLetter(letter: string, effect: Effect): Item {
const items = $items.all().filter((i) => i.name.startsWith(letter));

const itemsWithValues = items.map((item) => ({
item,
value: calculateItemValue(item, effect),
}));

return maxBy(itemsWithValues, (entry) => entry.value).item;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return maxBy(itemsWithValues, (entry) => entry.value).item;
return maxBy(itemsWithValues, "value").item;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also fwiw if you aren't using the values outside of the maxby it makes more sense to not do the map at all and to instead just ```typescript
return maxBy(items, (it) => calculateItemValue(it, effect));

}

// Function to design the pizza based on the effect's name letters
function designPizza(effect: Effect): Item[] {
return effect.name
.substring(0, 4)
.split("")
.map((letter) => bestPizzaItemForLetter(letter, effect));
}

// Simulation to calculate pizza cost and benefit
export function simCreatePizza(effect: Effect): [number, number] {
const pizzaItems = designPizza(effect);

const benefit = pizzaItems.reduce(
(acc, it) => acc + calculateItemValue(it, effect),
0,
);
Comment on lines +206 to +209
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const benefit = pizzaItems.reduce(
(acc, it) => acc + calculateItemValue(it, effect),
0,
);
const benefit = sum(pizzaItems, (it) => calculateItemValue(it, effect));

const cost = pizzaItems.reduce((acc, it) => acc + mallPrice(it), 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const cost = pizzaItems.reduce((acc, it) => acc + mallPrice(it), 0);
const cost = sum(pizzaItems, mallPrice);


return [cost, benefit];
}

// Function to create the pizza by calling the appropriate URL
export function createPizza(effect: Effect) {
const pizzaItems = designPizza(effect);

visitUrl(
`campground.php?action=makepizza&pizza=${pizzaItems.map((item) => item.id).join(",")}`,
true,
true,
);
}
Loading