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

57 lines
1.7 KiB
TypeScript

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,
};
}