initial commit
This commit is contained in:
40
game/atBatSimulator.ts
Normal file
40
game/atBatSimulator.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
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
|
||||
};
|
||||
}
|
||||
30
game/gameRuntime.ts
Normal file
30
game/gameRuntime.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
import type { Player } from "../types/Player";
|
||||
import type { GameState } from "../types/GameState";
|
||||
import type { ThrownPitch } from "../types/ThrownPitch";
|
||||
|
||||
import pitchGenerator from "../systems/pitchGenerator";
|
||||
import type { Team } from "../types/Team";
|
||||
|
||||
function startGame(homeTeam: Team, awayTeam: Team) {
|
||||
// simulate
|
||||
}
|
||||
|
||||
function advanceOrEndGame(game: GameState): GameState {
|
||||
// home team always bats last
|
||||
// if it's the top of the 9th and the away team is behind, the game is over
|
||||
if (game.inning == 9 || game.top == true && game.score.home > game.score.away) console.log("game should be over now.");
|
||||
|
||||
// next inning
|
||||
if (game.top) {
|
||||
return { ...game, top: false };
|
||||
} else {
|
||||
return {
|
||||
...game, inning: game.inning + 1, top: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function endGame(game: GameState) {
|
||||
console.log("GAME SHOULD END NOW SO FIGURE OUT WHAT TO DO!")
|
||||
}
|
||||
15
game/inningSimulator.ts
Normal file
15
game/inningSimulator.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import type { GameState } from "../types/GameState";
|
||||
import type { Team } from "../types/Team";
|
||||
import type { Player } from "../types/Player";
|
||||
import atBatSimulator from "./atBatSimulator";
|
||||
|
||||
export default function inningSimulator(battingTeam: Team, fieldingTeam: Team, game: GameState): GameState {
|
||||
while (game.outs < 3) {
|
||||
const batter: Player = battingTeam.battingLineup[battingTeam.batterIndex] as Player;
|
||||
const catcher: Player = fieldingTeam.fieldingLineup.c;
|
||||
const pitcher: Player = fieldingTeam.fieldingLineup.pitcher;
|
||||
|
||||
game = atBatSimulator(batter, catcher, pitcher, game);
|
||||
}
|
||||
return game;
|
||||
}
|
||||
Reference in New Issue
Block a user