# Bug Hunt Scurry

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)

### VERSION

$Id: Bug Hunt Scurry.nlogo 37529 2008-01-03 20:38:02Z craig $

### WHAT IS IT?

A natural selection model that shows the result of two competing forces on natural selection of the speed of prey.

One force is that predators that chase prey, tend to catch slower moving prey more often, thereby selecting for prey that are faster over many generations of offspring.

Another force is that predators who wait for their prey without moving, tend to catch prey that are moving faster more often, thereby selecting for prey that are slower over many generations of offspring.

By also adjusting whether bugs try to avoid the predator and the predictability of their motion, a different one of these competing forces will tend to dominate the selective pressure on the population.

### HOW IT WORKS

You assume the role of a predator amongst a population of bugs. To begin your pursuit of bugs as a predator, press SETUP to create a population of bugs, determined by the six times the NUMBER-BUGS-EACH-SPEED slider. These bugs that are created are randomly distributed around the graphics window. Each of these bugs may have one of six speeds assigned to it, at which it will always travel when the model is running.

When you press GO the bugs begin to move at their designated speeds. As they move around, try to eat as many bugs as fast as you can by clicking on them in the graphics window. Alternatively, you may hold the mouse button down and move the mouse pointer over the bugs in the graphics window.

The six different speeds that a bug might move at are distributed amongst six different sub-populations of the bugs. These speeds are genetically inherited. With each bug you eat, a new bug is randomly chosen from the population to reproduce one offspring. This bug's offspring is an exact duplicate of the parent (in terms of its speed, orientation, and location). The creation of this new offspring keeps the overall number population of the bugs on the screen constant.

Initially there are equal numbers of each sub-population of bug (e.g. ten bugs at each of the 6 speeds). Overtime, however, as you eat bugs, the distribution of the bugs will change as shown in the "frequency of bugs" histogram and the "number of bugs vs. time" graph. In the histogram, you might see the distribution shift to the left (showing that more slow bugs are surviving) or to the right (showing that more fast bugs are surviving). Sometimes one sub-population of a single speed of bug will be exterminated. At this point, no other bugs of this speed can be created in the population.

Bugs will avoid the predator (your mouse pointer in the graphics window) if the DETECTS-PREDATOR-AT slider is greater than zero. Bugs will also diverge from walking in a straight line based on the amount of WANDER-ANGLE specified is greater than zero.

### HOW TO USE IT

NUMBER-BUGS-EACH-SPEED is the number of bugs you start with in each of the six sub-populations. The overall population of bugs is determined by multiplying this value by 6.

WANDER-ANGLE is the amount of possible change in the angle of orientation that each of the bugs might have with each step.

SPEED-FACTOR is an overall speed coefficient to use to speed up or slow down all the bugs, without making their motion jerky. This is an important slider to adjust to compensate for different speed platforms the model might run on.

DETECTS-PREDITOR-AT is the radius that the bugs can detect the mouse pointer (the predator) from. If they can see the mouse pointer, they determine what direction the mouse pointer is in, and they will turn around in the opposite direction.

SPEED-COLOR-MAP settings help you apply color visualization to the speed of the bugs. The "all green" setting does not show a different color for each bug based on its speed". Keeping the color settings switched to something besides "all green" can tend to result in the predator (the user) unconsciously selecting bugs based on color instead of speed.

The "rainbow" setting shows 6 distinct colors for the 6 different speeds a bug might have. These color settings correspond to the plot pen colors in the graphs.

The "blue red" setting shows the lower half of the speeds of the starting population as blue, and the upper half as red.

The "purple shades" setting shows a gradient of dark purple to light purple for slow to fast bug speed.

### THINGS TO NOTICE

This histogram tends to shift right if you assume the role of chasing easy prey.

This histogram tends to shift left if you assume the role of waiting for prey come to you. (The same effect is achieved with moving the mouse around the screen randomly)

### THINGS TO TRY

Different combinations of WANDER-ANGLE and SPEED-FACTOR and DETECTS-PREDITOR-AT often lead to different selective forces dominating the outcome of a model run. For example, a SPEED-FACTOR that is low and a WANDER-ANGLE that is high and DETECTS-PREDITOR-AT of 0, lead to bugs that just twitch in place. In this scenario all of these bugs are equally easy to catch, therefore there is no selective mechanism here for the predator to catch one sub-population of the prey over another.

Try different combinations of WANDER-ANGLE and SPEED-FACTOR and DETECTS-PREDITOR-AT.

### EXTENDING THE MODEL

It would be interesting to model energy gain from consumption of bugs and energy loss from your amount of motion around the screen.

You could add a slider to assign the random chance that a bug that is an offspring inherits a mutation, resulting in a speed that is not the same as its parent.

You could have each bug inherit WANDER-ANGLE as well as speed.

You could have each bug inherit DETECTS-PREDATOR-AT. It is envisioned that this would tend to select for bugs that the maximum value for this. To balance this with a competing selective force, you could have bugs consume grass or seeds to gain energy and consume energy as they move.

A HubNet version of the model with adjustable starting populations of bugs would help show what happens when two or more competitors assume similar vs. different hunting strategies on the same population at the same time.

### RELATED MODELS

See Bug Hunt.

### CREDITS AND REFERENCES

Inspired by EvoDots software:

http://faculty.washington.edu/~herronjc/SoftwareFolder/EvoDots.html

## Comments and Questions

breed [ bugs bug ] breed [ predators predator] breed [ grass a-grass ] breed [ bugs-starting a-bug-starting] patches-own [energy] bugs-own [speed wander-angle detects-predator-within] bugs-starting-own [speed wander-angle detects-predator-within] globals [total-caught total-6-caught total-5-caught total-4-caught total-3-caught total-2-caught total-1-caught time start-time time-last-caught time-this-caught total-frequency-of-catching changed-color-map? old-color-map histogram-interval-size avg-radius-starting avg-wander-starting show-path? ] to setup ca set total-caught 0 set time 0 set start-time 0 set show-path? false set histogram-interval-size 1 set old-color-map speed-color-map set changed-color-map? false ask patches [set pcolor white] create-bugs number-bugs-each-speed [set speed 1 assign-random-attributes] create-bugs number-bugs-each-speed [set speed 2 assign-random-attributes] create-bugs number-bugs-each-speed [set speed 3 assign-random-attributes] create-bugs number-bugs-each-speed [set speed 4 assign-random-attributes] create-bugs number-bugs-each-speed [set speed 5 assign-random-attributes] create-bugs number-bugs-each-speed [set speed 6 assign-random-attributes] ask bugs [ set shape "bug" setxy random 100 random 100 hatch 1 [set breed bugs-starting set hidden? true] ] create-predators 1 [set hidden? true] ask bugs [set-colors] set avg-radius-starting mean [detects-predator-within] of bugs set avg-wander-starting mean [wander-angle] of bugs setup-plots end to assign-random-attributes ifelse random-attribute-start? [ set wander-angle (random 360) set detects-predator-within (random (max-pxcor)) ] [set wander-angle 20 set detects-predator-within max-pxcor ] end to go let bugs-remaining 0 set time (time + 1) check-color-map-change check-caught move-predator move-bugs do-plots show-path set bugs-remaining (count bugs) set changed-color-map? false end to show-path if (show-path? and (time - start-time) < 200) [ask turtle 0 [pendown]] if (show-path? and (time - start-time) >= 200) [ask turtle 0 [penup] set show-path? false] end to move-predator ;; show the hawk shape under the mouse-pointer in the graphics window if predator? is true if (mouse-inside?) [ask predators [setxy mouse-xcor mouse-ycor]] end to move-bugs let predator-agent one-of predators let heading-toward 0 let distance-from-predator nobody ask bugs [ set distance-from-predator distance-nowrap predator-agent ;; if bugs are close enough to the mouse pinter, calculate the heading toward the mouse pointer and set the heading of the bugs to be in the opposite direction if (mouse-inside? and distance-from-predator < detects-predator-within) [ set heading-toward towards predator-agent set heading (-1 * heading-toward)] fd (speed * speed-factor) rt random wander-angle lt random wander-angle ] end to check-caught let speed-of-caught 0 let period-to-catch 0 let snap-mouse-xcor mouse-xcor let snap-mouse-ycor mouse-ycor if mouse-down? and mouse-inside? [ if (any? bugs-on patch snap-mouse-xcor snap-mouse-ycor) [ set total-caught (total-caught + 1) set time-last-caught time-this-caught set time-this-caught time set period-to-catch (time-this-caught - time-last-caught) set total-frequency-of-catching (total-frequency-of-catching + (1 / period-to-catch)) reproduce-one ;; kill only one of the bugs at the mouse location ask one-of bugs-on patch snap-mouse-xcor snap-mouse-ycor [ set speed-of-caught speed if (speed-of-caught = 1) [set total-6-caught (total-6-caught + 1)] if (speed-of-caught = 2) [set total-5-caught (total-5-caught + 1)] if (speed-of-caught = 3) [set total-4-caught (total-4-caught + 1)] if (speed-of-caught = 4) [set total-3-caught (total-3-caught + 1)] if (speed-of-caught = 5) [set total-2-caught (total-2-caught + 1)] if (speed-of-caught = 6) [set total-1-caught (total-1-caught + 1)] die] ] ] end to reproduce-one ask one-of bugs [ hatch 1 [ set heading (random 360) if mutations? [mutate-offspring-attributes] ] ] end to mutate-offspring-attributes if random-attribute-start? [ set wander-angle (wander-angle + (random-float angle-drift)) set detects-predator-within (detects-predator-within + (random-float detects-drift) - 1) if (random 100 < probability-mutation) [set speed (speed + (random (speed-drift + 1) ) ) ] if speed < 1 [set speed 1] if speed > 6 [set speed 6] ] end to check-color-map-change ;; apply color map change only once: when a new value for speed-color-map is selected if (old-color-map != speed-color-map) [ ask bugs [ set old-color-map speed-color-map set changed-color-map? true set-colors ] ] end to do-plots set-current-plot "Avg. radius vs. time" set-current-plot-pen "starting" plotxy time avg-radius-starting set-current-plot-pen "changing" plotxy time mean [detects-predator-within] of bugs set-current-plot "Avg. wander-angle vs. time" set-current-plot-pen "starting" plotxy time avg-wander-starting set-current-plot-pen "changing" plotxy time mean [wander-angle] of bugs set-current-plot "radius distribution" clear-plot if show-starting? [ set-histogram-num-bars 10 set-current-plot-pen "starting" set-plot-pen-interval 1 histogram [detects-predator-within] of bugs-starting ] set-histogram-num-bars 10 set-current-plot-pen "current" set-plot-pen-interval 1 histogram [detects-predator-within] of bugs set-current-plot "wander angle distribution" clear-plot if show-starting? [ set-histogram-num-bars 10 set-current-plot-pen "starting" set-plot-pen-interval 36 histogram [wander-angle] of bugs-starting ] set-histogram-num-bars 10 set-current-plot-pen "current" set-plot-pen-interval 36 histogram [wander-angle] of bugs set-current-plot "bugs caught vs. time" plot-caught set-current-plot "number of bugs vs. time" plot-populations set-current-plot "consumption rate vs. time" if (total-caught > 0) [ plotxy time (total-frequency-of-catching / total-caught)] set-current-plot "frequency of bugs" plot-histograms end to setup-plots set-current-plot "bugs caught vs. time" plotxy time total-caught set-current-plot "frequency of bugs" plot-histograms end to set-colors if (speed-color-map = "all green") [set color green] if (speed-color-map = "blue red") [recolor-twocolor ] if (speed-color-map = "violet shades") [recolor-shade ] if (speed-color-map = "rainbow") [recolor-rainbow ] end to recolor-twocolor ifelse (speed <= 3) [set color blue] [set color red] end to recolor-shade set color (112 + speed ) end to recolor-rainbow if (speed = 6) [set color red] if (speed = 5) [set color orange] if (speed = 4) [set color (yellow - 1)] if (speed = 3) [set color green] if (speed = 2) [set color blue] if (speed = 1) [set color violet] end to plot-histograms set-histogram-num-bars 8 set-current-plot-pen "pen1" set-plot-pen-interval histogram-interval-size histogram [speed] of bugs with [speed = 1] set-histogram-num-bars 8 set-current-plot-pen "pen2" set-plot-pen-interval histogram-interval-size histogram [speed] of bugs with [speed = 2] set-histogram-num-bars 8 set-current-plot-pen "pen3" set-plot-pen-interval histogram-interval-size histogram [speed] of bugs with [speed = 3] set-histogram-num-bars 8 set-current-plot-pen "pen4" set-plot-pen-interval histogram-interval-size histogram [speed] of bugs with [speed = 4] set-histogram-num-bars 8 set-current-plot-pen "pen5" set-plot-pen-interval histogram-interval-size histogram [speed] of bugs with [speed = 5] set-histogram-num-bars 8 set-current-plot-pen "pen6" set-plot-pen-interval histogram-interval-size histogram [speed] of bugs with [speed = 6] end to plot-populations set-current-plot-pen "speed=1" plot (count bugs with [speed = 1]) set-current-plot-pen "speed=2" plot (count bugs with [speed = 2]) set-current-plot-pen "speed=3" plot (count bugs with [speed = 3]) set-current-plot-pen "speed=4" plot (count bugs with [speed = 4]) set-current-plot-pen "speed=5" plot (count bugs with [speed = 5]) set-current-plot-pen "speed=6" plot (count bugs with [speed = 6]) end to plot-caught ;; set-current-plot-pen "total" ;; plotxy time total-caught set-current-plot-pen "speed=1" plotxy time total-1-caught set-current-plot-pen "speed=2" plotxy time total-2-caught set-current-plot-pen "speed=3" plotxy time total-3-caught set-current-plot-pen "speed=4" plotxy time total-4-caught set-current-plot-pen "speed=5" plotxy time total-5-caught set-current-plot-pen "speed=6" plotxy time total-6-caught end

There is only one version of this model, created over 12 years ago by Uri Wilensky.

## Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.