Source code and some comments:
I orginally wrote this in Pascal for DOS. I took the code, and turned it into objects. Then I used Java's graphics to show the ant on the board.
An ant doesn't do much; depending upon its state and whether or not it sees food directly in front, it will step forward, turn left or right, or do nothing. The memory of the ant consists of these states or chromosomes. And chromosomes consist of genes which tell the ant what to do and what the next state should be.
The ant walks upon a board where food is placed from top to bottom. Sometimes there are gaps. Note that the ant has no sense of direction.
The problem is to find a "good set" of chromosomes so that the ant will eat as much food as possible. The algorithm works as follows:
By looking at the Java Console, you can see the generations of ants, the parents of each ant, how well it does, and the board and memory for the best ant in each generation. (The applet will run a lot slower though.)
By taking the source and compiling that, Ants.class can run stand alone giving text output similar to what is seen the the Java Console.
Other source creates the
arrow, the
random numbers, and semaphores
to coordinate the input and output (see Dynamic
Hanoi for details.)