Skip to content
Open
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
59 changes: 22 additions & 37 deletions src/worker/core/GameSim.basketball/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,21 +689,23 @@ class GameSim {
*/
fatigue(energy: number, skip?: boolean): number {
energy += 0.016;

if (energy > 1) {
energy = 1;
}
if (skip) {
return energy;
}

// Late in games, or in OT, fatigue matters less
if (this.isLateGame()) {
const factor = 6 - this.t;
return (energy + factor) / (1 + factor);
let res = energy;
if (res > 1) {
res = 1;
}
if (!skip) {
// Late in games, or in OT, fatigue matters less
if (this.isLateGame()) {
const factor = 6 - this.t;
res = (res + factor) / (1 + factor);
}
}
// *0.5 + 0.5 is just turning tanh into sigmoid
// 50 is the steepness of curve
// 0.85 is the average (e.g. when output equals 0.5)
res = Math.tanh((res - 0.85) * 50) * 0.5 + 0.5;

return energy;
return res;
}

/**
Expand Down Expand Up @@ -754,15 +756,17 @@ class GameSim {
) {
ovrs[p] = -Infinity;
} else {
// scale energy based on playing time, except in all-star game.
const energy = !this.allStarGame
? this.team[t].player[p].stat.energy *
this.team[t].player[p].ptModifier
: this.team[t].player[p].stat.energy;

ovrs[p] =
this.team[t].player[p].valueNoPot *
this.fatigue(this.team[t].player[p].stat.energy) *
this.fatigue(energy) *
(!lateGame ? random.uniform(0.9, 1.1) : 1);

if (!this.allStarGame) {
ovrs[p] *= this.team[t].player[p].ptModifier;
}

// Also scale based on margin late in games, so stars play less in blowouts (this doesn't really work that well, but better than nothing)
if (blowout) {
ovrs[p] *= (p + 1) / 10;
Expand Down Expand Up @@ -854,25 +858,6 @@ class GameSim {
}
}

const cutoff =
this.numPlayersOnCourt >= 5
? 2
: this.numPlayersOnCourt >= 3
? 1
: 0;
if (
(numG < cutoff && numPG === 0) ||
(numF < cutoff && numC === 0)
) {
if (
this.fatigue(this.team[t].player[p].stat.energy) > 0.728 &&
!onCourtIsIneligible
) {
// Exception for ridiculously tired players, so really unbalanced teams won't play starters whole game
continue;
}
}

substitutions = true;

// Substitute player
Expand Down