Skip to content

Commit

Permalink
Fix strike out throw outs not advancing the batting order if they end…
Browse files Browse the repository at this point in the history
… the inning (like if they happen with 1 out exactly)
  • Loading branch information
dumbmatter committed Dec 15, 2024
1 parent ebfd33f commit 5ac8031
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
4 changes: 2 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
runner stealing base should only very rarely be caught in double play

make player graphs remember selections https://old.reddit.com/r/BasketballGM/comments/1gplx7g/could_you_make_the_player_graphs_remember_what/
- other pages?

Expand Down Expand Up @@ -48,8 +50,6 @@ Don't allow play if versions in tabs don't match
- close worker?
- newPhasePreseason being called twice in two different tabs and somehow updating the database twice?

Strike out throw out DP does not advance batting order https://discord.com/channels/290013534023057409/290015591216054273/1010153106740351057

move from my iterate function to async iterators
- regex search: [\t ]iterate\(

Expand Down
6 changes: 6 additions & 0 deletions src/common/constants.baseball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,10 @@ const NUM_ACTIVE_BATTERS = 14;

const NUM_OUTS_PER_INNING = 3;

const NUM_STRIKES_PER_OUT = 3;

const NUM_BALLS_PER_WALK = 4;

export {
AWARD_NAMES,
DEFAULT_CONFS,
Expand All @@ -650,6 +654,8 @@ export {
NUM_ACTIVE_PITCHERS,
NUM_OUTS_PER_INNING,
NUM_STARTING_PITCHERS,
NUM_STRIKES_PER_OUT,
NUM_BALLS_PER_WALK,
PLAYER_GAME_STATS,
PLAYER_STATS_TABLES,
PLAYER_SUMMARY,
Expand Down
33 changes: 19 additions & 14 deletions src/worker/core/GameSim.baseball/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { g, helpers, random } from "../../util";
import {
NUM_BALLS_PER_WALK,
NUM_OUTS_PER_INNING,
NUM_STRIKES_PER_OUT,
POS_NUMBERS,
POS_NUMBERS_INVERSE,
} from "../../../common/constants.baseball";
Expand Down Expand Up @@ -330,7 +332,7 @@ class GameSim extends GameSimBase {
}

doFoul() {
if (this.strikes < 2) {
if (this.strikes < NUM_STRIKES_PER_OUT - 1) {
this.strikes += 1;
}

Expand Down Expand Up @@ -967,7 +969,7 @@ class GameSim extends GameSimBase {
for (let i = stealing.length - 1; i >= 0; i--) {
if (stealing[i]) {
// If this is a walk and the runner gets the base automatically, then no steal attempt
if (this.balls === 4 && this.isForceOut(i as any)) {
if (this.balls === NUM_BALLS_PER_WALK && this.isForceOut(i as any)) {
continue;
}

Expand Down Expand Up @@ -1006,8 +1008,11 @@ class GameSim extends GameSimBase {

this.logOut();

if (this.outs >= NUM_OUTS_PER_INNING) {
// Same batter will be up next inning
// If inning is over, same batter will be up next inning, unless he also struck out
if (
this.outs >= NUM_OUTS_PER_INNING &&
this.strikes < NUM_STRIKES_PER_OUT
) {
this.team[this.o].moveToPreviousBatter();
}
} else {
Expand Down Expand Up @@ -1131,12 +1136,12 @@ class GameSim extends GameSimBase {
};
let ballProb = BALL_PROB_BY_COUNT[this.strikes][this.balls];

if (this.strikes === 2 && this.balls === 0) {
if (this.balls === NUM_BALLS_PER_WALK - 1) {
ballProb -= 0.2 * pitcher.compositeRating.controlPitcher;
} else if (this.strikes === NUM_STRIKES_PER_OUT - 1 && this.balls === 0) {
ballProb += 0.2 * pitcher.compositeRating.controlPitcher;
} else if (this.strikes === 2 && this.balls === 1) {
} else if (this.strikes === NUM_STRIKES_PER_OUT - 1 && this.balls === 1) {
ballProb += 0.1 * pitcher.compositeRating.controlPitcher;
} else if (this.balls === 3) {
ballProb -= 0.2 * pitcher.compositeRating.controlPitcher;
} else {
ballProb -= 0.1 * pitcher.compositeRating.controlPitcher;
}
Expand Down Expand Up @@ -1168,7 +1173,7 @@ class GameSim extends GameSimBase {
let contactAdjusted = 0.25 + 0.5 * batter.compositeRating.contactHitter;

let swingProbAdjustment = 0;
if (this.strikes === 2) {
if (this.strikes === NUM_STRIKES_PER_OUT - 1) {
swingProbAdjustment += 0.2;
contactAdjusted += 0.08;
}
Expand Down Expand Up @@ -1619,7 +1624,7 @@ class GameSim extends GameSimBase {
this.doBalkWildPitchPassedBall(wildPitchPassedBall);

this.balls += 1;
if (this.balls >= 4) {
if (this.balls >= NUM_BALLS_PER_WALK) {
this.doWalk("normal");
doneBatter = true;
} else {
Expand Down Expand Up @@ -1647,8 +1652,8 @@ class GameSim extends GameSimBase {
const stealing = [false, false, false] as [boolean, boolean, boolean];
const fullCountTwoOuts =
this.outs === NUM_OUTS_PER_INNING - 1 &&
this.balls === 3 &&
this.strikes === 2;
this.balls === NUM_BALLS_PER_WALK - 1 &&
this.strikes === NUM_STRIKES_PER_OUT - 1;

let numStealing = 0;
let numStaying = 0;
Expand Down Expand Up @@ -1709,7 +1714,7 @@ class GameSim extends GameSimBase {

if (outcome === "ball") {
this.balls += 1;
if (this.balls >= 4) {
if (this.balls >= NUM_BALLS_PER_WALK) {
this.doWalk("normal");
doneBatter = true;
} else {
Expand All @@ -1729,7 +1734,7 @@ class GameSim extends GameSimBase {
}
} else if (outcome === "strike") {
this.strikes += 1;
if (this.strikes >= 3) {
if (this.strikes >= NUM_STRIKES_PER_OUT) {
this.doStrikeout(swinging);
doneBatter = true;
if (this.outs >= NUM_OUTS_PER_INNING) {
Expand Down

0 comments on commit 5ac8031

Please sign in to comment.