Skip to content

AI opponent integration #61

@lisambet

Description

@lisambet

Description

user story : As a Player, I want to play Pong against an AI opponent so that I can practice or play when no human opponents are available.

Details

We need to implement a new microservice (pong-ai) that runs a pre-trained Reinforcement Learning model to control the opponent paddle.

Architecture

  • Service: Python (FastAPI)
  • Communication: The Game Service (Node.js) will send the current game state (ball position, velocity, paddle positions) to the AI Service via HTTP POST.
  • Model: PPO (Proximal Policy Optimization) using stable-baselines3.

Requirements

  • The AI must respond in <50ms to ensure real-time gameplay.
  • The model should be pre-trained (loaded from a .zip file on startup).

Additional context (screenshots, links, ...)

Note

The AI service endpoint should look like: POST /join-game
Body: { "ball_x": float, "ball_y": float, ... }
Response: { "action": 0 | 1 | 2 } (STOP, UP, DOWN)


Priority and estimates

  • Priority: High (Core Feature)
  • Estimate: 3 days

Definition of done

functional

Testing details :

  • Manual: Start a "Vs AI" game. Verify the opponent paddle tracks the ball and attempts to hit it.
  • Manual: Verify the game ends correctly when score limit is reached.
  • Manual: Ensure no lag/jitter in the paddle movement.

technical

  • Tests are written using Pytest (for the Python service) and Vitest (for the Node integration)
  • Tests are passing
  • API endpoint /join-game

others

  • Documentation is updated (Wiki: [[AI Service]], [[API Documentation]])
  • docker-compose.yml includes the new pong-ai container

Out of scope

  • Training the model from scratch during deployment (use pre-trained weights).
  • Adjustable difficulty levels (v1 will have a single difficulty).

Subtasks

  • DevOps: Create Dockerfile for Python service (install FastAPI, Stable Baselines3).
  • AI: Implement server.py with FastAPI and load the PPO model.
  • Backend: Add "Vs AI" game mode logic in Game Service (Node.js).
  • Backend: Implement HTTP client in Game Service to query AI Service.
  • Doc: Update Wiki with API specs.

Metadata

Metadata

Assignees

Labels

featureNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions