Upgrade to Pro — share decks privately, control downloads, hide ads and more …

From Pygame to Trained Agents with Open-Source ...

From Pygame to Trained Agents with Open-Source Tools

Promo Slides for Workshop Tutorial for OpenSouthCode 2026 Submission

Avatar for David Olivieri

David Olivieri

February 28, 2026

Other Decks in Programming

Transcript

  1. BuildYourOwn RLPlayground From Pygame to Trained Agents with Open-Source Tools

    Málaga · OpenSouthCode 2026 · 2h Workshop ▷ @AlgorithmicMatters
  2. The Problem Everyone runs someone else’s RL environments. Almost nobody

    learns to build their own. pip install gym Run CartPole demo Copy a training script ??? What next ??? Design your own game world Wrap it as a Gymnasium env Train agents & watch them learn This workshop ▷ @AlgorithmicMatters OpenSouthCode 2026 · Málaga
  3. The Open-Source Stack Everything we use is free, open-source, and

    community-maintained. Pygame Game & simulation Gymnasium Standard RL API Stable- Baselines3 RL algorithms TensorBoard Visualization NumPy PettingZoo multi-agent Godot (next step) You leave with a forkable MIT-licensed repo ▷ @AlgorithmicMatters OpenSouthCode 2026 · Málaga
  4. What We’ll Build The Game (worked example) • Agents move

    on a 2D map • Signal sources that must be covered • Agents have limited vision — no god’s-eye view • Cooperation is required to cover all signals The theme is a starting point. Reskin it as: → Drones mapping a disaster zone → Robots in a warehouse → Characters in a cooperative roguelike → Your idea here! SwarmSignal — Pygame • Agent • Signal ▪ Obstacle ▷ @AlgorithmicMatters OpenSouthCode 2026 · Málaga
  5. Workshop Roadmap — 2 Hours 0:00 0:30 1:00 1:30 2:00

    30 min Simulation Agents, obstacles, collisions, render loop + human play mode 30 min Gymnasium reset(), step(), obs/action spaces, seeding, reproducibility 30 min SB3 Training PPO, reward shaping, watch agents learn, TensorBoard 15 min Next Steps Partial observability, communication, Godot bridge, OSS repo Bring your laptop · Python required · No RL experience needed ▷ @AlgorithmicMatters OpenSouthCode 2026 · Málaga
  6. A Taste of the Code The Gymnasium wrapper import gymnasium

    as gym from gymnasium import spaces import numpy as np class SwarmEnv(gym.Env): metadata = {" render_modes ": ["human", "rgb_array"]} def __init__(self , n_agents =4, grid_size =20): super ().__init__ () self. action_space = spaces.Discrete (5) self. observation_space = spaces.Box( low=0, high=1, shape =( n_agents , 8), dtype=np.float32 ) def reset(self , seed=None , **kw): super ().reset(seed=seed) # ... init world state return obs , info def step(self , action): # ... physics + rewards return obs , reward , done , truncated , info Training with Stable-Baselines3 from stable_baselines3 import PPO from stable_baselines3 .common.env_util \ import make_vec_env # One line to vectorize env = make_vec_env ( "SwarmSignal -v0", n_envs =4 ) # Train model = PPO( "MlpPolicy", env , verbose =1, tensorboard_log ="./ tb_logs/" ) model.learn( total_timesteps =100 _000) # Watch the result ! obs = env.reset () for _ in range (1000): action , _ = model.predict(obs) obs , reward , done , info = \ env.step(action) env.render () ▷ @AlgorithmicMatters OpenSouthCode 2026 · Málaga
  7. The Payoff: AI agent learns in your environment Reward Training

    steps Agents learn to cooperate! You built the game. You trained the AI. You own the whole stack! ▷ @AlgorithmicMatters OpenSouthCode 2026 · Málaga
  8. What You Take Home Template repo (MIT license) Fork, modify,

    publish — it’s yours Gymnasium API mastery The standard interface for all RL SB3 training pipeline PPO on your own environment Clear extension path Multi-agent, Godot, your own theme ✓ Python basics is the only prerequisite ✓ No RL experience needed ✓ Bring a laptop ▷ @AlgorithmicMatters OpenSouthCode 2026 · Málaga
  9. Join the Workshop Build · Train · Open-Source Where: OpenSouthCode

    2026 — Málaga Format: 2-hour hands-on workshop Web: opensouthcode.org/conferences/opensouthcode2026 YouTube: @AlgorithmicMatters — subscribe for updates! Code: Repo link coming soon Built with open-source. Shared as open-source. That’s the whole point.