Reinforcement Learning
stable-baselines3
English
sb3-contrib
gymnasium
maskable-ppo
utdg
tower-defense
game-ai
deep-reinforcement-learning
Eval Results (legacy)
Instructions to use chrisjcc/utdg-maskableppo-policy with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- stable-baselines3
How to use chrisjcc/utdg-maskableppo-policy with stable-baselines3:
from huggingface_sb3 import load_from_hub checkpoint = load_from_hub( repo_id="chrisjcc/utdg-maskableppo-policy", filename="{MODEL FILENAME}.zip", ) - Notebooks
- Google Colab
- Kaggle
File size: 10,961 Bytes
d5334ec 0742362 d5334ec e3c8f7e 0742362 e3c8f7e 0742362 e3c8f7e 09b634e e3c8f7e 09b634e e3c8f7e fea30a7 3b514c6 fea30a7 0742362 fea30a7 0742362 e3c8f7e 3866bf6 f2ae026 8f1a8c4 f2ae026 3866bf6 f2ae026 e3c8f7e 8f1a8c4 3866bf6 e3c8f7e 8f1a8c4 f2ae026 3866bf6 f2ae026 0fe111e 8f1a8c4 0fe111e 80ce673 3866bf6 e3c8f7e fea30a7 e3c8f7e fea30a7 3b514c6 fea30a7 6496399 fea30a7 6496399 fea30a7 6496399 fea30a7 e3c8f7e 0208e0c e3c8f7e 50cea6d 3866bf6 50cea6d 5c987e7 3866bf6 5c987e7 3866bf6 50cea6d a974935 50cea6d e3c8f7e d5334ec e3c8f7e d5334ec 0742362 fea30a7 3b514c6 fea30a7 0742362 fea30a7 0742362 d5334ec e3c8f7e 0742362 09b634e 0742362 d5334ec 0742362 d5334ec 0742362 09b634e 0742362 09b634e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | ---
language: en
license: mit
library_name: stable-baselines3
tags:
- reinforcement-learning
- stable-baselines3
- sb3-contrib
- gymnasium
- maskable-ppo
- utdg
- tower-defense
- game-ai
- deep-reinforcement-learning
datasets:
- custom-utdg-env
metrics:
- episode_reward
- episode_length
model-index:
- name: MaskablePPO-UTDG
results:
- task:
type: reinforcement-learning
name: Tower Defense
dataset:
type: custom
name: UTDG Environment
metrics:
- type: episode_reward
name: Mean Episode Reward
value: TBD
pipeline_tag: reinforcement-learning
metadata:
utc_timestamp: 2025-12-27T18:33:32.663706
env_name: UTDGEnv-v0
model_file: model_policy_v0.3.5.zip
total_timesteps: 0
learning_rate: 0.0003
n_steps: 2048
batch_size: 64
n_epochs: 10
gamma: 0.99
gae_lambda: 0.95
clip_range: 0.2
ent_coef: 0.001
vf_coef: 0.5
task: reinforcement-learning
algorithm: MaskablePPO
game: Untitled Tower Defense Game
hydra_config: |
{
"runtime": {
"mode": "web-hf-train",
"web": {
"enabled": true,
"path": "builds/web",
"http_port": 8080
},
"launcher": {
"enabled": false,
"mode": null,
"auto_port": false,
"browser": false,
"headless": false
},
"connection": {
"type": "websocket",
"role": "server",
"url": null,
"timeout": 60.0,
"reconnect_attempts": 5
},
"server": {
"enabled": true,
"host": "0.0.0.0",
"port": 7860,
"routes": {
"ui": "/ws",
"godot": "/godot"
}
},
"godot_path": null,
"max_episode_steps": 5000,
"resume": false,
"checkpoint_path": "checkpoints/maskableppo_utdg_100000_steps.zip"
},
"env": {
"observation_space": {
"include_enemy_health": true,
"include_tower_stats": true,
"grid_resolution": 32,
"normalize": true
},
"action_space": {
"type": "discrete",
"max_towers": 10
},
"episode": {
"max_episode_steps": 5000,
"truncate_on_life_lost": false,
"starting_gold": 150,
"base_health": 10
}
},
"agent": {
"type": "maskable_ppo",
"deterministic": true
},
"model": {
"policy": "MaskableActorCriticPolicy",
"learning_rate": 0.0003,
"n_steps": 2048,
"batch_size": 64,
"n_epochs": 10,
"gamma": 0.99,
"gae_lambda": 0.95,
"clip_range": 0.2,
"normalize_advantage": true,
"ent_coef": 0.001,
"vf_coef": 0.5,
"max_grad_norm": 0.5
},
"training": {
"total_timesteps": 200000,
"device": "auto",
"log_interval": 2048,
"progress_bar": true,
"verbose": 1,
"curriculum": {
"enabled": false,
"initial_max_steps": 500,
"step_increase": 1000,
"reward_thresholds": [
-50,
-25,
0,
25,
50,
100
],
"window_size": 20,
"max_steps_cap": 10000
}
},
"checkpoint": {
"enabled": true,
"save_path": "checkpoints",
"save_freq": 10000,
"save_best_only": true,
"keep_last": 3,
"name_prefix": "model_policy",
"save_replay_buffer": false,
"save_vecnormalize": false
},
"callbacks": {
"wandb": {
"enabled": true,
"project": "utdg",
"entity": "rl4aa",
"run_name": null,
"tags": [],
"mode": "online",
"save_code": true,
"eval_enabled": false
},
"hf_upload": {
"enabled": true,
"repo_id": "chrisjcc/utdg-maskableppo-policy",
"private": true,
"repo_type": "model",
"token": null,
"metadata": {
"task": "reinforcement-learning",
"algorithm": "MaskablePPO",
"game": "Untitled Tower Defense Game"
},
"push_strategy": "final",
"local_model_path": "",
"upload_freq": 10000,
"commit_message": "Upload model checkpoint",
"lfs": {
"use_lfs": true,
"files": [
"*.zip",
"*.onnx"
]
}
}
},
"experiment": {
"name": "utdg_experiment",
"seed": 42,
"log_dir": "logs"
},
"logging": {
"level": "INFO",
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
}
}
---
# UTDG MaskablePPO Agent
[](https://huggingface.co/chrisjcc/utdg-maskableppo-policy)
[](https://sb3-contrib.readthedocs.io/)
[](https://opensource.org/licenses/MIT)
> A trained reinforcement learning agent for the Untitled Tower Defense Game using MaskablePPO.
## Model Details
### Description
This model is a **MaskablePPO** (Proximal Policy Optimization with invalid action masking) agent trained on the UTDG (Untitled Tower Defense Game) environment. The agent learns to strategically place and upgrade towers to defend against waves of enemies.
### Model Architecture
- **Algorithm**: MaskablePPO from [sb3-contrib](https://github.com/Stable-Baselines-Contrib/stable-baselines3-contrib)
- **Policy Network**: MlpPolicy (Multi-layer Perceptron)
- **Framework**: [Stable-Baselines3](https://stable-baselines3.readthedocs.io/)
- **Environment**: Custom UTDG Gymnasium environment with action masking
### Training Hyperparameters
| Parameter | Value |
|-----------|-------|
| Total Timesteps | 0 |
| Learning Rate | 0.0003 |
| N Steps | 2048 |
| Batch Size | 64 |
| N Epochs | 10 |
| Gamma (γ) | 0.99 |
| GAE Lambda (λ) | 0.95 |
| Clip Range | 0.2 |
| Entropy Coefficient | 0.001 |
| Value Function Coefficient | 0.5 |
## Usage
### Quick Start
```python
from huggingface_hub import hf_hub_download
from sb3_contrib import MaskablePPO
# Download the model from Hugging Face Hub
model_path = hf_hub_download(
repo_id="chrisjcc/utdg-maskableppo-policy",
filename="model_policy_v0.3.5.zip"
)
# Load the trained model
model = MaskablePPO.load(model_path)
```
### Inference with Action Masking
```python
import gymnasium as gym
from sb3_contrib import MaskablePPO
# Assuming you have the UTDG environment installed
# from utdg_env import UTDGEnv
# Load model
model = MaskablePPO.load(model_path)
# Create environment
env = gym.make("UTDGEnv-v0")
obs, info = env.reset()
# Run inference loop
done = False
total_reward = 0
while not done:
# Get action mask from environment info
action_masks = info.get("action_mask", None)
# Predict action with masking
action, _states = model.predict(
obs,
action_masks=action_masks,
deterministic=True # Set False for stochastic behavior
)
# Step environment
obs, reward, terminated, truncated, info = env.step(action)
done = terminated or truncated
total_reward += reward
print(f"Episode reward: {total_reward}")
env.close()
```
### Load Specific Revision
```python
from sb3_contrib import MaskablePPO
# Load from a specific branch/revision
model = MaskablePPO.load(
"chrisjcc/utdg-maskableppo-policy",
revision="production" # or "main", specific commit hash, etc.
)
```
## Environment
### UTDG (Untitled Tower Defense Game)
The agent is trained on a custom tower defense environment with the following characteristics:
#### Observation Space
- Grid-based game state representation
- Tower positions and types
- Enemy positions and health
- Player resources (gold, lives)
- Wave information
#### Action Space
- Discrete action space with invalid action masking
- Actions include: place tower, upgrade tower, sell tower, skip turn
- Action masking prevents invalid actions (e.g., placing towers on occupied tiles)
#### Reward Structure
- Positive rewards for defeating enemies
- Negative rewards for losing lives
- Bonus rewards for completing waves
- Efficiency bonuses for resource management
## Training
### Methodology
The model was trained using the MaskablePPO algorithm, which extends standard PPO with support for invalid action masking. This is crucial for the tower defense domain where many actions are contextually invalid (e.g., placing a tower on an occupied cell).
### Key Features
1. **Action Masking**: Prevents the agent from selecting invalid actions, improving sample efficiency
2. **Curriculum Learning**: Progressive difficulty increase through wave complexity
3. **Reward Shaping**: Carefully designed reward function to encourage strategic play
### Training Infrastructure
- Trained using [Stable-Baselines3](https://stable-baselines3.readthedocs.io/) and [sb3-contrib](https://sb3-contrib.readthedocs.io/)
- Configuration managed via [Hydra](https://hydra.cc/)
- Experiment tracking and model versioning via Hugging Face Hub
## Repository Contents
| File | Description |
|------|-------------|
| `model_policy_v0.3.5.zip` | Trained MaskablePPO model checkpoint (SB3 format) |
| `README.md` | This model card with full documentation |
| `config.yaml` | Hydra configuration snapshot (if included) |
## Limitations and Intended Use
### Intended Use
- Research and experimentation with RL agents in game environments
- Baseline comparisons for tower defense AI development
- Educational purposes for understanding action-masked RL
### Limitations
- Trained on a specific map configuration; may not generalize to significantly different layouts
- Performance may vary with different enemy compositions not seen during training
- Requires the UTDG environment to be installed for inference
### Ethical Considerations
This model is designed for entertainment and research purposes in a game simulation context.
## Citation
If you use this model in your research, please cite:
```bibtex
@misc{utdg-maskableppo,
author = {Chris Cadonic},
title = {UTDG MaskablePPO Agent},
year = {2025},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/chrisjcc/utdg-maskableppo-policy}}
}
```
## Acknowledgments
- [Stable-Baselines3](https://github.com/DLR-RM/stable-baselines3) team for the RL framework
- [sb3-contrib](https://github.com/Stable-Baselines-Contrib/stable-baselines3-contrib) for MaskablePPO implementation
- [Hugging Face](https://huggingface.co/) for model hosting infrastructure
---
*Generated on 2025-12-27T18:33:32.663706 UTC*
|