← Back to Baseball Game

🏏 Baseball Simulation Documentation

This comprehensive guide explains the Marshall's Hub Baseball Simulation system, including game mechanics, data storage architecture, and statistical reporting capabilities.

🎮 Overview

The Baseball Simulation is a comprehensive web-based baseball game that simulates realistic gameplay with detailed statistics tracking. The system includes:

🏗️ System Architecture

Core Components

baseball-simulation/ ├── baseball-game.html # Main game interface ├── baseball-game-logic.html # Game logic and rules engine ├── baseball-rules.html # Official rules documentation ├── baseball-save-game.php # Game saving API ├── baseball-stats.php # Statistics dashboard ├── baseball-db-config.php # Database configuration └── baseball_games.json # Game data storage

Data Flow

The simulation follows a clear data flow:

  1. Game Initialization: Player starts a new game through baseball-game.html
  2. Gameplay: Logic engine (baseball-game-logic.html) processes each play
  3. Data Persistence: Game state saved via baseball-save-game.php
  4. Analysis: Statistics generated and displayed in baseball-stats.php

💾 JSON Storage System

Storage Architecture

The system uses a file-based JSON storage approach for simplicity and portability:

Primary Storage: baseball_games.json - Contains all game data in a structured JSON format

JSON Structure

The main storage file follows this structure:

{ "games": [ { "game_id": 1, "game_date": "2025-12-07 14:30:00", "home_team": "Marshall's Eagles", "away_team": "Opponent", "home_score": 7, "away_score": 4, "innings": 9, "status": "completed", "players": [...], "plays": [...], "statistics": {...} } ] }

Data Persistence Methods

The system provides several data operations:

Operation PHP Function Description
Initialize initializeDatabase() Creates the JSON file structure if it doesn't exist
Save Game saveGameData() Appends a completed game to the JSON file
Retrieve Games getAllGames() Loads all games from the JSON file for analysis

Storage Advantages

📊 Statistical Reporting

Report Types

The system generates comprehensive statistics across multiple dimensions:

Game-Level Statistics

Player Statistics

Team Performance

Reporting Interface

The statistics dashboard (baseball-stats.php) provides:

Data Analysis Pipeline

// Example: Calculating batting average function calculateBattingAverage($player) { $hits = $player['hits'] ?? 0; $at_bats = $player['at_bats'] ?? 0; if ($at_bats == 0) return 0.000; return round($hits / $at_bats, 3); }

🎯 Game Logic Engine

Core Mechanics

The game logic engine handles all baseball rules and simulations:

Pitching System

Hitting Mechanics

Game Flow

  1. Game initialization with team and player setup
  2. Inning-by-inning progression
  3. Real-time play-by-play generation
  4. Automatic game state management
  5. Win/loss determination and final statistics

🔧 API Endpoints

Game Management

Endpoint Method Description
baseball-save-game.php?action=init GET Initialize the JSON database
baseball-save-game.php?action=save_game POST Save a completed game
baseball-save-game.php?action=get_stats GET Retrieve statistical data

Data Formats

All API responses follow a consistent JSON format:

{ "success": true, "data": {...}, "message": "Operation completed" }

🚀 Future Enhancements

Planned Features

Scalability Considerations

For high-volume usage, consider migrating to:

📝 Conclusion

The Baseball Simulation represents a comprehensive approach to web-based sports gaming, combining realistic gameplay mechanics with robust data management and analytical capabilities. The JSON-based storage system provides flexibility and ease of use, while the modular architecture allows for continuous improvement and expansion.

For technical support or feature requests, please contact MARSHALL EVETTS.

\\\\mars-server\\Xdrive\\Programs\\Apache\\htdocs\\baseball-simulation-documentation.html