Baseball is a game of chess at 90mph. BaseHit's AI pitcher doesn't throw randomly — it watches your timing, learns your habits, and adjusts pitch selection with remarkable precision. No machine learning required.
What Makes Our AI Different
The BaseHit AI pitcher creates an intelligent opponent through elegant rule-based design. It watches your timing patterns in real-time and adapts pitch selection strategically—all without machine learning.
Timing Bias Detection
AI analyzes your last 5 swings to detect if you're consistently early, late, or balanced. Then it selects pitches that exploit those patterns.
Adaptive Speed Adjustment
Pitch velocities adjust based on your swing timing. Early swings get slower pitches, late swings get faster ones. It feels like the pitcher is reading you.
Smart Zone Targeting
Five pitch zones (center, inside, outside, high, low) with varying home run multipliers. Difficulty-based zone distribution means harder opponents pitch to tougher locations.
Pitch Variety Prevention
The AI never throws the same pitch 3 times consecutively. Strategic sequencing keeps you honest without requiring complex models.
The AI Systems Under the Hood
BaseHit's AI pitcher is powered by three interconnected systems that work together to create a cohesive, intelligent opponent:
Timing Bias Detector
Tracks your last 5 swing timings and classifies you as 'early', 'late', or 'balanced'. Automatically selects pitch distributions that exploit this bias.
Pitch Selection Engine
Rule-based decision-making that considers difficulty level, pitch variety prevention, and timing bias to choose the next pitch type and zone.
Adaptive Speed Calculator
Adjusts pitch velocity based on your swing timing patterns. Early swings trigger slower pitches; late swings get speed boosts. Perfect swings trigger penalty speeds.
Reactive Fielding
Simple reactive fielders (3 outfielders) that chase hits and play animated reactions. No shift AI or spray chart analysis—pure reactive animation.
Technical Deep Dive
For the technically curious, here's how the timing bias detection system creates genuine adaptive AI without complex machine learning:
Timing Bias Detection Algorithm
The core innovation: analyzing swing timing to detect and exploit patterns. The system tracks the last 5 swing events:
// Calculate swing timing relative to perfect window
const timingBias = analyzeLastFiveSwings([
{ swing_time: 245, perfect_window: [250, 318] }, // 5ms EARLY
{ swing_time: 260, perfect_window: [250, 318] }, // 10ms EARLY
{ swing_time: 255, perfect_window: [250, 318] }, // BALANCED
{ swing_time: 248, perfect_window: [250, 318] }, // 2ms EARLY
{ swing_time: 330, perfect_window: [250, 318] }, // 12ms LATE
]);
// Result: Player classified as 'early' bias
const classification = classifyBias(timingBias);
// Returns: 'early' | 'late' | 'balanced'
Pitch Selection Based on Timing Bias
Once bias is detected, the AI selects pitch distributions that exploit it:
function decidePitch(timingBias, difficulty) {
let pitchDistribution;
if (timingBias === 'early') {
// Throw more breaking balls (slower)
// 35% curveball, 20% changeup, 45% fastball
pitchDistribution = {
curveball: 0.35,
changeup: 0.20,
fastball: 0.45
};
}
else if (timingBias === 'late') {
// Throw more fastballs (faster)
// Exploit late timing with velocity
pitchDistribution = {
fastball: 0.60,
curveball: 0.20,
changeup: 0.20
};
}
else {
// Balanced: use difficulty-based distribution
pitchDistribution = getDifficultyPitchDistribution(difficulty);
}
// Prevent same pitch 3x consecutively
if (lastThreePitches.allSame()) {
return selectDifferentPitch(pitchDistribution);
}
return selectRandomFromDistribution(pitchDistribution);
}
Adaptive Speed Calculation
Pitch speed adjusts in real-time based on swing patterns. This creates the illusion of an opponent that reads you:
function getAdaptiveSpeed(basePitchSpeed, timingBias) {
let speedMultiplier = 1.0;
if (timingBias === 'early') {
// 20% slower for early swings
speedMultiplier = 0.80;
}
else if (timingBias === 'late') {
// 4-12% faster for late swings
speedMultiplier = 1.04 + Math.random() * 0.08;
}
// Penalty speed boost for recent perfect swings
if (recentPerfectSwings >= 2) {
// Boost 10% if pitcher "responds" to perfect contact
speedMultiplier *= 1.10;
}
const finalSpeed = basePitchSpeed * speedMultiplier;
// Clamp to valid range: 150-800 px/sec
return Math.max(150, Math.min(800, finalSpeed));
}
Five Pitch Zones & Home Run Multipliers
Pitch zones vary in difficulty and home run potential. Harder difficulties favor tougher zones:
Pitch Types
Four pitch types with different characteristics:
- Fastball: Straight, velocity-based. Most common in early counts.
- Curveball: Breaks with direction (left/right) and magnitude. Effective against early swings.
- Slider: Hybrid between fastball and curve. Mid-tier complexity.
- Changeup: Lower velocity. Sets up batter for slower approach, exploits timing.
Difficulty Tiers
Difficulty scales four key variables: pitch speed, perfect window size, curve percentage, and zone difficulty:
- Easy: 340 px/sec, 115ms perfect window, 0% curves, forgiving zones
- Medium: 500 px/sec, 68ms window, 20% curves, balanced zones
- Hard: 680 px/sec, 40ms window, 40% curves, tough outer zones
- Legend: 900 px/sec, 22ms window, 62% curves, nearly all difficult zones
Game Mechanics: Player as Batter Only
BaseHit is fundamentally about batting strategy. The player controls one action: swinging with two stances:
- Contact Stance: Wider timing window, fewer home runs. Better for consistent contact and learning pitch patterns.
- Power Stance: Narrow timing window, more home runs. High risk/reward for aggressive play.
5 at-bats per game (7 for boss levels). The 100-level campaign includes combo multipliers and power-ups that boost scoring without changing pitch selection.
Key Design Insight: This timing bias system is elegant game design that feels intelligent without requiring neural networks. By adapting pitch selection and speed based on observable swing timing, the AI creates the perception of machine learning while remaining fully rule-based and transparent to the player.
What About mlDataStore?
You'll notice BaseHit has an mlDataStore that logs swing events: timing, pitch type, and result. This is for analytics and future reference only. The AI never reads from this data. Pitch decisions are made purely from the current game's last 5 swings, not historical patterns across sessions.
This separation is intentional: it keeps the AI transparent and ensures every game is fair, without hidden training from your past mistakes.
Why Rule-Based > Machine Learning (for Baseball)
BaseHit deliberately avoids neural networks and complex ML models. Here's why this rule-based approach is superior for baseball game design:
- Transparency: Players can learn the pitcher's patterns. They see swings classified as 'early' and can adjust. The AI isn't a black box.
- Fairness: No hidden training on your mistakes. Every game starts fresh with the same rules. No algorithmic bias toward particular playstyles.
- Performance: Rule-based systems are instant and require zero computational overhead. Pitches are selected in microseconds.
- Design Clarity: Developers understand exactly how the AI behaves. Balancing is straightforward: tweak percentages, difficulty thresholds, speed multipliers.
- Depth Without Complexity: Simple rules create emergent complexity. Timing bias detection + adaptive speed + pitch variety prevention = surprisingly intelligent opponent.
Core Philosophy: Baseball is about reading the pitcher. BaseHit's AI is designed to be read—it has consistent, learnable patterns. That's good game design.
Future Enhancements
The rule-based foundation is solid and extensible. Future updates might include:
- Multi-Inning Pitch Memory: Instead of just last 5 swings, remember patterns across 3+ at-bats within a single game. Adds depth without ML.
- Stance-Based Adaptation: Different pitch distributions for contact vs. power stance. Harder to exploit if pitcher knows your stance.
- Combo Multiplier Penalties: When player builds a combo, pitcher shifts to tougher zones earlier, forcing risk/reward trades.
- Boss Pitcher Quirks: 100-level bosses with exaggerated timing biases and unique speed profiles. Each boss teaches a different discipline.
Experience AI Baseball
Ready to face an opponent that adapts to your strengths and exposes your weaknesses? Step into the batter's box today.
Back to ExaFabs