Source code of dpickleball-rl-agent, also published at https://github.com/WAYTECHG/dpickleball-rl-agent
dPickleBall: Deep Reinforcement Learning Agent
PPO agents trained with curriculum learning, reward shaping and league self-play Β· 2nd place of 13 teams
Overview
This project trains autonomous agents for the Unity dPickleBall environment with Proximal Policy Optimization (PPO). The agent learns three-dimensional discrete control: vertical movement, horizontal movement and paddle rotation.
Self-play between untrained policies produces weak interactions and little learning signal, because neither side can return the ball. The project addresses this with a two-stage training framework: foundation skills are learned first in a simplified wall environment, and the resulting policies are then improved through competitive league self-play.
| Method | Evaluation | Result |
|---|---|---|
| PPO with a six-level curriculum, reward shaping and league self-play | Internal round-robin tournament, then a Top-4 confirmation stage | 2nd place among 13 competing teams |
| Course | AIT306, Deep Reinforcement Learning |
| Institution | Xiamen University Malaysia |
| Team | Group 11, April 2026 semester |
Training pipeline
dPickleBall Environment
β
βΌ
Foundation Training
Six-Level Wall Curriculum
β
βΌ
PPO + Reward Shaping
β
βΌ
Trained Policies
β
βΌ
League Self-Play
Dynamic Opponent Pool
β
βΌ
PSRO / SFL-Inspired Selection
β
βΌ
Round-Robin Evaluation
β
βΌ
Final Agent: RealFT
Stage 1: foundation wall training
A six-level curriculum develops basic gameplay behaviour in a simplified wall-based environment.
| Level | Ball speed range | Rebound angle | Focus |
|---|---|---|---|
| 1 | 0.85β1.35 | Β±45Β° | Basic tracking and contact |
| 2 | 2.35β3.05 | Β±45Β° | Faster reactions |
| 3 | 0.35β0.80 | Β±75Β° | Wide-angle interception |
| 4 | 1.85β2.35 | Β±75Β° | Diverse medium-fast trajectories |
| 5 | 0.35β3.70 | Β±75Β° | Mixed-speed adaptation |
| 6 | 0.80β3.70 | Β±75Β° | Stronger controlled returns |
Reward shaping encourages effective movement, paddle alignment, successful returns and recovery positioning. Penalties discourage passive behaviour, poor contact and ineffective positioning. Different reward configurations were tried to produce agents with distinct playing styles.
Stage 2: league self-play
After foundation training, the agents move to competitive self-play in the Unity environment, with PPO improving action selection through clipped policy updates.
The action space is MultiDiscrete([3, 3, 3]):
| Action | Available controls |
|---|---|
| Vertical movement | None, Up, Down |
| Horizontal movement | None, Right, Left |
| Paddle rotation | None, Counter-clockwise, Clockwise |
The opponent pool holds independently trained agents, historical checkpoints and earlier learner policies. To avoid overfitting to a single opponent, selection combines:
- PSRO-inspired selection: a population of policies for adaptive opponent sampling.
- SFL-inspired frontier sampling: priority for opponents near the learner's current skill level.
- Softmax-based sampling: a balance between opponent difficulty and diversity.
Evaluation
Candidate agents were compared in internal round-robin tournaments, followed by a Top-4 confirmation stage.
| Rank | Agent | Series WβL | Game WβL | Point difference |
|---|---|---|---|---|
| 1 | RealFT | 2β1 | 5β2 | +20 |
| 2 | Haoren Original Lifted | 2β1 | 3β3 | β17 |
| 3 | Wilbert Blocker Converted | 1β2 | 4β4 | +1 |
| 4 | V67 Best 3 | 1β2 | 2β5 | β4 |
RealFT had the strongest internal result and was selected as the competition agent. It was then played against the agents of the other groups, and the team finished 2nd of 13.
RealFT uses a different checkpoint on each side, chosen through real-game matches against a reference opponent:
| Side | Checkpoint | Origin |
|---|---|---|
Left (TeamX, model_left.pt) |
realft_01600004 |
PPO fine-tuned in the real Unity game, then 1.6M steps against a PFSP opponent pool |
Right (TeamY, model_right.pt) |
realft_00300000, mirrored |
300k-step real-game fine-tune, mirrored through the court's centre line |
Both are small TorchScript policies (13β128β128β64 tanh, separate vertical and horizontal heads, rotation fixed at 0). They act on 16 features extracted with OpenCV from the 168Γ84 camera frame.
My contributions
This was a group project, and training and final selection were carried out collaboratively. My own work was:
- Trained and tuned an independent PPO agent.
- Tested reward and penalty configurations to improve gameplay behaviour.
- Evaluated trained policies through repeated testing and comparison.
- Contributed candidate policies for team-wide evaluation; my candidate reached the Top-4 stage.
- Took part in selecting the final competition agent.
Technology stack
| Category | Technologies and methods |
|---|---|
| Language | Python |
| Deep learning | PyTorch |
| Simulation | Unity, Unity ML-Agents |
| RL algorithm | Proximal Policy Optimization (PPO) |
| Training | Curriculum learning, reward shaping, league self-play |
| Opponent selection | PSRO-style and SFL-inspired sampling |
| Evaluation | Round-robin tournament |
Repository structure
dpickleball-rl-agent/
βββ Competition Script/
β βββ Competition.py # Runs a match in the Unity competition build
β βββ teamX.py / teamY.py # Left and right RealFT players (OpenCV features + policy)
β βββ model_left.pt / model_right.pt # RealFT TorchScript checkpoints
βββ Foundation training/ # Curriculum-based wall training
βββ League Self-Play Training/ # PPO training and opponent selection
βββ README.md
Getting started
Tested on Windows 10/11 with Python 3.10.12. A GPU is not required to run matches.
1. Create the Python environment
Install Miniconda (or Anaconda) and Git, then open Anaconda Prompt or PowerShell:
conda create -n dpickleball pip python=3.10.12
conda activate dpickleball
2. Install the dPickleBall version of Unity ML-Agents
The game talks to Python through dPickleBall's own fork of ML-Agents, which adds the side channel used to start the match. Install the fork, not mlagents-envs from PyPI:
git clone https://github.com/dPickleball/dpickleball-ml-agents.git
cd dpickleball-ml-agents
pip install -e ./ml-agents-envs
pip install -e ./ml-agents
cd ..
Keep the dpickleball-ml-agents folder, because the -e install loads ML-Agents from it.
3. Install the other packages
pip install numpy==1.23.5 opencv-python==4.7.0.72 matplotlib pynput==1.8.1
pip install torch==2.5.1
The training code also needs:
pip install stable-baselines3 gymnasium tensorboard
4. Download the Unity game
Download the dPickleBall build from the official dPickleBall Google Drive, linked from the dPickleBallEnv repository, and extract it. You need the Windows builds:
dPickleball BuildFiles/
βββ Competition/Windows/dp.exe # Used to run matches
βββ Training/Windows/dp.exe # Used by League Self-Play Training
5. Clone this repository
git config --global core.longpaths true
git clone https://github.com/WAYTECHG/dpickleball-rl-agent.git
cd dpickleball-rl-agent
The first line lets Windows check out the long checkpoint file names in League Self-Play Training/league_pool_filtered/. Without it, the clone can fail with Filename too long.
6. Run a match: RealFT against RealFT
conda activate dpickleball
cd "Competition Script"
python Competition.py --env-path "C:\path\to\dPickleball BuildFiles\Competition\Windows\dp.exe"
- The game opens on its title screen. Optionally type the player names, then click START.
- Keep the game window in front while it plays. The game pauses when it loses focus.
- The score is printed in the terminal. Press
Ctrl+Cto stop.
| Argument | Description |
|---|---|
--env-path |
Path to the Competition build dp.exe. Setting the DPICKLEBALL_EXE environment variable also works. |
--serve |
Serve code sent to the game (default 212, as in the competition). |
--wait |
Seconds to wait for START to be clicked (default 300). |
teamX.py (left) and teamY.py (right) load model_left.pt and model_right.pt from the same folder. To try another agent, replace those files with its TorchScript policies.
7. Train (optional)
Foundation training runs in a lightweight Python wall simulator, so the Unity game is not needed:
cd "Foundation training"
python run_train.py
League self-play training runs 6 learners in parallel in the Unity Training build. Point it at your Training/Windows/dp.exe:
cd "League Self-Play Training"
python run_fast_training.py --build-path "C:\path\to\dPickleball BuildFiles\Training\Windows\dp.exe"
python run_normal_finetune.py --build-path "C:\path\to\dPickleball BuildFiles\Training\Windows\dp.exe"
See the README in each folder for details and options.
Troubleshooting
| Problem | Fix |
|---|---|
UnityTimeOutException: The Unity environment took too long to respond |
Click START on the game's title screen, and check that --env-path points to Competition/Windows/dp.exe. |
ModuleNotFoundError: No module named 'mlagents_envs.envs.custom_side_channel' |
mlagents-envs from PyPI is installed in place of the dPickleBall fork. Run pip uninstall mlagents-envs, then repeat step 2. |
ModuleNotFoundError: No module named 'PIL' or 'typing_extensions' |
pip install Pillow typing_extensions |
error: Filename too long while cloning |
Run git config --global core.longpaths true and clone again. |
| The game freezes mid-match | The game window lost focus. Click on it to continue. |
Acknowledgements
Developed collaboratively for AIT306, Deep Reinforcement Learning at Xiamen University Malaysia. The project builds on the original dPickleBall environment and the dPickleBall ML-Agents fork; credit for the simulation remains with their authors.