Files
softball/game/atBatSimulator.ts
George Powell 9b779598e9 initial commit
2026-03-26 12:11:43 -04:00

41 lines
999 B
TypeScript

import type { ThrownPitch } from "../types/ThrownPitch";
import type { Player } from "../types/Player";
import type { BattedBall } from "../types/BattedBall";
import type { GameState } from "../types/GameState";
import pitchGenerator from "../systems/pitchGenerator";
export default function atBatSimulator(batter: Player, catcher: Player, pitcher: Player, game: GameState): GameState {
if (game.outs < 3) {
// do stuff
const pitch: ThrownPitch = pitchGenerator(pitcher);
// a pitch can either be:
// - batted
// - caught for a ball/strike
// - thrown wild
} else {
if (game.top) {
game.top = false;
} else {
game.top = true;
game.inning++ // games will keep going on forever
}
}
return game;
}
function swingSimulator(batter: Player, pitch: ThrownPitch): BattedBall {
// see the ball!
// decide if you're gonna swing!
// aim true! get that timing right!
// return a battedball
return {
exitVelo: 0,
launchAngle: 0,
attackAngle: 0,
spinRate: 0
};
}