This repository contains a Python implementation of a genetic algorithm to solve a pathfinding problem on a 2D grid. The goal is to navigate from starting points on the grid to maximize a score based on specific rules. This is actually a tool I used to help me play the Muterra Discord Game - it was by no means a winner, but was definitely a time saver and fun project
Mutates a given agent's genome by randomly altering its directions.
Compresses a solution by removing unnecessary moves.
Generates a random agent with a valid path from a random starting point.
Prints the solution in a readable format with the path and score.
Calculates the fitness of a given solution based on the grid rules and path.
Utility functions to handle immutable and mutable data structures for the genetic algorithm.
Generates a random population of agents.
Runs the genetic algorithm for a specified number of generations and population size.
- Python 3.x
- Required libraries:
datetime
,copy
,json
,sys
,random
,os
,base64
,hashlib
-
Clone the repository:
git clone https://github.com/yourusername/genetic-algorithm-pathfinding.git cd genetic-algorithm-pathfinding
-
Run the script:
python pathfinding.py
The script will output the generation number, best fitness score, unique genomes, and the path with its score.
Generation 1000 best: 55.5 | Unique genomes: 1000 [10.123]
[A] N-S-E-W-N-...