How Baseball Sim Engine Simulates Every Pitch

Baseball Sim Engine doesn’t simply select a strikeout, walk, or home run for each plate appearance. It simulates individual pitches, using real MLB data to establish the statistical environment and player ratings to influence what happens.

The goal is to reproduce the statistical characteristics of baseball while allowing each pitch and play to develop independently.

MLB-Derived Statistical Distributions

The foundation of the simulation is statistical data collected from MLB games.

Rather than assigning every fastball the same velocity or generating exit velocities from an arbitrary range, the engine uses distributions derived from actual MLB measurements.

These include averages, standard deviations, and other statistical relationships that describe how pitches and batted balls behave.

Measurement How the engine uses it
Pitch velocity Determines how fast pitches are thrown using MLB data for the selected pitch type
Pitch movement Determines horizontal and vertical break using pitch-type distributions
Exit velocity Determines how hard the ball is hit using MLB contact data
Launch angle Determines launch angles based on batted-ball type and outcome
Batted-ball distance Determines distance using MLB trajectory data
Spray direction Uses MLB pull, center, and opposite-field distributions

These distributions provide the baseline, while individual player ratings and the circumstances of the matchup influence the results.

For example, a pitcher with an above-average power rating tends to throw harder than the MLB baseline. A hitter’s contact rating and the quality of the pitch can also influence how hard the ball is hit and how far it travels.

The engine additionally models the statistical relationship between exit velocity and launch angle rather than treating them as entirely independent measurements.

Generating Each Pitch

Every pitch begins with the pitcher’s repertoire and the current matchup.

The engine determines the pitch’s velocity, horizontal and vertical movement, and intended and actual location. These characteristics are influenced by the pitcher’s ratings, handedness-specific abilities, and fatigue.

Pitch quality combines three components:

Component Weight
Velocity 33.3%
Movement 33.4%
Control 33.3%

The resulting quality affects the batter’s chances of swinging and making contact.

The engine also uses MLB-derived, count-specific probabilities to model how batters approach different situations. Swing decisions, contact rates, and fair-or-foul outcomes depend on the current count, pitch location, pitch quality, and the batter-pitcher matchup.

A plate appearance continues until the accumulated pitches produce a walk, strikeout, hit by pitch, or ball in play.

From Contact to a Baseball Play

When a ball is put in play, the engine first determines an outcome using the matchup and game environment.

It then determines the physical characteristics of the contact using MLB-derived distributions for the relevant batted-ball type and outcome.

For example, ground balls, line drives, fly balls, and popups have different statistical characteristics. The simulation uses those differences when determining exit velocity, launch angle, distance, and spray direction.

The resulting location helps determine which defensive player is involved. Individual fielding ratings, team defense, and contact quality can influence whether a ball becomes a hit or an out.

Finally, the baserunning system determines runner advancement, throws, additional outs, and runs scored.

Reproducing the MLB Environment

The underlying statistical environment also accounts for MLB offensive averages and stadium-specific park factors.

Park factors adjust the probabilities of singles, doubles, triples, home runs, walks, and strikeouts. This allows the same matchup to produce different statistical expectations in different stadiums.

Player ratings are evaluated relative to the league environment, so the simulation combines individual abilities with the broader statistical conditions of MLB.

Building a Complete Game

The process repeats through every pitch, plate appearance, inning, and substitution.

Because outcomes are determined through the simulation, the resulting box score reflects the actual sequence of simulated events rather than a collection of independently generated player statistics.

The simulation is statistical rather than a complete physical model of baseball, but it uses MLB measurements to give individual pitches and batted balls realistic characteristics.

For readers interested in the implementation, the pitch-generation, contact, fielding, and stadium calculations are available in the Baseball Sim Engine source code.