Skip to content

Finalize marginal MPA before returning stash items #1832

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

Merged
merged 1 commit into from
Mar 28, 2024
Merged
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
33 changes: 24 additions & 9 deletions packages/garbo/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import { failedWishes } from "./potions";
import { garboValue } from "./garboValue";
import { estimatedGarboTurns } from "./turns";

type SessionKey = "full" | "barf" | "meat-start" | "meat-end" | "item";
type SessionKey =
| "full"
| "barf"
| "meat-start"
| "meat-end"
| "item-start"
| "item-end";
const sessions: Map<SessionKey, Session> = new Map();
/**
* Start a new session, deleting any old session
Expand All @@ -32,29 +38,35 @@ export function trackMarginalTurnExtraValue(additionalValue: number) {
extraValue += additionalValue;
}

export function trackMarginalMpa() {
export function trackMarginalMpa(remainingTurns?: number) {
const barf = sessions.get("barf");
const current = Session.current();
if (!barf) {
sessions.set("barf", Session.current());
} else {
const turns = barf.diff(current).totalTurns;
remainingTurns ??= estimatedGarboTurns();
// track items if we have run at least 100 turns in barf mountain or we have less than 200 turns left in barf mountain
const item = sessions.get("item");
const item = sessions.get("item-start");
if (!item && (turns > 100 || estimatedGarboTurns() <= 200)) {
sessions.set("item", current);
sessions.set("item-start", current);
}
// start tracking meat if there are less than 75 turns left in barf mountain
const meatStart = sessions.get("meat-start");
if (!meatStart && estimatedGarboTurns() <= 75) {
if (!meatStart && remainingTurns <= 75) {
sessions.set("meat-start", current);
}

// stop tracking meat if there are less than 25 turns left in barf moutain
const meatEnd = sessions.get("meat-end");
if (!meatEnd && estimatedGarboTurns() <= 25) {
if (!meatEnd && remainingTurns <= 25) {
sessions.set("meat-end", current);
}

const itemEnd = sessions.get("item-end");
if (!itemEnd && remainingTurns <= 0) {
sessions.set("item-end", current);
}
}
}

Expand All @@ -64,7 +76,8 @@ function printMarginalSession() {
const barf = sessions.get("barf");
const meatStart = sessions.get("meat-start");
const meatEnd = sessions.get("meat-end");
const item = sessions.get("item");
const itemStart = sessions.get("item-start");
const itemEnd = sessions.get("item-end");

// we can only print out marginal items if we've started tracking for marginal value
if (barf && meatStart && meatEnd) {
Expand All @@ -85,9 +98,9 @@ function printMarginalSession() {
isOutlier,
});

if (item) {
if (itemStart && itemEnd) {
// MPA printout including maringal items
const itemMpa = Session.computeMPA(item, Session.current(), {
const itemMpa = Session.computeMPA(itemStart, itemEnd, {
value: garboValue,
isOutlier,
excludeValue: { item: extraValue },
Expand Down Expand Up @@ -163,6 +176,8 @@ function resetGarboDaily() {
}

export function endSession(printLog = true): void {
// force marginal mpa to always have a 0 turns remaining calculation
trackMarginalMpa(0);
resetGarboDaily();
const message = (head: string, turns: number, meat: number, items: number) =>
print(
Expand Down