DEV Community

Cover image for Building a Multi-Agent AI Cricket Simulator in Vanilla JS
Abhisar Choubey
Abhisar Choubey

Posted on

Building a Multi-Agent AI Cricket Simulator in Vanilla JS

"How I built a high-performance Sports HUD simulating cricket strategy using Google Gemini at GDG Cloud Pune Hackathon with mentors @pratik_kale & @antrixsh_gupta "

tags: "javascript, ai, webdev, gemini"

Captains HUD: AI-Powered Cricket Strategy Simulator

Demo Video Link - https://youtu.be/VudXVtMESMY

Overview

Captains HUD (formerly "Captain Cool") is an interactive, AI-driven web application that simulates high-pressure cricket match scenarios. Users can input a specific match situation (e.g., "19th over, 24 runs to win, heavy dew"), and the application uses Google's Gemini AI to generate strategic decisions, simulate a multi-agent debate, and deliver dynamic live commentary.

Problem Statement

The goal was to build an application that could demonstrate multi-agent AI interactions in a fun, relatable context. Cricket strategy, with its diverse captaincy styles and high-pressure scenarios, provided the perfect backdrop. The application needed to:

  • Emulate the distinct personalities of legendary Indian cricket captains: MS Dhoni (calm/methodical), Virat Kohli (aggressive/passionate), Rohit Sharma (tactical/flexible), and Gautam Gambhir (intense/match-up driven).
  • Use a multi-agent architecture (Strategist, Devil's Advocate, Commentator, and Stats Analyst) to debate the scenario.
  • Present the data in a minimalist, broadcast-style "Sports HUD"…

Have you ever wondered how different cricket captains would handle the exact same high-pressure situation? Would MS Dhoni's ice-cool logic prevail, or would Virat Kohli's sheer aggression win the day?


I decided to find out by building Captains HUD, a multi-agent AI simulator powered by Google Gemini! 🏏🤖

The Concept

The idea was to create a "Sports Broadcast HUD" where different AI agents debate cricket strategy in real-time. I wanted an architecture that included:

  • The Stats Analyst: Evaluates pitch conditions and calculates a "Pressure Index".
  • The Strategist: Takes on the persona of a famous captain (Dhoni, Kohli, Rohit, or Gambhir) and makes a tactical call.
  • The Devil's Advocate: A critical agent that finds the fatal flaw in the Strategist's plan.
  • The Commentary Desk: Dynamic play-by-play commentary from legends like Harsha Bhogle and Ravi Shastri.

The Tech Stack

To keep things lightning-fast and visually striking, I avoided heavy frameworks and stuck to:

  • Vanilla HTML/CSS/JS: For a pure, responsive broadcast HUD.
  • Google GenAI SDK: To interact with the Gemini models.
  • Canvas Confetti: For some explosive visual feedback! 🎉

The "Mega-Prompt" Optimization

Initially, I had each agent calling the Gemini API sequentially. This created latency and quickly hit Free Tier rate limits.

The Solution: I refactored the backend into a single "Mega-Prompt" using strictly structured JSON schema output. I asked the AI to simulate the entire debate in one go, returning a JSON object containing the internal monologue, the decision, the challenge, the rebuttal, and the final commentary.

On the frontend, I simply staggered the rendering of this JSON payload using setTimeout delays. The result? A single API call that feels like a live, real-time debate to the user!

Key Takeaways

Building this project taught me that you don't always need complex orchestration frameworks for multi-agent systems. Sometimes, a well-crafted prompt with strict JSON schemas and clever frontend staggering can create a highly immersive AI experience.

If you're building an AI app, focus on the user's perception of the AI thinking! Simple CSS animations and delayed rendering can turn static text generation into a thrilling live event.

Have you built any fun multi-agent systems? Let me know in the comments!

Top comments (0)