Skip to content

Commit

Permalink
Schedule is more compact with series now, so pitchers should start ev…
Browse files Browse the repository at this point in the history
…ery 5 days, not every 6
  • Loading branch information
dumbmatter committed Oct 2, 2024
1 parent 44f9a81 commit f7a77b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
25 changes: 9 additions & 16 deletions src/worker/core/GameSim.baseball/getStartingPitcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,32 @@ export const getStartingPitcher = (
const playoffs = g.get("phase") === PHASE.PLAYOFFS;

// First pass - look for starting pitcher with no fatigue
let firstFound;
for (let i = 0; i < pitchers.length; i++) {
const p = pitchers[i];
if ((p.pFatigue === 0 || (playoffs && p.pFatigue < 30)) && !p.injured) {
// Add some randomness, to get lower starters some extra starts
if (playoffs || Math.random() < 0.8) {
return p;
}

firstFound = p;
const pFatigue = p.pFatigue ?? 0;
if ((pFatigue === 0 || (playoffs && pFatigue < 30)) && !p.injured) {
return p;
}

if (i === NUM_STARTING_PITCHERS - 1) {
break;
}
}

if (firstFound) {
// If randomness didn't turn up another candidate
return firstFound;
}

// Second pass - reliever with no fatigue
for (let i = CLOSER_INDEX + 1; i < pitchers.length; i++) {
const p = pitchers[i];
if (p.pFatigue === 0 && !p.injured) {
const pFatigue = p.pFatigue ?? 0;
if (pFatigue === 0 && !p.injured) {
return p;
}
}

// Third pass - look for slightly tired starting pitcher
for (let i = 0; i < pitchers.length; i++) {
const p = pitchers[i];
if (p.pFatigue <= 30 && !p.injured) {
const pFatigue = p.pFatigue ?? 0;
if (pFatigue <= 30 && !p.injured) {
return p;
}

Expand All @@ -61,7 +53,8 @@ export const getStartingPitcher = (
// Fourth pass - tired reliever
for (let i = CLOSER_INDEX + 1; i < pitchers.length; i++) {
const p = pitchers[i];
if (p.pFatigue <= 30 && !p.injured) {
const pFatigue = p.pFatigue ?? 0;
if (pFatigue <= 30 && !p.injured) {
return p;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/worker/core/game/play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const play = async (
p.pFatigue = helpers.bound(
p.pFatigue - P_FATIGUE_DAILY_REDUCTION,
0,
100,
80,
);
changed = true;
}
Expand Down

0 comments on commit f7a77b0

Please sign in to comment.