"Isn't the program supposed to preserve the best creature and so the drop in fitness shouldn't happen because of that?“
Yes, the best creature’s brain will be included without any modifications in the next generation if you have the setting enabled (I’ve also tested and verified this). You’re right, this should theoretically prevent a drastic fitness drop. Maybe this is also related to the behaviour change bug.
"Isn't the simulation deterministic so the same creature with the same brain should always behave exactly the same way?“
The neural network is fully deterministic so yes, the idea is that the same brain should always result in the same behaviour. Apparently though, this doesn’t always happen, for which I have no explanation. The only part of the full code that isn’t deterministic is the mutation and mating logic (the creatures that get picked are based on weighted randomization), but this has nothing to do with the brain during the simulation.
The part that is not under my control is Unity’s physics system, which could have something to do with the issue.
"Maybe the best creature is picked but for some reason some other creature is being displayed?“
The way that the best creatures logic works is the following: At the end of every generation I store the encoded brain (as a string) of the best creature in a list. When a „Best creature“ needs to be displayed (either manually or automatically), I pick the respective encoded brain, instantiate a new copy of the body, decode the brain string (chromosome) into an actual neural network and apply that to the body. (I also verified that the creatures always get the same brain that the best one of the generation had - even when the „Best creature“ doesn’t move, it has the exact same brain as when it used to be moving)
"Also shouldn't the worst creatures be erased from the population and so there shouldn't be such a big gap between the best and worst creature?“
The worst ones don’t get completely erased but they have a very small chance of passing on their genes to the next generation. It can also always happen that you mate two good creatures and then mutate a section of their brain that then renders the whole brain useless and results in a really bad creature.
"You said that the bug doesn't happen often but for me it happens all the time. As you can see in the video the "best of" screen never shows anything other than a creature falling on it's face.“
I mean it doesn’t happen that often in different simulations. Once it happens in a certain simulation then it seems to persist for the rest of that simulation without going back to normal.
"Are you the one who wrote the code behind the neural network or are you using some libraries for that?“
Yes, I wrote the network (and everything else) myself without using any libraries. The whole point of this project to me was to learn the basics of neural networks and evolutionary algorithms and have something to apply that knowledge to and playing around with.
"And one last thing. Is there any chance of you releasing the source code to public?“
I get asked that quite often and I’m actually surprised that nobody just tries to search for it, because you could easily find it in about 20 seconds. The source code is and has always been on my GitHub. https://github.com/keiwando/evolution
The project does not have an open source license, so the regular copyright stuff applies. You can obviously read through the code or play around with it for personal use though.
"Hmm, may it be that the reason for the bug is that, you are reseting physical structure of creature but not it's brain at the start of "the best" simulation? Same reason could be the cause for that fitness drop.“
The brains / neural networks have no state associated with them that would need to be reset. The networks always get encoded into strings (which is just an encoding of the weight matrices), then these strings are used for mutation and reproduction and then the new strings are decoded into networks to be applied to the new set of copies of the body.