Skip to content

carlospuenteg/Q-Racer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Track Solver with Q-Learning

Index

  1. Description
  2. How It Works
  3. Output
  4. Installation
  5. Usage
  6. Configuration
  7. Project Structure

Description

This AI can train a car to complete a custom track drawn by the user and find the shortest path possible. The AI is made from scratch using custom classes and utilizes a Q-Learning Agent for training.

How It Works

  • draw_track.py: Allows you to create a custom track using Pygame.
  • train.py: Trains a Q-Learning Agent to find the optimal path to reach the finish on your custom track.

Output

  • Learning curve: Graph of the learning curve
  • Best attempt: Video of the best attempt.
  • GIFs: GIFs of the best attempts; of each time the max reward is surpassed
  • Combined attempts: Video of the combined attempts.

Example Output

Learning Curve

Graph depicting the AI's learning trajectory over training sessions.

Best Attempt Video

Video

Footage of the AI's optimal path completion.

Combined Attempts Video

Video

Montage video showing a range of attempts, visualizing the AI's evolution.

GIFs of Milestones

GIFs capturing breakthrough moments when the AI outperformed its previous best (these are just some of them).

Installation

  1. Clone the repository:
    git clone <repository_link>
  2. Install required packages:
    pip install -r requirements.txt

Usage

Drawing a Track

Run draw_track.py to create your own track:

python3 draw_track.py

Controls:

Colors
  • Options
    • ⌃ Control S Save track.
    • ⌃ Control Z Undo.
  • Bucket fill (⇧ Shift) COLOR Left Click
    • B Background color.
    • R Road color.
    • O Obstacle/border color.
    • S Start color.
    • F Finish color.

Training the AI

After drawing your track, run train.py:

python3 train.py

This initiates the training loop and generates videos and graphs of the training process. The training process can be configured in the conf directory.

Configuration

Customize various settings in the conf directory:

Project Structure

  • classes/:
  • constants/: Constant values and paths.
  • conf/: Configuration settings.
  • utils/: Utility functions like plotting.
  • track/: Stores the custom track.
    • track.npy: Numpy array of the track.
  • out/: Stores the learning curve PNG image after training.
    • learning_curve.png: Learning curve PNG image.
    • best_attempt.mp4: Video of the best attempt.
    • combined_attempts.mp4: Video of the combined attempts.
    • attempts/: Folder containing GIFs of the best attempts; of each time the max reward is surpassed.
  • train.py: Trains a Q-Learning Agent to find the optimal path to reach the finish on your custom track.
  • draw_track.py: Allows you to create a custom track using Pygame.
  • requirements.txt: Required packages.
  • LICENSE.md: MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages