# Evolution + Mutation AI tries to escape a maze

Inspired by Boxed in ai.
It creates 5 (or however many you set the slider to) clones, each one with a slightly mutated set of steps. By the end, the clone with the highest distance from the center is kept, and its moveset is mutated among the new generation of clones. (Sorry if that was hard to follow...)
The most successful path from the previous generation is highlighted in green.
The mutation is weighted so that only more recent steps can be changed. This is helpful for preserving the previous path, but can be a pain sometimes when it overwrites its own progress.
As of now I haven't seen it overcome (and commit to) the first turn, but feel free to share anything you find.

After making some tweaks to make the code run faster, the clones make it past the first turn.

You can probably improve the AI a little bit:
Instead of training based on how far from the center it is, add some "food" to the map. Then make the point system work based on how much "food" each clone has "eaten".

Why should you do it this way?

Since the map is drawn loopy, the AI can get confused about whether or not it's making progress.
Let me demonstrate using these images:

The green cross in the middle is the starting point of the maze. The yellow circle is further from the center than the blue circle, right? Yes, but the blue circle is closer to the finish (marked by the checkered part).

See the comparison of the lines below:

Since you are calculating the score based on the distance from the center, your AI will become confused and backtrack, or become stuck. That's because your AI is following a false trail, and won't escape because going toward the finish line makes the AI go closer to the starting point, which it doesn't want.

Giving the AI imaginary "food" eliminates this problem because the "food" (usually) goes to the finish line.

Is a human being going to decide where to put the food? If so, doesn't that defeat the AI-ness? If not, what's the algorithm?

No, it wouldn't defeat the AI-ness because the "food" (checkpoints) would be part of the already human-made map.
To @joecooldoo: That's a good idea, I might work on adding that.

How do you get them to start a specific point, this could be exactly what we need

I’ve tried so much do try and get them to start but they always start at 0,0 no matter what

Even forcing them to stay at a specific cord it doesn’t work

You can now edit the origin position through the "origin" variable.

Yes, I’m trying to make them treverse a map. How would I properly get them to do that, they always just go to the left instead of down (the room above the very bottom one is the goal)