globals [grass]
;; Sheep and wolves are both breeds of turtle.
breed [sheep a-sheep] ;; sheep is its own plural, so we use "a-sheep" as the singular.
breed [wolves wolf]
turtles-own [energy] ;; both wolves and sheep have energy
patches-own [countdown]
to setup
clear-all
ask patches [ set pcolor green ]
;; check GRASS? switch.
;; if it is true, then grass grows and the sheep eat it
;; if it false, then the sheep don't need to eat
if water? [
if grass? [
ask patches [
set pcolor one-of [green brown blue]
if-else pcolor =[green blue]
[ set countdown grass-regrowth-time ]
[ set countdown random grass-regrowth-time ] ;; initialize grass grow clocks randomly for brown patches
]
]
if grass? [
ask patches [
set pcolor one-of [green brown]
if-else pcolor = green
[ set countdown grass-regrowth-time ]
[ set countdown random grass-regrowth-time ] ;; initialize grass grow clocks randomly for brown patches
]
]
]
set-default-shape sheep "sheep"
create-sheep initial-number-sheep ;; create the sheep, then initialize their variables
[
set color white
set size 1.5 ;; easier to see
set label-color blue - 2
set energy random (2 * sheep-gain-from-food)
setxy random-xcor random-ycor
]
set-default-shape wolves "wolf"
create-wolves initial-number-wolves ;; create the wolves, then initialize their variables
[
set color black
set size 2 ;; easier to see
set energy random (2 * wolf-gain-from-food)
setxy random-xcor random-ycor
]
display-labels
set grass count patches with [pcolor = green]
;;set water count patches with [pcolor = blue]
reset-ticks
end
to go
if not any? turtles [ stop ]
ask sheep [
move
if water? [
if pcolor = blue [
set energy energy = 0
death ;;sheep drowns
]
]
if grass? [
set energy energy - 1 ;; deduct energy for sheep only if grass? switch is on
eat-grass
]
death
reproduce-sheep
]
ask wolves [
move
if water? [
if pcolor = blue [
set energy energy = 0
death
]
]
set energy energy - 1 ;; wolves lose energy as they move
catch-sheep
death
reproduce-wolves
]
if grass? [ ask patches [ grow-grass ] ]
set grass count patches with [pcolor = green]
tick
display-labels
end
to move ;; turtle procedure
rt random 50
lt random 50
fd 1
end
to eat-grass ;; sheep procedure
;; sheep eat grass, turn the patch brown
if pcolor = green [
set pcolor brown
set energy energy + sheep-gain-from-food ;; sheep gain energy by eating
]
end
to reproduce-sheep ;; sheep procedure
if random-float 100 < sheep-reproduce [ ;; throw "dice" to see if you will reproduce
set energy (energy / 2) ;; divide energy between parent and offspring
hatch 1 [ rt random-float 360 fd 1 ] ;; hatch an offspring and move it forward 1 step
]
end
to reproduce-wolves ;; wolf procedure
if random-float 100 < wolf-reproduce [ ;; throw "dice" to see if you will reproduce
set energy (energy / 2) ;; divide energy between parent and offspring
hatch 1 [ rt random-float 360 fd 1 ] ;; hatch an offspring and move it forward 1 step
]
end
to catch-sheep ;; wolf procedure
let prey one-of sheep-here ;; grab a random sheep
if prey != nobody ;; did we get one? if so,
[ ask prey [ die ] ;; kill it
set energy energy + wolf-gain-from-food ] ;; get energy from eating
end
to death ;; turtle procedure
;; when energy dips below zero, die
if energy < 0 [ die ]
end
to grow-grass ;; patch procedure
;; countdown on brown patches: if reach 0, grow some grass
if pcolor = brown [
ifelse countdown <= 0
[ set pcolor green
set countdown grass-regrowth-time ]
[ set countdown countdown - 1 ]
]
end
to display-labels
ask turtles [ set label "" ]
if show-energy? [
ask wolves [ set label round energy ]
if grass? [ ask sheep [ set label round energy ] ]
]
end
but when I run this ( you have to place a on off switch for water? in the wolf sheep predation) it runs as if I made no changes at all. Why is this? How can I fix this?
anything related to water was added to the code by me.
You have two if statements inside the first if water? (in setup), and both respond to grass? So you do turn some patches blue, but then you execute the send if and turn all either brown or green.
Whenever you get confused, make smaller procedures. E.g.,
to color-patches
if grass? [
let patch-colors [green brown]
if water? [set patch-colors [green brown blue]]
ask patches [set pcolor one-of patch-colors]
]
end
One other problem, is that you don't want if pcolor = [green blue], which (i) will always be false and (ii) is trying to set a regrowth countdown on water patches.
Related
This question already has an answer here:
How do you go about making a convert probability chance for an agent in netlogo?
(1 answer)
Closed 1 year ago.
currently I'm working on a zombie apocalypse simulation on Netlogo, and I'm almost done except that the convertion function is not working. when the zombies collide with humans the humans they either die or convert the human to a zombie according to the global variable convert_probability. For example, if convert probability is set to 80 the human would have an 80% chance of winning the fight and killing the zombie and the zombie would have a 20% chance of converting the human to a zombie.
Also, zombies and humans are not allowed to pass over the brown patches and the function I wrote for that is change_direction, but had to comment those parts because I run to an error.
I have spent hours but couldnt come up with a solution so I would really appreciate any help;
breed [humans human]
humans-own [ humans_speed]
turtles-own [
infected?
]
patches-own [
block
]
breed [zombies zombie]
zombies-own [ zombies_speed]
globals [
student_id
username
nzomb
%infected
]
to setup_world
clear-all
reset-ticks
set student_id 19009670
ask patches [set pcolor green]
set-default-shape zombies "person"
set-default-shape humans "person"
create-zombies 5 [
set color red
set size 4
set zombies_speed 0.5
setxy random-pxcor random-pycor
]
ask zombies[
move-to one-of patches with [pcolor = green]
]
create-humans 15 [
set color blue
set size 4
set humans_speed 1 + random-float 0.1
setxy random-pxcor random-pycor
]
ask humans[
move-to one-of patches with [pcolor = green]
]
set %infected (count turtles with [color = red ] / 20 ) * 100
set nzomb 0
draw_blocks
end
to draw_blocks
ask patches [
set block false
]
ask n-of 100 patches with [pcolor = green][
set pcolor brown
set block true
]
end
to change_direction
if[block] of patch-ahead 2 = true [
right 180
face one-of patches in-radius 2 with [not block]
]
end
to run_model
if ticks >= 10000 [ stop ]
tick
move-turtles
convert
if not any? humans [stop]
end
to move-turtles
ask humans [move-humans]
ask zombies [move-zombies]
end
to move-humans
ask humans [
if any? zombies in-radius (10 + random 20) [rt 180]
set infected? false
set heading (heading + 45 - (random 90))
forward 1 + random-float 1.1
zombiedeath
convert
;;change_direction
]
end
to move-zombies
ask zombies [
chasehuman
convert
zombiedeath
set %infected (count turtles with [color = red ] / 20 ) * 100
set infected? true
set heading (heading + 45 - (random 90))
forward 0.5
; change-direction
]
end
to chasehuman
if any? humans in-radius 10 [
set heading towards one-of humans in-radius 10]
; change_direction
end
to runaway
face min-one-of zombies [distance myself]
rt 180
;change_direction
end
to convert
ask turtles with [ breed = zombies ]
[
ask humans-on patch-here
[
if random 100 < convert_probability [set breed zombies]]
ask humans-on patch-here [if random 100 < convert_probability
[set color red]]
]
end
to zombiedeath
ask zombies-on patch-here [if random 100 > convert_probability
[die]]
end
Okay, the only procedure relevant to this question is this one (same code as above, formatted so you can see the structure logic}:
to convert
ask turtles with [ breed = zombies ]
[ ask humans-on patch-here
[ if random 100 < convert_probability
[ set breed zombies
]
]
ask humans-on patch-here
[ if random 100 < convert_probability
[ set color red
]
]
]
end
You haven't actually told us what the problem is - "convertion function is not working" does not say whether it is generating an error, or what behaviour it is doing compared to what is expected for example. But, look at what this code actually does. First it finds all the zombies then, for each zombie, it:
gets the humans on the same patch to convert to zombies with some probability
gets the humans on the same patch to change colour to red with some probability
Your first problem is that you haven't linked the turning red with becoming a zombie. Is that the problem you were trying to solve? If so, here is some cleaned up code that links zombie and red:
to convert
ask zombies ; note, you can just directly use the breed name
[ ask humans-here ; again, can use the breed name
[ if random 100 < convert_probability
[ set breed zombies
set color red
]
]
]
end
I am working with the daisyworld model and am planning to add a predator to the model which will eat the daisies (this is for a class project). I have successfully added the predators (brown rabbits eat the white daisies, grey rabbits eat the black daisies). But in order for them to eat the daisies, their coordinates have to line up perfectly causing very little "eating" to occur. Is there a way for me to generate rabbits with random xy cor but be generated in the exact center of the pixel?
globals [
max-age ;; maximum age that all daisies live to
global-temperature ;; the average temperature of the patches in the world
num-blacks ;; the number of black daisies
num-whites ;; the number of white daisies
scenario-phase ;; interval counter used to keep track of what portion of scenario is currently occurring
]
breed [daisies daisy]
breed [brown-rabbits brown-rabbit]
breed [grey-rabbits grey-rabbit]
patches-own [temperature] ;; local temperature at this location
daisies-own [
age ;; age of the daisy
albedo ;; fraction (0-1) of energy absorbed as heat from sunlight
daisy-black ;; boolean if daisy is black
]
brown-rabbits-own
[energy]
grey-rabbits-own
[energy]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Setup Procedures ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup
clear-all
set-default-shape daisies "flower"
ask patches [ set pcolor gray ]
set max-age 25
set global-temperature 0
if (scenario = "ramp-up-ramp-down" ) [ set solar-luminosity 0.8 ]
if (scenario = "low solar luminosity" ) [ set solar-luminosity 0.6 ]
if (scenario = "our solar luminosity" ) [ set solar-luminosity 1.0 ]
if (scenario = "high solar luminosity") [ set solar-luminosity 1.4 ]
seed-blacks-randomly
seed-whites-randomly
ask daisies [set age random max-age]
ask patches [calc-temperature]
set global-temperature (mean [temperature] of patches)
update-display
;reset-ticks
create-grey-rabbits grey-rabbit-number
[
setxy random-xcor random-ycor
set shape "rabbit"
set size 1.5
set color grey
set energy random (2 * grey-rabbit-gain-from-food)
]
create-brown-rabbits brown-rabbit-number
[
setxy random-xcor random-ycor
set shape "rabbit"
set size 1.5
set color brown
set energy random (2 * brown-rabbit-gain-from-food)
]
reset-ticks
end
to seed-blacks-randomly
ask n-of round ((start-%-blacks * count patches) / 100) patches with [not any? daisies-here]
[ sprout-daisies 1 [set-as-black] ]
ask daisies [set daisy-black true]
end
to seed-whites-randomly
ask n-of floor ((start-%-whites * count patches) / 100) patches with [not any? daisies-here]
[ sprout-daisies 1 [set-as-white] ]
ask daisies [set daisy-black false]
end
;to daisy-black
; ifelse color = 0
; [daisy-black true]
; [daisy-black false]
;end
;ask daisies if color = 0 [set daisy-black true]
;ask daisies if color = 9.9 [set daisy-black false]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Runtime Procedures ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go
ask grey-rabbits [
move
set energy energy - 1
eat-black-daisies
death
reproduce-grey-rabbits
]
ask brown-rabbits [
move
set energy energy - 1
eat-white-daisies
death
reproduce-brown-rabbits
]
ask patches [calc-temperature]
diffuse temperature .5
ask daisies [check-survivability]
set global-temperature (mean [temperature] of patches)
update-display
tick
if scenario = "ramp-up-ramp-down" [
if ticks > 200 and ticks <= 400 [
set solar-luminosity precision (solar-luminosity + 0.005) 4
]
if ticks > 600 and ticks <= 850 [
set solar-luminosity precision (solar-luminosity - 0.0025) 4
]
]
if scenario = "low solar luminosity" [ set solar-luminosity 0.6 ]
if scenario = "our solar luminosity" [ set solar-luminosity 1.0 ]
if scenario = "high solar luminosity" [ set solar-luminosity 1.4 ]
end
to move
rt random 20
lt random 20
fd 1
end
to eat-black-daisies ;grey rabbits eat black daisies
ask grey-rabbits
[if any? daisies-here with [daisy-black = true]
[let prey one-of daisies-here; with [daisy-black = true]
if prey != nobody
[ask prey [die]
set energy energy + grey-rabbit-gain-from-food]
]
]
end
to eat-white-daisies ;brown rabbits eat white daisies
; ask brown-rabbits
; ;[if any? daisies-here with [daisy-black = false]
; patch-here
; [let prey one-of daisies-here with [daisy-black = false]
; if prey != nobody
; [ask prey [die]
; set energy energy + brown-rabbit-gain-from-food]
; ]
; ;]
end
to reproduce-grey-rabbits
if random-float 100 < grey-rabbits-reproduce [
set energy (energy / 2)
hatch 1 [rt random-float 360 fd 1]
]
end
to reproduce-brown-rabbits
if random-float 100 < brown-rabbits-reproduce [
set energy (energy / 2)
hatch 1 [rt random-float 360 fd 1]
]
end
to death
if energy < 0 [die]
end
to set-as-black ;; turtle procedure
set color black
set albedo albedo-of-blacks
set age 0
set size 0.6
end
to set-as-white ;; turtle procedure
set color white
set albedo albedo-of-whites
set age 0
set size 0.6
end
to check-survivability ;; turtle procedure
let seed-threshold 0
let not-empty-spaces nobody
let seeding-place nobody
set age (age + 1)
ifelse age < max-age
[
set seed-threshold ((0.1457 * temperature) - (0.0032 * (temperature ^ 2)) - 0.6443)
;; This equation may look complex, but it is just a parabola.
;; This parabola has a peak value of 1 -- the maximum growth factor possible at an optimum
;; temperature of 22.5 degrees C
;; -- and drops to zero at local temperatures of 5 degrees C and 40 degrees C. [the x-intercepts]
;; Thus, growth of new daisies can only occur within this temperature range,
;; with decreasing probability of growth new daisies closer to the x-intercepts of the parabolas
;; remember, however, that this probability calculation is based on the local temperature.
if (random-float 1.0 < seed-threshold) [
set seeding-place one-of neighbors with [not any? daisies-here]
if (seeding-place != nobody)
[
if (color = white)
[
ask seeding-place [sprout-daisies 1 [set-as-white] ]
]
if (color = black)
[
ask seeding-place [sprout-daisies 1 [set-as-black] ]
]
]
]
]
[die]
end
to calc-temperature ;; patch procedure
let absorbed-luminosity 0
let local-heating 0
ifelse not any? daisies-here
[ ;; the percentage of absorbed energy is calculated (1 - albedo-of-surface) and then multiplied by the solar-luminosity
;; to give a scaled absorbed-luminosity.
set absorbed-luminosity ((1 - albedo-of-surface) * solar-luminosity)
]
[
;; the percentage of absorbed energy is calculated (1 - albedo) and then multiplied by the solar-luminosity
;; to give a scaled absorbed-luminosity.
ask one-of daisies-here
[set absorbed-luminosity ((1 - albedo) * solar-luminosity)]
]
;; local-heating is calculated as logarithmic function of solar-luminosity
;; where a absorbed-luminosity of 1 yields a local-heating of 80 degrees C
;; and an absorbed-luminosity of .5 yields a local-heating of approximately 30 C
;; and a absorbed-luminosity of 0.01 yields a local-heating of approximately -273 C
ifelse absorbed-luminosity > 0
[set local-heating 72 * ln absorbed-luminosity + 80]
[set local-heating 80]
set temperature ((temperature + local-heating) / 2)
;; set the temperature at this patch to be the average of the current temperature and the local-heating effect
end
to paint-daisies ;; daisy painting procedure which uses the mouse location draw daisies when the mouse button is down
if mouse-down?
[
ask patch mouse-xcor mouse-ycor [
ifelse not any? daisies-here
[
if paint-daisies-as = "add black"
[sprout-daisies 1 [set-as-black]]
if paint-daisies-as = "add white"
[sprout-daisies 1 [set-as-white]]
]
[
if paint-daisies-as = "remove"
[ask daisies-here [die]]
]
display ;; update view
]
]
end
to update-display
ifelse (show-temp-map? = true)
[ ask patches [set pcolor scale-color red temperature -50 110] ] ;; scale color of patches to the local temperature
[ ask patches [set pcolor grey] ]
ifelse (show-daisies? = true)
[ ask daisies [set hidden? false] ]
[ ask daisies [set hidden? true] ]
end
; Copyright 2006 Uri Wilensky.
; See Info tab for full copyright and license.
Instead of checking whether 2 turtles are exactly on the same spot, I would use patch-here to see if they are on the same patch.
https://ccl.northwestern.edu/netlogo/docs/dictionary.html#patch-here
I am building a model population within a bioreactor, building on a basic tutorial telling how to eat, reproduce, and die, etc. While tinkering, my turtles stopped walking. I suspect it has to do with how to ask the different breeds to do things?
Edit: For some reason my contaminants aren't "wheels" either
turtles-own [ energy ]
patches-own [ nutrition ]
breed [ Xanthomonas Xanthomona ]
breed [ contaminants contaminant ]
globals
[ xanthan biomass ]
to setup
clear-all
setup-patches
set-default-shape Xanthomonas "bug"
set-default-shape contaminants "wheel"
crt num-Xanthomonas
[set color yellow
set energy 10
setxy random-xcor random-ycor
]
foul
determine-biomass
reset-ticks
;; begins defining a procedure named "setup"
;; resets the world to an initial, empty state
;; creates 100 turtles, they start out standing at the origin 0,0
;; set default shape so I don't have to tell it every time
;; A turtle's color variable is random until specified
;; setxy command with next two numbers as inputs
;; chooses random reporters for allowable x and y coordinates
End
to setup-patches
ask patches
[ set pcolor green
set nutrition 50
]
;; every patch starts with 50 nutrition, the color indicates it for us
end
to foul
set-default-shape contaminants "wheel"
if Contamination?
[ crt num-contaminants
[ set color red
setxy random-xcor random-ycor
]
compete ]
end
to go
if ticks >= 2000 [ stop ]
if count turtles > 2000 [stop]
if count turtles = 0 [stop]
feed
move-turtles
ask turtles
[eat-glucose]
ask Xanthomonas
[reproduce]
check-death
tick
end
to determine-biomass
ifelse Contamination?
[set biomass num-Xanthomonas + num-contaminants
]
[set biomass num-Xanthomonas ]
end
to move-turtles
;; says that each turtle should run the commands in the brackets
;; random doesn't include the number you give it as a possible result
;; uses a reporter, each turtle picks a random whole number between 0 and 359
;; makes the turtle move forward one step
;;specify what you're defining will lose 1 energy per step
ask Xanthomonas
[ right random 360
forward 1
set energy energy - 1 ]
end
to Feed
if Continuous-feed?
[ ask patches
[if random 100 < 3
[set pcolor green
set nutrition nutrition + 50
] ] ]
end
to eat-glucose
ask Xanthomonas
[ if pcolor = green
[ set energy energy + 10
set nutrition nutrition - 50
set pcolor gray
set biomass biomass + 1
] ]
ifelse show-energy?
[ set label energy ]
[ set label "" ]
;;ask turtles before "if"
;;if when true, and only then will the turtle run the commands inside the brackets (otherwise it skips them)
;;true/false questions, if true, will do first set of brackets
;;false means turtle runs commands in second set of bracket
;;energy (elements) will default to zero
end
to reproduce
ask Xanthomonas
[ if energy > 50
[set energy energy - 50
set xanthan xanthan + 1
hatch-Xanthomonas 1
[set biomass biomass + 1
rt random-float 360 fd 1
] ] ]
end
to check-death
ask Xanthomonas
[ if energy < 0
[ die ]
]
end
to reinoculate
ask patches [
if random 100 < 10
[ set pcolor green
]
]
end
to Contaminate
crt num-contaminants
[ set color red
setxy random-xcor random-ycor
]
end
to compete
ask contaminants
[ if energy > 50
[set energy energy - 50
set xanthan xanthan + 1
hatch-contaminants 1
[ set color red
set biomass biomass + 1
rt random-float 360 fd 1
] ] ]
end
okay, your basic problem is the crt command. This is short for create-turtles. You have two breeds here and you have defined them. However, when you create the turtles, you are not telling NetLogo which breed to create.
What this means is that you need to make a couple of minor changes to specify the breed. If you look in the dictionary, you will see the command is create-<breed>. Where you have crt num-Xanthomonas, change it to create-Xanthomonas num-Xanthomonas and similarly where you create the contaminants.
breed [ bug bugs ]
breed [ bird birds ]
bird-own [ energy ] ;; birds energy
bug-own [ energy ] ;; bugs energy
to setup
ca
grow-grass
set-default-shape bird "bird"
set-default-shape bug "bug"
create-bird 3 [
set color 37
setxy random-xcor random-ycor
set energy random 10
]
create-bug 20 [
set color green
setxy random-xcor random-ycor
set energy random 10
]
reset-ticks
end
to go
if not any? bugs [crt 2 ]
grow-grass
ask bugs
[ move
eat-grass
reproduce
death ]
ask birds
[ move
eat-bugs
reproduce
death ]
tick
end
to grow-grass
ask patches [
if pcolor = white [
if random-float 1000 < grass-grow-rate
[ set pcolor 57 ]
] ]
end
to move
rt random
lt random
fd 1
set energy energy -0.5
end
to eat-grass
if pcolor = 57
[ set pcolor white
set energy energy + grass-energy ]
end
to eat-bugs
if color = green
[ set pcolor black
set energy energy + ]
end
to reproduce
if energy > birth-threshold
[ set energy energy / 2
hatch 1 [ fd 1 ] ]
end
to death
if energy < 0 [ die ]
end
the birds gain energy when the they eat the bugs and the bugs gain energy when they eat the grass and they use that energy to reproduce. It won't work when i click setup I'm not sure what to do. I need to show the amount of energy they get from eating and the amount they lose from reproducing and moving around
There were several issues with how you defined your breeds. Also, you did not define some variables you use later on. I made some modifications and the basics are now working. Have a look at the energy variables and put in your own values (I made some up as I went). I also changed the eat-bugs proc and now you have birds that do eat the bugs. Finally, I out-commented the shapes of birds and bugs as this is not essential and you can always import them later on. For now, your breeds differ in color only, not shape.
Hope this helped!
breed [ bugs bug ]
breed [ birds bird ]
birds-own [ energy ] ;; birds energy
bugs-own [ energy ] ;; bugs energy
globals [grass-grow-rate
grass-energy ;; you need to define this in the setup and use it in a procedure
birth-threshold]
to setup
ca
grow-grass
;set-default-shape birds "bird"
; set-default-shape bugs "bug"
create-birds 3 [
set color red
setxy random-xcor random-ycor
set energy random 10
]
create-bugs 20 [
set color green
setxy random-xcor random-ycor
set energy random 10
]
reset-ticks
set grass-grow-rate 0.5 ;; put in your values
set birth-threshold 10 ;; ditto
end
to go
if not any? bugs [create-bugs 2 [set color green
setxy random-xcor random-ycor
set energy random 10]]
grow-grass
ask bugs
[ move
eat-grass
reproduce
death ]
ask birds
[ move
eat-bugs
reproduce
death ]
tick
end
to grow-grass
ask patches [
if pcolor = white [
if random-float 1000 < grass-grow-rate
[ set pcolor 57 ]
] ]
end
to move
rt random 100
lt random 80
fd 1
set energy energy - 0.5
end
to eat-grass
if pcolor = 57 ; what if the color is not 57? i.e. if another turtle already visited this patch?
[ set pcolor white
set energy energy + grass-energy ]
end
to eat-bugs
;suggested change for this proc:
if any? bugs
[set energy energy + 1
ask one-of bugs [die]]
;if color = green
;[ set pcolor black
; set energy energy + 1 ]
end
to reproduce
if energy > birth-threshold
[ set energy energy / 2
hatch 1 [ fd 1 ] ]
end
to death
if energy < 0 [ die ]
end
Check out "Wolf Sheep Predation" in "Models Library" -> Biology. Under Tools -> "Turtle Shapes Editor" you might be able to find relevant shapes to replace wolves and sheep.
i am trying to create a predation model in netlogo with foxes and rabbits. foxes eat rabbits and waste (left from people) und rabbits eat grass in a special pleasure ground.
the initial proportion of patches fixed in the setup should be: 65% green patches (grass), 35 % brown patches (eaten grass), 10 % margenta patches (waste from people). they can be distributed randomly.
at the moment it looks like that :
globals [grass waste]
breed [rabbits rabbit]
breed [foxes fox]
turtles-own [energy]
patches-own [countdown]
to setup
clear-all
ask patches [ set pcolor green ]
if grass? [
ask patches [
set pcolor one-of [green brown]
if-else pcolor = green
[ set countdown grass-regrowth-time ]
[ set countdown random grass-regrowth-time ]
]
]
ask patches [ set pcolor magenta ]
if waste? [
ask patches [
set pcolor one-of [ green brown magenta ]
if-else pcolor = [ green brown ]
[ set countdown waste-regeneration-time ]
[ set countdown random waste-regeneration-time ]
]
]
set-default-shape rabbits "rabbit"
create-rabbits initial-number-rabbits
[
set color white
set size 2.2
set label-color gray + 1
set energy random ( 2 * rabbit-gain-from-food)
setxy random-xcor random-ycor
]
set-default-shape foxes "fox"
create-foxes initial-number-foxes
[
set color red
set label-color gray + 1
set size 2.2
set energy random ( fox-gain-from-food )
setxy random-xcor random-ycor
]
display-labels
set grass count patches with [pcolor = green]
set waste count patches with [pcolor = magenta]
reset-ticks
end