Skip to main content

Command line interface for battling with a local Pokemon Showdown simulator - includes Pokemon Showdown source code

Project description

CLI-Mon Showdown

A terminal-based Pokémon battle CLI that drives the official Pokémon Showdown simulator for accurate mechanics, quick testing, and lightweight play.

New in v0.1.6+: Pokemon Showdown source code is now included in the package! No need for separate installation.

Features

  • Self-contained: Pokemon Showdown simulator source code included in package
  • Accurate engine: uses the official Pokémon Showdown simulator
  • AI opponents: Gemini AI agent for strategic battle decisions
  • Teams: load Showdown import/export text files
  • CLI-first: fast feedback loop and readable battle feed
  • Random battles: generate teams via Showdown

Attribution

This package includes the Pokemon Showdown source code, which is licensed under the MIT License:

Project Structure

  • src/cli_mon_showdown/ - installable Python package (CLI, wrapper, Gemini agent)
  • cli.py - shim so cli-mon still works locally
  • pokemon-showdown/ - expected checkout of the Node simulator
  • teams/ - example team files in Showdown format
  • BATTLE_FIXES.md - notes on battle handling improvements

Requirements

  • Python 3.10+
  • Node.js 18+ (required for Pokemon Showdown)

Note: Starting with v0.1.6, Pokemon Showdown source code is bundled with the package, but Node.js is still required to run it.

Quick Start

Install from PyPI (recommended)

# First, ensure Node.js is installed
node --version  # Should show v18.0.0 or higher

# Install the CLI tool
pip install cli-mon-showdown
cli-mon --help

Pokemon Showdown is now included! The first time you run a battle, Pokemon Showdown will be automatically built if needed.

Node.js Installation

If you don't have Node.js installed:

Windows:

  • Download from nodejs.org (LTS version recommended)
  • Or use winget: winget install OpenJS.NodeJS

macOS:

  • Download from nodejs.org
  • Or use Homebrew: brew install node

Linux:

  • Ubuntu/Debian: sudo apt install nodejs npm
  • CentOS/RHEL: sudo yum install nodejs npm
  • Or download from nodejs.org

Run from a local clone

git clone https://github.com/papichoolo/cli-mon-showdown.git
cd cli-mon-showdown

python -m venv .venv
.venv\Scripts\activate

# Install the package in editable mode (includes Python dependencies)
pip install -e .

# Fetch the Showdown simulator
git clone https://github.com/smogon/pokemon-showdown.git
cd pokemon-showdown
npm ci
cd ..

# Run a battle with sample teams
cli-mon teams/p1.txt teams/p2.txt --format gen7ou

Gemini AI Agent Configuration

The CLI includes an optional Gemini AI agent that can play as Player 2, making strategic decisions based on battle state analysis. This provides a more challenging and realistic opponent compared to the default random AI.

Prerequisites

  1. Google AI API Key: You need access to Google's Gemini API

    • Get an API key from Google AI Studio
    • The API may require billing setup depending on usage
  2. Python Dependencies: Install the required packages

    pip install -r requirements.txt
    

Configuration

Set your API key using one of these methods:

Option 1: Environment Variable (Recommended)

# PowerShell (persistent)
[Environment]::SetEnvironmentVariable("GOOGLE_AI_API_KEY", "your-api-key-here", "User")

# PowerShell (current session only)
$env:GOOGLE_AI_API_KEY = "your-api-key-here"

Option 2: Alternative Environment Variable

$env:GEMINI_API_KEY = "your-api-key-here"

Usage with Gemini AI

Once configured, the Gemini AI agent will automatically be used for Player 2 when the --p2-ai flag is enabled (which is the default):

# Gemini AI will control Player 2 automatically
cli-mon teams/p1.txt teams/p2.txt --format gen7ou

# Support for Random Battles as well
cli-mon --randbat

Features of the Gemini AI Agent

  • Strategic Analysis: Evaluates complex battle states including HP, status conditions, type matchups, and team composition
  • Advanced Decision Making: Considers win conditions, hazard management, momentum, and endgame scenarios
  • Competitive Play Style: Follows high-level competitive Pokemon principles and strategies
  • Fallback Safety: Automatically falls back to basic heuristics if API calls fail

Model Configuration

The default model is gemini-2.5-flash-lite for optimal performance and cost. Advanced users can modify the model in gemini_agent.py:

# In gemini_agent.py, modify the init_gemini_agent function
agent = init_gemini_agent(model_name="gemini-2.5-flash")  # More capable but slower/costlier

Available models:

  • gemini-2.5-flash-lite (default): Fast, cost-effective
  • gemini-2.5-flash: More capable, higher cost
  • gemini-2.0-flash-exp: Experimental features

Troubleshooting Gemini Setup

  • "No API key found": Ensure your environment variable is set correctly and restart your terminal
  • API errors: Check that your API key is valid and you have sufficient quota
  • Import errors: Run pip install -r requirements.txt to install dependencies
  • Fallback behavior: If Gemini fails, the system automatically uses random decisions with a warning message

Bash (macOS/Linux):

git clone https://github.com/papichoolo/cli-mon-showdown.git
cd cli-mon-showdown

python3 -m venv .venv
source .venv/bin/activate

git clone https://github.com/smogon/pokemon-showdown.git
cd pokemon-showdown && npm ci && cd ..

python3 cli.py teams/p1.txt teams/p2.txt --format gen7ou

Setup Details

  • Python: this project uses the standard library plus optional AI dependencies. See requirements.txt for AI agent dependencies.
  • Node: used to run the Showdown simulator and its CLI utilities (simulate-battle, pack-team, validate-team, generate-team).
  • Showdown path: by default the code looks for pokemon-showdown/pokemon-showdown. Keep the folder at the project root or adjust the code if you move it.

CLI Usage

Basic:

cli-mon <p1_team> <p2_team> [--format FORMAT] [flags]

Random battle (no team files required):

cli-mon --randbat --format gen7randombattle

Flags

  • p1: path to Player 1 team file (Showdown importable).
  • p2: path to Player 2 team file.
  • --format FORMAT: Showdown format id. Default: gen7ou. Examples: gen7ou, gen9ou, gen7randombattle.
  • --randbat: generate random teams for both players (ignores p1/p2 positional args).
  • --no-auto-preview: disable automatic team preview ordering; you’ll be prompted to choose.
  • --side {p1|p2}: which side unprefixed commands control. Default: p1.
  • --p2-ai / --no-p2-ai: enable/disable AI for Player 2. When enabled with Gemini configured, uses Gemini AI agent. Default: enabled.
  • --humanize / --raw: show a summarized human-readable feed (default) or raw Showdown log lines.
  • --window / --no-window: render a minimal in-terminal game window (default) or print plain text only.
  • --debug: print additional debug information.

Examples:

# Gen 7 OU with built teams
cli-mon teams/p1.txt teams/p2.txt --format gen7ou

# Random battle using Showdown’s generator
cli-mon --randbat --format gen7randombattle

# Control p2 manually and show raw stream
cli-mon teams/p1.txt teams/p2.txt --side p2 --no-p2-ai --raw

# Disable the windowed UI and team auto-preview
cli-mon teams/p1.txt teams/p2.txt --no-window --no-auto-preview

# Play against Gemini AI with debug information
cli-mon teams/p1.txt teams/p2.txt --format gen9ou --debug --p2-ai

Teams

Team files should be in Pokémon Showdown’s import/export text format, for example:

Charizard @ Life Orb
Ability: Solar Power
EVs: 252 SpA / 4 SpD / 252 Spe
Timid Nature
- Solar Beam
- Fire Blast
- Air Slash
- Hidden Power Ice

When you run the CLI, your teams are packed and validated via Showdown’s CLI (pack-team and validate-team). If validation fails, the error output from Showdown is shown.

Troubleshooting

  • “node: not found” or “file not found”: ensure Node.js is installed and node is on your PATH.
  • Pokémon Showdown not found: confirm the folder exists at pokemon-showdown/ and run npm ci inside it.
  • Validation errors: check that your team is legal in the chosen --format.
  • Terminal window not rendering: some terminals may not support the UI; try --no-window.

Created by papichoolo. Uses the official Pokémon Showdown simulator.

Packaging and Release

Local build

python -m pip install --upgrade build twine
python -m build

Artifacts will land in dist/. Install one with pip install dist/cli_mon_showdown-<version>-py3-none-any.whl.

TestPyPI dry run

python -m twine upload --repository testpypi dist/*
python -m pip install --index-url https://test.pypi.org/simple/ cli-mon-showdown

Production release

  1. Bump the version in pyproject.toml.
  2. Tag the commit (git tag v0.1.1 && git push origin v0.1.1).
  3. Upload with python -m twine upload dist/* or trigger the GitHub Action described below.

GitHub Actions automation

Store a PyPI token as the PYPI_API_TOKEN repository secret (optionally scope it with an environment named pypi). The workflow in .github/workflows/publish.yml publishes whenever a tag that looks like v* is pushed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cli_mon_showdown-0.1.7-py3-none-any.whl (37.5 kB view details)

Uploaded Python 3

File details

Details for the file cli_mon_showdown-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for cli_mon_showdown-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 69aa58e59f6913027e4f6525e09f497421276d900385eaf8573d3ae43f655fe0
MD5 8344c7d00a677ca2a0acd0e218e1e95a
BLAKE2b-256 132aded4fdd41d155f87aee77a77cd7b42af09ff9882777f7b8a86388914afc4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page