Coral Reef Simulation
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
A coral reef ecosystem simulation
A coral reef ecosystem is a vibrant and highly diverse marine habitat, primarily formed by millions of tiny animals known as coral polyps. These polyps live in colonies and, over centuries of growth, have built complex structures that form the reef itself. Healthy coral ecosystems represent one of the most highly productive and diverse ecosystems on Earth, supporting approximately 25% of marine species while covering only about 0.2 % of the ocean floor. These ecosystems provide crucial benefits to millions of people, including food security, significant economic incomes thanks to recreational uses and fisheries, and coastal protection by dissipating wave energy. However, coral reefs are increasingly threatened. Global stressors such as climate change, especially ocean warming and acidification, pose severe risks to coral health. Additionally, local pressures from land-based pollution, such as agriculture or deforestation, marine pollution, overfishing, and destructive fishing practices like blast fishing, further impact reef resilience. For example, it is estimated that a global temperature increase of 2°C could push coral ecosystems beyond their tipping point, threatening their survival worldwide. In this context, the model presented here aims to simulate the dynamics of a small reef to explore how various threats and imbalances can lead to reef degradation, potentially resulting in ecosystem collapse. It is a simplified, educational toy model designed to illustrate the importance of maintaining a healthy and diverse ecosystem to ensure the long-term sustainability of coral reefs.
HOW IT WORKS
The coral reef ecosystem is represented from an aerial perspective using a 160 x 160 grid of sandy substrate. Coral is depicted as patches within this grid. The model includes five distinct agent types, each representing a typical ecological function within the reef. The parameters, biological processes, and their implementation, are detailed below.
Each agent is implemented with a global energy
parameter, which decreases with time and activities. When an agent’s energy reaches zero, it dies (death
procedure). If a species is completely absent or has been decimated, (i.e. its ecological niche is empty), a new individual might soon be attracted back into the system.
To reflect natural variability, randomization effects are applied at each time step to all relevant parameters. This ensures that every simulation run is unique, allowing users to explore a range of potential reef dynamics and outcomes.
Coral
Biology
Corals are formed by small animals called polyps that build colonies, which collectively create a reef structure. There is a huge diversity in coral species and shapes. Corals grow very slowly, with annual growth rates ranging from about 1 to around 10 cm depending on the species. When a coral die, its skeleton remains and serves as a substrate for other corals to settle on, promoting the growth of the reef structure. Corals reproduce in two main ways: - Sexual reproduction: both male and female corals release their gametes into the water, these gametes meet and fecundation occurs. Then, the resulting larva searches for a suitable place to settle and grow. Each coral colony can produce millions of larvae, but these larvae are typically weak swimmers, heavily predated, and dispersed by ocean currents. As a result, many larvae do not survive, and coral reproduction relies on mass spawning events, often synchronized and triggered by the full moon, to ensure enough larvae find suitable habitats to establish new colonies. - Asexual reproduction: Corals can reproduce asexually through several mechanisms, but this model focuses on fragmentation. When a piece of coral breaks off and lands near the reef, it can grow and form a new colony.
Implementation
At setup, the reef structure is simulated by initializing patches using the setup-coral-blobs
procedure, which arranges patches in an organic, blob-like circular shape. Each patch is assigned an individual growth rate (ind-growth-rate
) and an initial coral size (coral-growth
). The coral patches can have two maturity stages indicated by color: immature (orange) and mature (purple), the latter when the coral size exceeds a threshold fixed to 100 (coral-maturity-size
). Users can adjust parameters via sliders, including the number of blobs (number-of-blobs
), blob radius (blob-radius
), overall reef age (reef-age
), and coral growth rate (coral-growth-rate
). These settings influence reef shape, patch maturity, and growth dynamics. Spatial heterogeneity is introduced to reflect natural variation in coral density and age.
At each tick, coral patches grow via the grow
procedure, which updates coral size based on the patch’s intrinsic growth rate, modulated by a neighbor factor that simulates coral competition. Growth is boosted when neighboring coral is sparse (low competition) and reduced when coral is dense (high competition).
Sexual reproduction is implemented through larvae production by mature patches (hatch-larvae_
), with a user-defined frequency (spawning-frequency
). When spawning occurs, a user-defined number of larvae (Nb-larvae-produced
) is generated. If the Full-moon
option is activated, spawning is synchronized to occur every 150 ticks, with the spawning frequency increased by a factor of 1.8.
Asexual reproduction is implemented as a small probability (0.0005) that a neighboring patch is converted to coral. If the selected patch is already coral (orange or purple), it receives a growth boost. If sand, a new coral is created: its color is set to orange, and its coral-growth
and ind-growth-rate
values are initialized.
Larvae
Biology
As described above, coral larvae are tiny organisms with low swimming abilities and high mortality rates. They drift with water currents until they find a suitable substrate to settle. In natural habitats, settlement rates are generally higher on coral skeletons and lower on bare sand.
Implementation
The number of larvae created at setup is user-defined (Nb-larvae
). Larvae start with a low level of energy (larva-energy
), also adjustable by the user, to mimic their high mortality rate. At each model tick, larvae move one patch forward in a random direction (move-larva
) and lose one point of energy. For each tick, larvae also attempt to settle on the current patch (settle
), with a high probability if the patch is coral (0.05) and a lower probability if it is sand (0.03).
Parrot fishes
Biology
Parrotfishes belong to a family of colorful corallivorous fishes, meaning they feed on living coral, such as the green humphead parrotfish. They have modified teeth that form a beak, like a parrot’s, which they use to nibble the reef. Their feeding activity can cause substantial coral mortality and physically remove pieces of the reef, which are ground into fine sand through digestion and egestion, contributing to important bioerosion. On average, a single parrotfish can produce 250g of sand per day. Despite their destructive feeding habits, parrotfishes play a critical ecological role by preventing the overgrowth of other organisms, such as algae or sponges, which are major competitors for space and resources with corals. By keeping algae and sponges in check, parrotfishes help maintain reef health and promote coral recruitment and recovery.
Implementation
Parrotfishes are implemented as mobile agents in the model. The number of parrotfishes can be set by the user using the Nb-parrotfish
slider, as well as their mean energy level, using the parrotfish-energy
slider.
At each simulation tick, each parrotfish typically moves one patch forward in a random direction, but 10 % of the time, their movement is guided toward nearby coral patches (move-pfishes
procedure). Each movement costs the fish 5 energy points.
When a parrotfish encounters a coral patch (orange or purple) and its energy level is below its maximum energy threshold (pfish-energy-max
, set to 500), it attempts to feed on the coral. This feeding action reduces the coral’s growth size of the target patch, as well as 2 adjacent patches (parrotfishes have a big mouth), by an amount determined by the user-defined parameters energy-gain-from-coral
, simulating the physical removal of coral tissue. A portion of this energy from the coral is transferred to the fish. If a coral patch’s growth size falls below zero, the patch dies and is reset to sand.
When two parrotfishes meet, they have a chance to reproduce, with the probability defined by the user via the pfish-reproduction
slider. When reproduction occurs, each parent’s energy is halved (to account for the cost of reproduction), and a new parrotfish is created with a randomly assigned energy level.
Sharks
Biology
Sharks play a key role in coral reef ecosystems as apex predators. They help regulate the populations of other fish species, preventing overpopulation. By keeping fish populations in balance, sharks indirectly support coral health and help maintain the overall stability of the reef system.
Implementation
When the number of fish reaches or exceeds the ecosystem’s carrying capacity (set by the user using the ecosystem-capacity
slider), a user-defined number of sharks (Nb-sharks
) is attracted to the reef.
Sharks are fast and agile swimmers, making it difficult for prey fish to escape. At each tick, sharks move two patches forward, generally in the direction of the nearest fish (move-shark
procedure). Each movement costs the shark 20 energy points.
When a shark encounters a fish and its energy level is below its maximum threshold (shark-energy-max
, fixed at 1000), the shark has a 50 % chance of successfully eating the fish (eat-fish
procedure). When a fish is eaten, its energy is transferred to the shark, simulating the energy gained from predation.
Sharks do not reproduce in this model.
The Planktivores
option:
Biology
The planktivores option allows the introduction in the model of filter-feeders and planktivores function in the reef. Planktivores and filter-feeders family regroup a large variety of organisms, from whales to fixed organisms such as worms or mollusks. They play a vital role in coral reef ecosystems by capturing and consuming plankton, such as coral larvae, and small organic particles suspended in the water. By filtering the water, they help maintain water clarity, reduce nutrient levels, and control plankton blooms, which can otherwise harm corals by reducing light availability or fostering harmful algae. Additionally, filter feeders and planktivores transfer energy from the planktonic food web to the reef community, supporting higher trophic levels such as larger fish and invertebrates. However, a high concentration of filter-feeders can substantially increase the coral larvae mortality rate.
Implementation
The user can enable the Planktivores
option and select the desired species via the Planktivore-species
chooser. Two species are available: butterflyfishes, representing mobile planktivores, and giant clams, representing fixed planktivores.
Butterflyfishes: These fishes are implemented as mobile agents that primarily feed on coral larvae. The number of butterflyfishes can be set using the Nb-butterflyfishes
slider. For each tick, butterflyfishes move one patch forward, usually in a random direction, but 10% of the time they are attracted by nearby larvae (move-bfishes
). Each movement costs the fish 2 energy points. When a butterflyfish encounters a larva and its energy level is below its maximum threshold (bfish-energy-max
, fixed at 150), it attempts to eat the larva. Upon successful feeding, the fish gains a portion of the larva’s energy.
If two butterflyfishes meet, they have a chance to reproduce, with the probability defined by the user via the bfish-reproduction
slider. During reproduction, each parent’s energy is halved to simulate the cost of reproduction, and a new butterflyfish is created with a randomly assigned energy level.
Giant clams: These are implemented as fixed agents and are generated only in areas where at least four adjacent patches of coral are present. When larvae pass near a giant clam and the clam’s energy level is below its threshold (clam-energy-max
fixed to 100), the giant clam attempts to eat the larvae by filtering the surrounding water (clam-eats-larvae
procedure). Due to the low swimming ability of larvae, they have little chance of escaping. When a larva is eaten, its energy is transferred to the clam.
Clam reproduction is similar to that of coral: they release their gametes into the water, which then meet and form a larva. The larva settles when finding a suitable substrate. Consequently, giant clams do not need to be adjacent to another one to reproduce. Reproduction occurs occasionally, with the frequency controlled by the user using the clam-reproduction
slider, triggering the reproduction-clam
procedure to generate new clams.
The Threats
option
There are a multitude of threats affecting coral reefs, but this model covers only three: global warming, acidification, and dynamite fishing. The user can activate or deactivate each threat.
Global warming
Global warming is represented in the model by a gradual decline in how quickly corals can grow. Every 50 ticks, some coral patches will see their growth rates shrink. This means that even though corals are still alive, they expand more slowly, making it harder for them to build a strong and healthy reef. Over time, this can make the reef more vulnerable to other stresses.
Acidification
Ocean acidification is modeled by reducing the size of coral patches, reflecting how real-world acidification makes it harder for corals to build their skeletons. Every time step, there’s a small chance that each coral patch will get a bit smaller. This steady shrinking means that fewer corals reach maturity and more might die off over time. This weakens the overall structure of the reef.
Dynamite fishing
Dynamite fishing is modeled as a sudden, highly destructive event that wipes out large sections of the reef. When it happens, about half of the coral patches are instantly destroyed and turned into sand, and about 70% of the creatures in the area are killed. The occurrence of the explosion can be set by the user via the time-before-explosion
slider. This simulates the real-world impact of blast fishing, where explosions devastate the reef’s structure and kill a wide range of marine life. Such an event can leave the reef bare and lifeless, making it hard for the ecosystem to recover.
HOW TO USE IT
- Parametrize the model as wanted: select the different wanted option and adjust the sliders
- Press the Setup button
- Press the Go button to begin the simulation. A message will be printed in the Command Center.
- Observe the small reef evolving in front of your eyes.
- Look at the different plots on the left to see the evolution of the different elements of the reef.
The model will stop by itself when reaching 10,000 ticks or when all the coral is dead.
THINGS TO NOTICE
The user can notice how every element of the reef evolves by looking at the three real-time output plots.
THINGS TO TRY
The user can experiment with the various parameters of the reef to observe how the ecosystem responds under different conditions. For example, by adjusting sliders and options, the user can try to find a combination that creates a well-balanced and thriving reef. The user can then compare the healthy reef to one affected by threads, observing how issues like global warming, acidification, or dynamite fishing disrupt the ecosystem. Another interesting experiment is to remove an important ecological function from the reef, such as predation and fish population control, by switching off the presence of sharks. This allows the user to see how the unchecked parrotfish population can negatively affect coral growth and the overall structure of the reef.
Of course, the user can also simply watch the ecosystem unfold, witnessing the interactions of fish, coral, and other creatures. This small simulated world can be surprisingly mesmerizing as life evolves and changes over time.
EXTENDING THE MODEL
Many features and options could be added to make the model more detailed and realistic, capturing additional natural processes. For example, algae are major competitors and threats to coral reefs, as they can outcompete coral for space but do not provide the same ecosystem benefits. Additionally, incorporating fishing pressure would enhance the model’s realism. However, it’s worth noting that adding these processes would increase the model’s computational demands at each tick, potentially slowing down the simulation significantly. Parametrizing the model with real-world data and statistics would further improve its accuracy, helping reflect actual reef dynamics rather than remaining a purely educational tool.
NETLOGO FEATURES
All the model features have been described above.
RELATED MODELS
The eating, reproduction procedures, and predator-prey dynamics take inspiration from the Wolf-sheep predation model (NetLogo Models Library).
ChatGPT was used to help code the organic-like circle shapes of the coral blobs.
CREDITS AND REFERENCES
Model developed by Claire Peyran (2025).
Based on ecological principles of coral reef ecology described in : Souter, D., Planes, S., Wicquart, J., Logan, M., Obura, D., Staub, F. (eds) (2021). Status of coral reefs of the world: 2020 report. Global Coral Reef Monitoring Network (GCRMN) and International Coral Reef Initiative (ICRI). DOI: 10.59387/WOTJ9184.
Comments and Questions
; set up the agents breed [ clams clam ] breed [ pfishes pfish ] breed [ larvae larva ] breed [ butterflyfishes butterflyfish ] breed [ sharks shark ] turtles-own [ energy ] ; all agent will have a parameter energy patches-own [ coral-growth neighbor-factor ind-growth-rate ] globals [ clam-energy-max bfish-energy-max pfish-energy-max shark-energy-max coral-maturity-size dynamite-fishing-event-tick ] to setup clear-all clear-output print "Let's simulate a small reef !" ; globals parameters definition set clam-energy-max 100 set bfish-energy-max 150 set pfish-energy-max 500 set shark-energy-max 1000 set coral-maturity-size 100 set dynamite-fishing-event-tick random time-before-explosion ; environment definition setup-background setup-coral-blobs setup-larvae setup-planktivore setup-pfishes reset-ticks end to go ; stopping conditions: if ticks > 10000 [user-message "10,000 ticks reached" stop] if all? patches [pcolor = 49] [user-message "All the coral is dead, it's the end of the world !"] if (count pfishes + count butterflyfishes) >= ecosystem-capacity and count sharks = 0 [ setup-sharks print "All these fishes have attracted sharks !"] ask larvae [ move-larvae set energy energy - random-float 1 ; at each step, deduct 1 point of energy if random-float 1 < 0.1 [ settle ] death ] ask pfishes [ move-pfishes set energy energy - random 5 ; at each step, deduct 5 points of energy because a fish need more energy to swim if energy <= pfish-energy-max and random-float 1 < 0.3 [ eat-coral ] reproduce-pfish death ] if count pfishes <= 1 [ if random-float 1 < 0.001 [ create-pfishes 1 [ setxy random-xcor random-ycor set shape "parrot fish" set color cyan set size 15 set energy random (parrotfish-energy / 2) + (parrotfish-energy / 2) ] print "A parrot fish has been attracted." ] ] ask sharks [ move-shark set energy energy - 20 if energy <= shark-energy-max and random-float 1 < 0.5 [ eat-fish] death ] ask patches with [pcolor = orange or pcolor = 116 or pcolor = green] [ grow if random-float 1 < 0.0005 [ seed-new-coral self] ; check maturity if coral-growth < 0 [ set coral-growth 0 ] ; cannot be negative if coral-growth > 0 and coral-growth <= 100 [ set pcolor orange ] if coral-growth >= coral-maturity-size [ set pcolor 116 ] ; mature coral turns purple if coral-growth = 0 [ set pcolor 49 set ind-growth-rate 0 ] hatch-larvae_ ] if Planktivores [ ask butterflyfishes[ if energy <= bfish-energy-max and random-float 1 < 0.3 [ butterflyfish-eats-larvae ] move-bfishes set energy energy - ( random 2 ) ; smaller than a parrot fish thus movement costs less energy reproduce-bfish death ] ask clams [ if energy <= clam-energy-max and random-float 1 < 0.8 [ clam-eats-larvae ] set energy energy - (random-float 1 ) reproduce-clam death ] if Planktivore-species = "butterflyfishes" or Planktivore-species = "both" [ if (count butterflyfishes) <= 1 [ if random-float 1 < 0.001 [ create-butterflyfishes 1 [ set shape "butterflyfish" set color green set size 15 set energy random (bfish-energy-max / 2) + (bfish-energy-max / 2) setxy random-xcor random-ycor ] print "A butterflyfish has been attracted." ] ] ] if Planktivore-species = "clams" or Planktivore-species = "both" [ if (count clams) = 0 [ if random-float 1 < 0.001 [ let eligible-patches patches with [ (pcolor = orange or pcolor = 116) and count neighbors with [pcolor = orange or pcolor = 116] >= 4 ] if any? eligible-patches [ ask n-of 1 eligible-patches [ sprout-clams 1 [ set shape "giant clam" set color 107 set size 18 set energy random (clam-energy-max / 2) + (clam-energy-max / 2)]] ] print "A giant clam has just settled." ] ] ] ] ; Define the threats if Global-warming and (ticks mod 50 = 0) [ ; global-warming significantly decrease the growth rate but progressively ask patches with [pcolor = orange or pcolor = 116] [ if random-float 1 < 0.2 [ ; 20% chance per patch every 50 ticks set ind-growth-rate ind-growth-rate * (1 - random-float 0.05 - 0.025) ; cap at a minimum value to prevent collapse if ind-growth-rate < 0.01 [ set ind-growth-rate 0.01 ] ] ] ] if Acidification [ ; acidification significantly decrease the size of coral (make it harder to reach maturity and then die) but progressively ask patches with [pcolor = orange or pcolor = 116] [ if random-float 1 < 0.005 [ set coral-growth coral-growth * (1 - random-float 0.05 )] if coral-growth < 0.01 [ set coral-growth 0] ] ] if Dynamite-fishing and (ticks = dynamite-fishing-event-tick) [ ; Destroy most of the grid ask patches [ if random-float 1 < 0.5 [ ; 50% chance to destroy each patch set pcolor 49 ; sand set coral-growth 0 set ind-growth-rate 0 ] ] ; Kill all agents ask turtles [ if random-float 1 < 0.7 [ die ] ] user-message "Oh no! Your reef has been dynamited!" ; schedule next event set dynamite-fishing-event-tick ticks + round( random (time-before-explosion / 2 ) + (time-before-explosion / 2 ) ) print (word "Next explosion at tick: " dynamite-fishing-event-tick) ] tick end to setup-background ; Set sandy background ask patches [ set pcolor 49] end to setup-coral-blobs repeat number-of-blobs [ let cx random-xcor ;cx and cy for the center of the blob let cy random-ycor ask patches [ let dx_ abs (pxcor - cx) ; dx_ and dy_ are the absolute value from the patch to the center of the current blob let dy_ abs (pycor - cy) let dist sqrt (dx_ * dx_ + dy_ * dy_) ; euclidean distance from the patch to the blob center let noise random-float 1.3 - 0.5 ; add randomness to the distance of the plot to make it more irregular and with a more "organic" shape let dist-fuzzed dist + noise ; apply the noise/randomness to the distance ; to pick an overall round shape let blob-size random (blob-radius / 2) + 2 * (blob-radius / 2) if dist-fuzzed <= blob-size [ let edge-factor 1 - (dist-fuzzed / blob-size) if random-float 1 < (edge-factor ^ 1.2) [ set coral-growth random (reef-age / 2) + (reef-age / 2) ifelse coral-growth = 0 [ set pcolor 49] [ set pcolor orange] set ind-growth-rate random-float (coral-growth-rate / 2) + (coral-growth-rate / 2) if coral-growth >= coral-maturity-size [ set pcolor 116 ] ] ] ] ] end to setup-larvae create-larvae Nb-larvae [ setxy random-xcor random-ycor set color gray set size 3 set energy random ((larva-energy / 2)) + ((larva-energy / 2)) ; when a larvae is created its energy level take a random value between [Larva-energy/2 ; Larva-energy] ] end to setup-pfishes create-pfishes Nb-parrotfishes [ setxy random-xcor random-ycor set shape "parrot fish" set color cyan set size 15 set energy random (parrotfish-energy / 2) + (parrotfish-energy / 2) ] end to setup-planktivore if Planktivores [ if Planktivore-species = "clams" [ let eligible-patches patches with [ (pcolor = orange or pcolor = 116) and count neighbors with [pcolor = orange or pcolor = 116] >= 4 ] if any? eligible-patches [ ask n-of Nb-clams eligible-patches [ sprout-clams 1 [ set shape "giant clam" set color 107 set size 18 set energy random (clam-energy-max / 2) + (clam-energy-max / 2) ] ] ] ] if Planktivore-species = "butterflyfishes" [ create-butterflyfishes Nb-butterflyfishes [ set shape "butterflyfish" set color green set size 15 set energy random (bfish-energy-max / 2) + (bfish-energy-max / 2) setxy random-xcor random-ycor ] ] if Planktivore-species = "both" [ let eligible-patches patches with [ (pcolor = orange or pcolor = 116) and count neighbors with [pcolor = orange or pcolor = 116] >= 4 ] if any? eligible-patches [ ask n-of Nb-clams eligible-patches [ sprout-clams 1 [ set shape "giant clam" set color 107 set size 18 set energy random (clam-energy-max / 2) + (clam-energy-max / 2)] ] ] create-butterflyfishes Nb-butterflyfishes [ set shape "butterflyfish" set color green set size 15 setxy random-xcor random-ycor set energy random (bfish-energy-max / 2) + (bfish-energy-max / 2) ] ] ] end to setup-sharks create-sharks random Nb-sharks [ set shape "shark" set color gray set size 30 set energy random (shark-energy-max / 2) + (shark-energy-max / 2) setxy random-xcor random-ycor ] ; ] end to grow ; make the coral grow and adding a neighbor factor to mimic competition let neighbor-coral count neighbors with [pcolor = orange or pcolor = 116 or pcolor = green] ; calculate neighbor influence with competition set neighbor-factor 1 ; default value if member? neighbor-coral [1 2 3 ] [ set neighbor-factor 1.05] ; when few neighbor the growth is boosted if member? neighbor-coral [4 5 6 7 8] [ set neighbor-factor 0.8 ] ; when too many neighbor, the growth is slow down because of competition ; ensure neighbor-factor stays positive (so growth can't go negative) if neighbor-factor < 0 [ set neighbor-factor 0 ] ; apply growth ifelse ind-growth-rate = 0 [ set coral-growth coral-growth ] [ if ind-growth-rate > 0 [ set coral-growth coral-growth + (ind-growth-rate * neighbor-factor) ] ] end to seed-new-coral [origin] let target-patch one-of neighbors if target-patch != nobody [ ask target-patch [ ; if there is already coral, high chance (50 %) to have a growth boost ifelse pcolor = orange or pcolor = 116 or pcolor = green [ if random-float 1 < 0.5 [ set coral-growth coral-growth + random 5 ] ] [ if pcolor = 49 [ ; low probability (30%) to establish on sand if random-float 1 < 0.3 [ set pcolor orange set coral-growth 0.1 set ind-growth-rate random-float (coral-growth-rate / 2) + (coral-growth-rate / 2) ] ] ] ] ] end to hatch-larvae_ if pcolor = 116 [ ifelse Full-moon [ if ticks mod 150 = 0 and random-float 1 < (spawning-frequency * 1.8) [ sprout random (Nb-larvae-produced / 2) + (Nb-larvae-produced / 2) [ set breed larvae set color grey set size 3 set energy random (larva-energy / 2) + (larva-energy / 2) rt random 360 fd 1 ] ] ] [ if random-float 1 < (spawning-frequency / 100) [ sprout random (Nb-larvae-produced / 2) + (Nb-larvae-produced / 2) [ set breed larvae set color grey set size 3 set energy random (larva-energy / 2) + (larva-energy / 2) rt random 360 fd 1 ] ] ] ] end to move-larvae ; movement right random 360 ; turn a random number of degrees between 1 and 359 forward 1 ; move forward 1 step end to settle ifelse pcolor = orange or pcolor = 116 [ if random-float 1 < 0.05 [ set ind-growth-rate ind-growth-rate + random-float 0.1 set color orange die ; the larvae disappear after settlement ] ] [ if pcolor = 49 [ if random-float 1 < 0.3 [ set pcolor orange set coral-growth 0.01 set ind-growth-rate ind-growth-rate + (random-float (coral-growth-rate / 2) + (coral-growth-rate / 2)) die ] ] ] end to move-pfishes ifelse random-float 1 < 0.1 [ let nearby-coral patches in-radius 50 with [pcolor = orange or pcolor = 116] if any? nearby-coral [ let target min-one-of nearby-coral [distance myself] face target fd 1 ] ; move toward coral ] [ ; random movement rt random 50 lt random 50 fd 1 ] ; move forward 1 step end to move-bfishes ifelse random-float 1 < 0.1 [ let nearby-larvae larvae in-radius 50 if any? nearby-larvae [ let target min-one-of nearby-larvae [distance myself] face target fd 1 ] ; move toward larvae ] [ ; random movement rt random 50 lt random 50 fd 1 ] ; move forward 1 step end to move-shark ifelse random-float 1 < 0.3 [ let nearby-fish turtles in-radius 30 with [ breed = butterflyfishes or breed = pfishes ] if any? nearby-fish [ let target min-one-of nearby-fish[distance myself] face target fd 3 ] ; move toward fish, sharks are fast ] [ ; random movement rt random 50 lt random 50 fd 2 ] ; move forward 2 steps because sharks are fast end to eat-coral if pcolor = orange or pcolor = 116 [ let nearby-coral-fish patches in-radius 3 with [pcolor = orange or pcolor = 116] ; For each nearby coral patch: ask nearby-coral-fish [ ; Fish gains energy from each coral patch ; Coral loses growth set coral-growth coral-growth - (random (energy-gain-from-coral / 2) + (energy-gain-from-coral / 2))] set energy energy + (random (energy-gain-from-coral / 2) + (energy-gain-from-coral / 2)) ] end to clam-eats-larvae let clam-prey larvae in-radius 12 ; Clams eat larvae within radius 12 if any? clam-prey [ ask clam-prey [ die ] set energy energy + (random (larva-energy / 2) + (larva-energy / 2)) ] end to butterflyfish-eats-larvae let bfish-prey larvae in-radius 4 ; Butterflyfish eat larvae within radius 4 because they can move and are fast if any? bfish-prey [ ask bfish-prey [ die ] set energy energy + (random-float (larva-energy / 2) + (larva-energy / 2)) ] end to eat-fish let prey-pool turtles in-radius 3 with [ breed = butterflyfishes or breed = pfishes ] if any? prey-pool [ let prey one-of prey-pool set energy energy + (random ([energy] of prey) / 2 + ([energy] of prey) / 2 ) ask prey [ die ] ] end to reproduce-clam let eligible-patches patches with [ (pcolor = orange or pcolor = 116) and count neighbors with [pcolor = orange or pcolor = 116] >= 4 ] if any? eligible-patches in-radius 90 [ if random-float 100 < (clam-reproduction / 100 ) [ set energy energy / 2 ask one-of eligible-patches [ sprout-clams 1 [ set shape "giant clam" set color 107 set size 18 set energy random (clam-energy-max / 2) + (clam-energy-max / 2) ] ] ] ] end to reproduce-bfish if count butterflyfishes in-radius 30 >= 2 [ if random-float 100 < (bfish-reproduction / 100 ) [ set energy energy / 2 hatch 1 [ set breed butterflyfishes set shape "butterflyfish" set color green set size 15 set energy random (bfish-energy-max / 2) + (bfish-energy-max / 2) rt random 360 fd 1 ] ] ] end to reproduce-pfish if count pfishes in-radius 30 >= 2 [ if random-float 100 < (pfish-reproduction / 100 ) [ set energy energy / 2 hatch 1 [ set breed pfishes set shape "parrot fish" set color cyan set size 15 set energy random (pfish-energy-max / 2) + (pfish-energy-max / 2) rt random 360 fd 1 ] ] ] end to death ; turtle procedure (i.e. all agents will have this propriety). ; when energy dips below zero, die if energy < 0 [ die ] end ;;;;;;;;;;;;;;;;;;;;;;
There is only one version of this model, created 3 months ago by Claire P..
This model does not have any ancestors.
This model does not have any descendants.