Escape a maze using (deep) reinforcement learning
Generates a grid maze, with start, finish and walls, which an agent has to navigate. The agent can move through the maze by performing actions and learning from them.
- Install poetry for dependency management and install venv:
poetry install - Open poetry shell:
poetry shellThen run the desired Python commands.
A complete configuration should be in root/config/ and consists of:
- Config file: Maze settings, parameters, training
- Maze file: Text file containing a maze with walls (1) and hallways (0) and other features.
Choose settings in root/config/<config_file>:
- epochs
- learning rate
$\alpha$ - discount rate
$\gamma$ - exploration vs. exploitation
$\epsilon$ - rewards
Custom mazes and configurations can easily be added.
RLMaze can easily be used as follows:
from rlmaze.rlmaze import RLMaze
RLMaze(<config_file>).escape_maze()
to train on a maze. The maze can be visualized with:
Utils().visualize_maze(<config_file>)
Some test cases can be found in `root/tests/' and run with:
python tests/test_maze_diagonal.py
or
python tests/test_maze_13x13.py

Fig 1: Diagonal maze layout with start (S) and finish (F).

Fig 2: Diagonal maze training (deep RL). Convergence to optimal number of steps (8).

Fig 2: Diagonal maze training (Classic Q-learning). Convergence to optimal number of steps (8).

Fig 3: Diagonal maze layout with start (S) and finish (F).

Fig 4: 13x13 maze training (Classic Q-learning). Convergence to optimal number of steps (20).