StepanTita / q-learning

a Python-based platformer infused with Q-Learning and dynamic level creation from simple JSON files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Q-Learning game with epsilon-greedy algorithm ๐ŸŽฎ ๐Ÿง 

This is a university project. The game with basic level editing. One can add obstacles, enemies, and bonuses on the level by putting those in the JSON file. That way creating and editing test environments is as easy as adding a couple of rows to the JSON file. After the level is built, one should initialize some basic parameters and see the model performance. Based on that, one may consider updating or keeping the parameters. The game itself is just a set of primitives. The objects can either be static or moving. We also introduce the concept of reward backpropagation in this project.

More precise description of the solution and full report please find in the REPORT

Demo:

Screen.Recording.2023-08-10.at.20.37.54.mov

Features ๐Ÿš€

  • Q-Learning Powered: Experience a game environment influenced by Q-Learning.
  • Epsilon-Greedy Strategy: Watch the game evolve and adapt its strategy over time.
  • Custom Levels: Design and play on your very own levels using straightforward JSON structures:

*.json level file

{
  "floors": [
    {
      "shape": "rect",
      "type": "platform",
      "x": 0,
      "y": 650,
      "width": 150,
      "height": 10
    }
  ],
  "walls": [
    {
      "shape": "rect",
      "type": "wall",
      "x": 800,
      "y": 400,
      "width": 10,
      "height": 300
    }
  ],
  "spikes": [
    {
      "shape": "triangle",
      "type": "spike",
      "scale": 25,
      "internal_angle": 45,
      "rotation": 0,
      "x": 150,
      "y": 575,
      "rotor": true,
      "angle": 5
    }
  ],
  "finish": {
    "shape": "rect",
    "type": "finish",
    "x": 950,
    "y": 650,
    "width": 100,
    "height": 10
  }
}

Tech Stack ๐Ÿ“š

  • Python
  • Reinforcement Learning: Q-Learning with epsilon-greedy algorithm
  • Reward backpropagation concept. Please find detailed description in the REPORT

Getting Started ๐Ÿ

Prerequisites

  • Python 3.8+

Installation

  1. Clone the repository:
git clone https://github.com/StepanTita/q-learning.git
  1. Install requirements:
pip install -r requirements.txt
  1. Run the game:
python main.py

or

  1. Run the game in reinforcement learning mode:
cd reiforcement # make sure you are in the correct direction
python main.py

Level Creation ๐ŸŒ

Create custom levels using JSON files. Refer to the level creation guide to learn about the structure and possibilities!

License ๐Ÿ“„

This project is licensed under the MIT License. See the LICENSE.md file for details.

TODO:

  • enemies