|
Now we must fix all the variables and procedures to fit this program. Everywhere "wolves" appears, replace it with "birds" and instead of "sheep" we have "moths." After editing, if you select compile, you get an error message that says you didn't define Move. So, we must define move by writing a routine that will move the birds around. This routine must be outside of the to go routine because it is to be done by the birds. After the end of the to go routine add a to move routine. How will you move the birds? Random heading and random distance might work out alright. Can you write this piece of the program? Remember to give them directions that vary and a distance to travel.
Now, compile. Our next task is to write code so our birds will catch moths. Once again, we can use the code in the Wolf Sheep Predation model. Find the wolf procedureto catch-sheep and cut and paste it into the peppered moth program just after the Move routine you wrote for the birds. Replace references to wolves and sheep with birds and moths. Do the same thing with the routine to reproduce wolves and to death. After you do this, and compile again, the error message will tell you that "grabbed?" is not defined. Look at the Wolf Sheep Predation model to see where to put this definition. This "moths" variable will also have to be set to false during the setup of the moth population. Refer to the Predation model if you have a problem with that.
The model should now run. Is it doing what we wanted? Study the code and see how moths die. Predation is not the only way. They die due to a lack of fitness. That is what predation is supposed to do. There is no advantage given to certain colored moths by our birds even though the fitness formula does provide an advantage. Lets remove the fitness formula and see if we can just use the birds to determine fitness. Delete the slider for selection also.
Now, you need to alter the catch-moths routine so that only moths that are not camouflaged are captured. A simple and statement will cause the birds to inspect the moth to see if it matches the patch it is currently on. The amount of energy provided to the bird by eating the moth may need tinkering. Have the moth count for about 3 energy units. That section of the program should look like this:
|