t i m - w o o d . n e t
Genetic Pathfinding Algorithm

The goal is to get from the black square on the left to the one on the right avoiding the blue squares. Sure that sounds easy, but how can you make a computer learn to get there within a certain number of steps? One solution is to use genetic algorithms.

This works by producing a random sequence of genes. The combination of these control each step that the computer moves, up, down, left or right. If you create a population with different series of these genes, combine them in such a way that the ones who are closest to the goal are more likely to mate, and throw in a little random mutation, eventually it will reach the finish!

Certainly not the most practical way to solve the problem, but still interesting to watch. The display shows the member of each generation that got closest to the end and then proceeds to the next generation.

Source code
Built with Processing

 

t i m - w o o d . n e t