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
31 changes: 26 additions & 5 deletions src/worker/core/GameSim.basketball/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ class GameSim {

numPlayersOnCourt: number;
baseInjuryRate: number;
isOneTwos: boolean;

/**
* Initialize the two teams that are playing this game.
Expand All @@ -254,6 +255,7 @@ class GameSim {
homeCourtFactor = 1,
allStarGame = false,
baseInjuryRate,
isOneTwos = false,
}: {
gid: number;
day?: number;
Expand All @@ -262,6 +264,7 @@ class GameSim {
homeCourtFactor?: number;
allStarGame?: boolean;
baseInjuryRate: number;
isOneTwos: boolean;
}) {
if (doPlayByPlay) {
this.playByPlay = [];
Expand Down Expand Up @@ -309,6 +312,7 @@ class GameSim {
this.elamActive = false;
this.elamDone = false;
this.elamTarget = 0;
this.isOneTwos = isOneTwos;

this.fatigueFactor = 0.055;

Expand Down Expand Up @@ -1350,7 +1354,7 @@ class GameSim {
}

if (inBonus) {
return this.doFt(shooter, 2); // fg, orb, or drb
return this.doFt(shooter, this.determineFtAmount()); // fg, orb, or drb
}

return "nonShootingFoul";
Expand All @@ -1360,6 +1364,21 @@ class GameSim {
return this.doShot(shooter, possessionLength); // fg, orb, or drb
}

/*
* Determines the amount of FT a team gets.
*/
determineFtAmount(isThreePointer: boolean = false): number {
// default FT amount
var ft = 2;
if (this.isOneTwos) {
ft -= 1;
}
if (isThreePointer) {
ft += 1;
}
return ft;
}

/**
* Probability of the current possession ending in a turnover.
*
Expand Down Expand Up @@ -1606,12 +1625,11 @@ class GameSim {
const threePointer = type === "threePointer" && g.get("threePointers");

this.doPf(this.d, threePointer ? "pfTP" : "pfFG", shooter);

if (threePointer) {
return this.doFt(shooter, 3); // fg, orb, or drb
return this.doFt(shooter, this.determineFtAmount(true)); // fg, orb, or drb
}

return this.doFt(shooter, 2); // fg, orb, or drb
return this.doFt(shooter, this.determineFtAmount()); // fg, orb, or drb
}

// Miss
Expand Down Expand Up @@ -1716,7 +1734,10 @@ class GameSim {
const p = this.playersOnCourt[this.o][shooter];
this.recordStat(this.o, p, "fga");
this.recordStat(this.o, p, "fg");
this.recordStat(this.o, p, "pts", 2); // 2 points for 2's
this.recordStat(this.o, p, "pts");
if (!this.isOneTwos) {
this.recordStat(this.o, p, "pts");
}

let fouler;
if (andOne) {
Expand Down