en license:mit region:us
---
license: mit
language:
- en
---

# README for Flappy-AI with Reinforcement Learning

Model for the repository [flappy-ai](https://github.com/amc-madalin/flappy-ai), an project that utilizes reinforcement learning, to train an AI agent to master the game of Flappy Bird. This model is the 20th episode for the following hyperparameters:

# File: config.yml
```
game_screen:
  width: 800
  height: 600

game_mechanics:
  gravity: 5
  flap_strength: 20
  pipe_speed: 2
  pipe_width: 100
  pipe_gap: 200
  character_size: 50
  collision_penalty: -1  # Penalty for hitting a pipe
  pass_reward: 1          # Reward for successfully passing a pipe
  height_penalty: -0.1    # Penalty for flying too high or too low

initial_positions:
  character_x: 350
  character_y: 250
  pipe_x: 800
  pipe_height_min: 100
  pipe_height_max: 400

ai_config:
  epsilon: 0.3
  epsilon_min: 0.01
  epsilon_decay: 0.98
  gamma: 0.1
  learning_rate: 0.0001
  batch_size: 32
  buffer_size: 5000
  num_episodes: 500

other_settings:
  random_seed: 42

model:
  save_path: ./experiments/
  load_path: ~
```
## Project Structure

- `ai/`: This directory houses the core AI components, including the Q-network for decision making, the replay buffer for learning from past actions, and the training logic essential for the agent's learning process.
- `assets/`: Here, you'll find all the graphical and audio assets utilized in the project, enriching the game's visual and auditory experience.
- `configs/`: Contains various configuration files that allow customization and fine-tuning of the AI agent and the game environment.
- `environment.yml`: A comprehensive list of dependencies required for the project, ensuring consistent setup across different environments.
- `experiments/`: This section includes experimental code and data, showcasing the trials and tests conducted during the development process.
- `game/`: Contains the game's logic and rendering code, the heart of the Flappy Bird game that the AI interacts with.
- `model/`: Here lies the trained AI model, a testament to the learning and adaptation achieved through reinforcement learning.
- `runs/`: Stores outputs from various training runs, providing insights into the AI's performance and learning progression.
- `utils/`: A collection of utility scripts and modules that support various functionalities across the project.
- `train.py`: The primary script used to kickstart the AI agent's training process.
- `test_game.py`: A testing script to run the game independently of the AI agent, useful for debugging and game playthroughs.

## Installation

To set up this project on your local machine, follow these steps:

1. Clone the repository:
  ```sh
  git clone https://github.com/amc-madalin/flappy-ai.git
  ```
2. Navigate to the project directory:
  ```sh
  cd flappy-ai
  ```
3. Install the required dependencies:
  ```sh
  conda env create -f environment.yml
  ```

## Usage

Once the installation is complete, you can start exploring Flappy-AI.

1. Activate the project environment:
  ```sh
  conda activate flappy-ai
  ```
2. To begin training the AI agent, execute:
  ```sh
  python train.py
  ```
3. To test the game mechanics without the AI agent, run:
  ```sh
  python test_game.py
  ```

## License

This project is released under the MIT License, promoting open-source collaboration and sharing.

