initial commit
This commit is contained in:
56
test/generateFixtures.ts
Normal file
56
test/generateFixtures.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import type { Player } from "../types/Player";
|
||||
import type { Team } from "../types/Team";
|
||||
|
||||
const firstNames = ["Alex", "Jordan", "Casey", "Riley", "Morgan", "Taylor", "Drew", "Jamie", "Sam", "Pat"];
|
||||
const lastNames = ["Smith", "Johnson", "Williams", "Brown", "Jones", "Garcia", "Miller", "Davis", "Wilson", "Moore"];
|
||||
const hometowns = ["Austin, TX", "Portland, OR", "Denver, CO", "Nashville, TN", "Raleigh, NC"];
|
||||
const genders = ["m", "f", "nb"] as const;
|
||||
|
||||
function rand(min: number, max: number): number {
|
||||
return Math.random() * (max - min) + min;
|
||||
}
|
||||
|
||||
function pick<T>(arr: readonly T[]): T {
|
||||
return arr[Math.floor(Math.random() * arr.length)] as T;
|
||||
}
|
||||
|
||||
export function randomPlayer(): Player {
|
||||
return {
|
||||
gender: pick(genders),
|
||||
firstname: pick(firstNames),
|
||||
lastname: pick(lastNames),
|
||||
hometown: pick(hometowns),
|
||||
skillset: {
|
||||
batting: rand(0.2, 1.0),
|
||||
pitching: {
|
||||
armStrength: rand(0.2, 1.0),
|
||||
gripStrength: rand(0.2, 1.0),
|
||||
fourSeam: rand(0, 1.5),
|
||||
twoSeam: rand(0, 1.2),
|
||||
changeup: rand(0, 1.2),
|
||||
curveball: rand(0, 1.0),
|
||||
slider: rand(0, 1.0),
|
||||
splitter: rand(0, 0.8),
|
||||
knuckleball: rand(0, 0.5),
|
||||
},
|
||||
running: rand(0.2, 1.0),
|
||||
fielding: rand(0.2, 1.0),
|
||||
gamesense: rand(0.2, 1.0),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function randomTeam(): Team {
|
||||
const battingLineup: Player[] = Array.from({ length: 9 }, randomPlayer);
|
||||
const [pitcher, c, firstBase, secondBase, thirdBase, ss, lf, cf, rf] = battingLineup as [
|
||||
Player, Player, Player, Player, Player, Player, Player, Player, Player
|
||||
];
|
||||
|
||||
return {
|
||||
battingLineup,
|
||||
fieldingLineup: { pitcher, c, firstBase, secondBase, thirdBase, ss, lf, cf, rf },
|
||||
bullpen: Array.from({ length: 3 }, randomPlayer),
|
||||
bench: Array.from({ length: 3 }, randomPlayer),
|
||||
batterIndex: 0,
|
||||
};
|
||||
}
|
||||
27
test/testAtBat.ts
Normal file
27
test/testAtBat.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { GameState } from "../types/GameState";
|
||||
import atBatSimulator from "../game/atBatSimulator";
|
||||
import { randomTeam } from "./generateFixtures";
|
||||
|
||||
const batting = randomTeam();
|
||||
const fielding = randomTeam();
|
||||
|
||||
const initialState: GameState = {
|
||||
inning: 1,
|
||||
top: true,
|
||||
outs: 0,
|
||||
count: { balls: 0, strikes: 0 },
|
||||
score: { home: 0, away: 0 },
|
||||
};
|
||||
|
||||
const batter = batting.battingLineup[batting.batterIndex]!;
|
||||
const pitcher = fielding.fieldingLineup.pitcher;
|
||||
const catcher = fielding.fieldingLineup.c;
|
||||
|
||||
console.log(`Batter: ${batter.firstname} ${batter.lastname} (batting: ${batter.skillset.batting.toFixed(2)})`);
|
||||
console.log(`Pitcher: ${pitcher.firstname} ${pitcher.lastname} (armStrength: ${pitcher.skillset.pitching.armStrength.toFixed(2)})`);
|
||||
console.log(`Catcher: ${catcher.firstname} ${catcher.lastname}`);
|
||||
console.log("---");
|
||||
|
||||
const result = atBatSimulator(batter, catcher, pitcher, initialState);
|
||||
|
||||
console.log("Result state:", result);
|
||||
14
test/testPitch.ts
Normal file
14
test/testPitch.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import pitchGenerator from "../systems/pitchGenerator";
|
||||
import { randomPlayer } from "./generateFixtures";
|
||||
|
||||
const pitcher = randomPlayer();
|
||||
|
||||
console.log(`Pitcher: ${pitcher.firstname} ${pitcher.lastname}`);
|
||||
console.log(` armStrength: ${pitcher.skillset.pitching.armStrength.toFixed(2)}`);
|
||||
console.log(` gripStrength: ${pitcher.skillset.pitching.gripStrength.toFixed(2)}`);
|
||||
console.log(` fourSeam: ${pitcher.skillset.pitching.fourSeam.toFixed(2)}`);
|
||||
console.log("---");
|
||||
|
||||
const pitch = pitchGenerator(pitcher);
|
||||
|
||||
console.log("ThrownPitch:", pitch);
|
||||
Reference in New Issue
Block a user