Skip to content

jmduea/lux_agent_comp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

33 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Lux AI Season 3 Challenge - Deep Space Relic Explorer

Python JAX License Competition

A sophisticated multi-agent reinforcement learning system for the Kaggle Lux AI Season 3 Challenge, featuring custom pathfinding algorithms, Deep Q-Networks, and strategic exploration-exploitation balance for competitive gameplay in a dynamic space environment.

๐Ÿš€ Project Overview

This project implements intelligent agents capable of competing in the Lux AI Season 3 challenge, where two teams control units in deep space to explore ancient relics, harvest energy, and score points across best-of-5 match sequences. The challenge features:

  • Dynamic Environments: Procedurally generated 24x24 maps with asteroids, nebulae, and energy nodes
  • Fog of War: Limited vision based on unit positions and environmental factors
  • Strategic Depth: Balance between exploration in early matches and exploitation in later matches
  • Randomized Mechanics: Game parameters vary between matches, requiring adaptive strategies

โœจ Key Features

Advanced Agent Implementations

  • DQN-Based Agent: Deep Q-Network implementation using JAX for high-performance training
  • Q-Learning Agent: Traditional reinforcement learning with experience replay and exploration strategies
  • Relic Bot Base: Specialized pathfinding and relic discovery agent
  • Defensive Sapper: Strategic agent with defensive positioning and energy sapping capabilities

Technical Highlights

  • JAX Integration: High-performance numerical computing with GPU acceleration support
  • Custom Space Mapping: Efficient fog-of-war tracking and terrain analysis using JAX arrays
  • Pathfinding System: A* pathfinding with dynamic obstacle avoidance
  • Modular Architecture: Clean separation between agent logic, environment interaction, and utilities
  • Comprehensive Testing: Unit tests for core functionality with pytest
  • Replay System: Episode recording for post-match analysis and debugging

๐Ÿ—๏ธ Technical Architecture

lux_agent_comp/
โ”œโ”€โ”€ core/                    # Core agent framework
โ”‚   โ”œโ”€โ”€ base_agent.py       # Abstract base agent with DQN support
โ”‚   โ”œโ”€โ”€ space.py            # Space representation and fog-of-war tracking
โ”‚   โ”œโ”€โ”€ pathfinding.py      # A* pathfinding implementation
โ”‚   โ”œโ”€โ”€ node.py             # Node structure for pathfinding
โ”‚   โ””โ”€โ”€ debug.py            # Visualization tools
โ”œโ”€โ”€ lux/                    # Lux AI environment integration
โ”‚   โ”œโ”€โ”€ kit.py              # Lux AI kit utilities
โ”‚   โ””โ”€โ”€ utils.py            # Helper functions
โ”œโ”€โ”€ agent.py                # Main agent implementation
โ”œโ”€โ”€ dqn_agent.py           # Deep Q-Network agent
โ”œโ”€โ”€ main.py                # Kaggle submission entry point
โ”œโ”€โ”€ evaluate_agents.py     # Agent evaluation and testing
โ”œโ”€โ”€ test_env.py            # Environment testing utilities
โ”œโ”€โ”€ profiling.py           # Performance profiling
โ”œโ”€โ”€ saved_agents/          # Version-controlled agent snapshots
โ”‚   โ”œโ”€โ”€ q_learning_agent/
โ”‚   โ”œโ”€โ”€ relic_bot_base/
โ”‚   โ””โ”€โ”€ relic_bot_defensive_sapper/
โ””โ”€โ”€ tests/                 # Unit and integration tests

๐Ÿ› ๏ธ Technologies Used

Category Technologies
Core ML/RL JAX, Flax, Stable-Baselines3, Ray RLlib, OpenRL
Environment Gymnasium, PettingZoo, luxai-s3
Visualization Matplotlib, Seaborn, Plotly, TensorBoard, Weights & Biases
Utilities NumPy, Pygame (rendering), Beautiful Soup
Testing pytest, pytest-cov
Package Management uv, pip

๐Ÿ“ฆ Installation

Prerequisites

  • Python 3.10 or higher
  • (Optional) CUDA-capable GPU for JAX acceleration

Quick Start

  1. Clone the repository

    git clone https://github.com/jmduea/lux_agent_comp.git
    cd lux_agent_comp
  2. Install dependencies using uv (recommended)

    # Install uv if you don't have it
    pip install uv
    
    # Install project dependencies
    uv sync

    Or using pip:

    pip install -e .
  3. Install development dependencies (for testing)

    uv sync --group dev

๐ŸŽฎ Usage

Running the Main Agent

python main.py

This agent is designed to work with the Kaggle submission system and reads input from stdin following the Lux AI protocol.

Evaluating Agents

Compare different agent implementations:

python evaluate_agents.py

This script runs multiple games between agents and saves replays to the replays/ directory for analysis.

Testing the Environment

python test_env.py

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=core --cov=lux

# Run specific test files
pytest tests/core/test_space.py

Training a DQN Agent

python dqn_agent.py

Monitor training progress using TensorBoard or Weights & Biases integration.

Creating a Kaggle Submission

python create_submission.py

This packages your agent and dependencies into a submission-ready format for Kaggle.

๐ŸŽฏ Agent Implementations

1. Main Agent (agent.py)

The primary competition agent featuring:

  • Relic exploration with unknown tile targeting
  • Energy-aware movement decisions
  • Dynamic action selection based on game state
  • JAX-accelerated state processing

2. DQN Agent (dqn_agent.py)

Deep reinforcement learning agent with:

  • Flax-based neural network architecture
  • Experience replay buffer
  • Target network for stable training
  • Epsilon-greedy exploration

3. Saved Agent Variants

  • Q-Learning Agent: Traditional Q-learning with custom reward shaping
  • Relic Bot Base: Specialized relic discovery and collection strategy
  • Defensive Sapper: Focuses on defensive positioning and opponent disruption

๐Ÿ“Š Development Workflow

  1. Development: Implement and test agents locally
  2. Evaluation: Run agents against baseline implementations
  3. Profiling: Identify performance bottlenecks using profiling.py
  4. Visualization: Analyze game replays and agent behavior
  5. Iteration: Refine strategy based on evaluation results
  6. Submission: Package and submit to Kaggle

๐ŸŽ“ Key Learnings

  • Exploration vs Exploitation: Early match exploration is crucial for mapping relic positions and energy distributions
  • JAX Performance: Using JAX for state representation provides significant performance improvements
  • Pathfinding: Custom A* implementation handles dynamic obstacles (asteroids, nebulae) efficiently
  • Vision Management: Proper fog-of-war tracking is essential for strategic decision-making
  • Modular Design: Separating concerns allows for rapid agent iteration and testing

๐Ÿ”ฎ Future Improvements

  • Implement Monte Carlo Tree Search (MCTS) for strategic planning
  • Add multi-agent coordination strategies
  • Enhance opponent prediction and modeling
  • Optimize energy harvesting algorithms
  • Implement adaptive strategy selection based on game parameters
  • Add comprehensive reward shaping for RL training
  • Integrate transformer-based models for sequence prediction

๐Ÿค Contributing

This is a personal competition project, but feedback and suggestions are welcome! Feel free to open issues for discussion.

๐Ÿ“„ License

This project is open source and available for educational and portfolio purposes.

๐Ÿ™ Acknowledgments

  • Lux AI Challenge Team for creating an engaging competition
  • Kaggle community for strategies and insights
  • JAX and Flax teams for excellent ML frameworks

๐Ÿ“š Resources


Author: Jon Duea (jdueadev@gmail.com)

Repository: github.com/jmduea/lux_agent_comp

About

Experimentation with multi-agent reinforcement learning systems for the Kaggle Lux AI Season 3 Challenge

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages