Skip to content

Utilizing evolutionary algorithms to mutate agents gens so they are able to find the best possible way through a maze represented as a 2D matrix written in Nim

License

Notifications You must be signed in to change notification settings

CoffeeeAtNight/Genetic_Algorithm_Maze_Solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🧬 Genetic Algorithm Maze Solver

A simple genetic algorithm project that evolves agents to navigate a 2D maze! 🚀


Overview 🎯

This project implements a genetic algorithm (GA) to evolve agents that can find their way through a maze. The agents start with random movements, and through natural selection, crossover, and mutation, they gradually improve their ability to reach the goal.

Key Features:

  • Genetic Algorithm Core: Includes selection, crossover, and mutation mechanics.
  • Maze Representation: The maze is represented as a 2D grid with walls, paths, and a goal.
  • Real-time Visualization: Watch agents as they evolve in the maze with a simple ASCII representation.
  • Elite Selection: Top-performing agents are selected as the basis for the next generation.

How It Works 🧠

  1. Initialization:

    • Agents are created with a random genome (sequence of moves: up, down, left, right).
    • Agents are placed at the start position in the maze.
  2. Fitness Evaluation:

    • Each agent’s fitness is determined by how close it gets to the goal. The closer, the better the fitness.
  3. Evolution Process:

    • Selection: The top-performing agents (elite agents) are selected to reproduce.
    • Crossover: Two parents’ genomes are combined at a random point to create offspring.
    • Mutation: Some offspring may experience small random changes to their genome to introduce variation.
  4. Next Generation:

    • The new generation replaces the old one, and the process repeats until agents successfully reach the goal or the set number of generations is reached.

Maze Layout 🗺️

The maze is represented as an 8x8 grid:

  • #: Wall
  • A: Agent
  • G: Goal
  • (Blank Space): Path

Todo:

  • Fix problem where generation stops after some time
  • Improve fitness function to prevent local maximum
  • Integrate OpenGL to better represent generations

image

About

Utilizing evolutionary algorithms to mutate agents gens so they are able to find the best possible way through a maze represented as a 2D matrix written in Nim

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages