-
Notifications
You must be signed in to change notification settings - Fork 0
Genetic Algorithm Tutorial
Although none of the others have been published, this is my 3rd time writing this tutorial. I hope this time I've simplified it as much as possible to present to a general readership (fluent in Java).
This is based on a final project that I did in Computer Science 136 at Williams College in Spring 2013. The main project was to implement a game called Darwin in which virtual creatures, running on a special machine code would battle each other. An example creature would be the Flytrap, which has the following instructions:
ifenemy 4
left
go 1
infect
go 1
.
This reads: "Check if the creature in front of you is an enemy, if so, go to instruction 4, which is infect, and then jump (go) to instruction 1, which starts the loop over. If there is no enemy, rotate left, and jump to instruction 1."
This tutorial is designed to avoid the details of the Darwin Machine Code, we're most concerned about getting a genetic algorithm working, but it is pretty cool. If you want to look at some more examples, they are in the Creatures/ directory. A formidable opponent is Frankenstein.txt built by Alex Wheelock and Donnie (?last name?). It will beat most creatures pretty handily. If you are wondering why it is so huge, it was made by a computerrr.
To run any of these examples, simply cd into Starter and run something like:
java -cp ./structure5.jar Darwin Flytrap.txt Rover.txt Frankenstein.txt
The command line arguments are the file names of the creature descriptions you want to duke it out. You'll then be prompted by a couple questions: the number of creatures of each race present on the field, the number of "rounds" which is really the number of steps executed before a winner is chosen, and whether you want graphics to be shown. The game is much faster without graphics of course.