Skip to content

Conversation

@init27
Copy link
Contributor

@init27 init27 commented Nov 2, 2025

This idea came super thanks to @cpich3g from our Hackathon.
We are continuing here but thanks again Justin for leading and inspiring!

Adds a complete Pokemon battle environment integration using poke-env and Pokemon Showdown, following OpenEnv's HTTP-based framework patterns.

Design Decisions

Event Loop Management

  • poke-env runs on dedicated POKE_LOOP background thread
  • FastAPI runs on main uvicorn event loop
  • Proper async synchronization via asyncio.run_coroutine_threadsafe()
  • Lazy initialization of asyncio.Event objects on correct loop

Memory Management

  • Automatic battle cleanup every 10 episodes (prevents accumulation)
  • Previous battle task cancellation on reset
  • Stable memory usage over 100+ episodes

Concurrency

  • Single lock for both reset() and step() operations
  • Prevents race conditions in battle state access
  • Thread-safe action queuing

Error Handling

  • Illegal move validation with fallback to random legal action
  • Battle state validation before step execution
  • Comprehensive None checks for Pokemon attributes
  • Graceful handling of finished battles

File Structure

src/envs/pokemon_env/
├── init.py # Package exports
├── models.py # Action, Observation, State dataclasses
├── client.py # HTTPEnvClient implementation
├── README.md # Environment documentation
└── server/
├── init.py
├── app.py # FastAPI application
├── pokemon_environment.py # Core environment logic
├── Dockerfile # Container with Showdown + OpenEnv
└── requirements.txt # Dependencies

examples/project-pikachu/
├── test_local_pokemon.py # Direct environment tests (6 tests)
├── test_http_pokemon.py # HTTP client tests (6 tests)
└── [documentation files] # Testing guides and architecture docs

Reward Modes

Sparse (default):

  • +1.0 for win, -1.0 for loss, 0.0 otherwise

Dense:

  • +0.2 per opponent Pokemon fainted
  • -0.2 per own Pokemon fainted
  • +0.05 per HP% damage dealt
  • +0.5 bonus for win, -0.5 penalty for loss

Credits

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 2, 2025
@init27 init27 requested a review from zkwentz November 2, 2025 03:57
@github-actions
Copy link

github-actions bot commented Nov 2, 2025

⚠️ Deployment failed for pokemon_env

  • Space repo:
  • Live URL:

Please resolve your environment.

You can iterate locally or validate fixes by running scripts/deploy_to_hf.sh --env "pokemon_env".

@init27 init27 requested a review from Darktex November 2, 2025 03:57
Added observations on popular choices and practices in Pokemon-RL projects.
@github-actions
Copy link

github-actions bot commented Nov 2, 2025

✅ Deployment succeeded for pokemon_env

Nice work! Wait for a code review and we're ready to go.

You can iterate locally or validate fixes by running scripts/deploy_to_hf.sh --env "pokemon_env".

Add observations section to Readme
@github-actions
Copy link

github-actions bot commented Nov 2, 2025

✅ Deployment succeeded for pokemon_env

Nice work! Wait for a code review and we're ready to go.

You can iterate locally or validate fixes by running scripts/deploy_to_hf.sh --env "pokemon_env".

cpich3g and others added 5 commits November 3, 2025 11:55
- Introduced a comprehensive tutorial for using the OpenEnv Pokemon Battle Environment.
- Included sections on setup, battle mechanics, observations, available moves, and actions.
- Demonstrated a complete battle simulation and a simple strategy agent.
- Ensured proper connection to the environment and handling of battle states.
- Created a Jupyter notebook tutorial for the Pokemon Battle Environment, covering setup, battle mechanics, and agent strategies.
- Added a shell script to test the Pokemon environment Docker image, ensuring services are running and performing basic environment interactions.
Updated Pokemon_Env & added a test notebook
@github-actions
Copy link

github-actions bot commented Nov 3, 2025

✅ Deployment succeeded for pokemon_env

Nice work! Wait for a code review and we're ready to go.

You can iterate locally or validate fixes by running scripts/deploy_to_hf.sh --env "pokemon_env".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. New Environment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants