# DriveAI — Autonomous Agent Workshop

> **Building Autonomous Agents with Reinforcement Learning**

Teach a car to drive itself using Python and Q-Learning.

---

## Quick Start

```bash
# Install dependencies (one time)
pip install -r requirements.txt

# Start DriveAI
python start.py
```

The browser opens automatically at `http://localhost:8000`.

---

## What You'll Learn

```
Observe State
     ↓
Choose Action
     ↓
Environment Changes
     ↓
Receive Reward
     ↓
Learn
     ↓
Improve
```

---

## Student Files

You only need to edit these files:

| File | When |
|------|------|
| `student/agent.py` | Missions 1–3: write decision logic |
| `student/reward.py` | Mission 4+: customize rewards (unlocks later) |

### agent.py

```python
def choose_action(state):
    # state["speed"]               — current speed (0–150)
    # state["front_distance"]      — distance ahead to boundary
    # state["left_distance"]       — distance left to boundary  
    # state["right_distance"]      — distance right to boundary
    # state["track_angle"]         — deviation from track (-180 to 180°)
    # state["checkpoint_progress"] — fraction of checkpoints passed
    
    return "ACCELERATE"  # one of: ACCELERATE, BRAKE, TURN_LEFT, TURN_RIGHT, COAST
```

---

## Available Actions

| Action | Effect |
|--------|--------|
| `ACCELERATE` | Speed up |
| `BRAKE` | Slow down |
| `TURN_LEFT` | Turn left (when moving) |
| `TURN_RIGHT` | Turn right (when moving) |
| `COAST` | No input — friction slows you |

---

## Workshop Missions

| Mission | Goal |
|---------|------|
| 01 | Make the car move forward |
| 02 | Use sensor values to steer |
| 03 | Navigate the full track |
| 04 | Understand rewards |
| 05 | Enable learning |
| 06 | Train the agent |
| 07 | Final challenge |

---

## Troubleshooting

**App won't start:**
```bash
pip install -r requirements.txt
python start.py
```

**Browser doesn't open:**
Navigate manually to `http://localhost:8000`

**Agent error in browser:**
Check the red error panel — it shows the line number and problem.

**My changes aren't working:**
Make sure you clicked **Save** and then **Run**.

---

## Requirements

- Python 3.9+
- pip

No cloud accounts. No API keys. Works 100% offline.
