"You can't use TICK in a turtle context, because TICK is observer-only." - Don't know how to fix that error - netlogo

I'm trying to create an own ecosystem and have already written about 100 lines of code. But I'm currently getting an annoying error message [Title] I cannot get rid of unless I delete the line with the «Tick» command.
That's how the Interface looks like at the moment
That's how the Interface looked like after the latest successful simulation
That's the defective Code:
turtles-own [saturation age gender]
breed [sheep a-sheep]
sheep-own [love-cooldown-sheep-f love-cooldown-sheep-m age%-sheep]
globals [tick-stopper]
patches-own [Next-to]
to setup
clear-all
setup-patches
setup-sheep
set tick-stopper 0
reset-ticks
end
to setup-patches
ask patches [ set pcolor green ]
end
to setup-sheep
create-sheep number_of_sheep [set saturation max-saturation-sheep set gender random 2 set shape "sheep" set age 0]
if setup-sheep-random-age? [
ask turtles with [shape = "sheep"] [set age random life-exp.-sheep]
]
ask turtles with [shape = "sheep"] [
setxy random-xcor random-ycor
if gender = 0 [
set color 118
]
if gender = 1 [
set color 98
]
]
end
to go
if tick-stopper >= stop-at-tick and stop-at-tick? [
set tick-stopper 0
stop
]
move-sheep
sheep-eat-grass
make-love-sheep
check-death-sheep
regrow-grass
set tick-stopper tick-stopper + 1
tick
end
to move-sheep
ask turtles with [shape = "sheep"] [
right random 60
left random 60
forward 1
set saturation saturation - 1
set age age + (((random life-exp.-sheep) + 1) / ((life-exp.-sheep + 1)/ 2))
if gender = 0 and love-cooldown-sheep-f > 0 [
set love-cooldown-sheep-f love-cooldown-sheep-f - 1
set saturation (saturation - (saturation-loss-til-birth-sheep / contribution-period-sheep))
]
]
if gender = 1 [
if love-cooldown-sheep-m > 0 [
set love-cooldown-sheep-m love-cooldown-sheep-m - 1
]
]
end
to sheep-eat-grass
ask turtles with [shape = "sheep"] [
if pcolor = green and saturation < max-saturation-sheep [
set pcolor brown
set saturation saturation + saturation-from-grass
]
ifelse show-saturation?
[ set label saturation ]
[ set label "" ]
]
end
to make-love-sheep
ask turtles with [shape = "sheep"] [
if gender = 0 and love-cooldown-sheep-f = 1 [hatch 1 [set saturation birth-saturation-sheep set gender random 2 set age 0
if gender = 0 [set color 118]
if gender = 1 [set color 98]
if gender = 1 and love-cooldown-sheep-m = 0 and saturation > saturation-for-love-sheep and 1 = count turtles with [shape = "sheep" and gender = 0 and love-cooldown-sheep-f = 0 and saturation > saturation-for-birth-sheep] in-radius 1 [
set saturation saturation - saturation-loss-at-love-sheep
set love-cooldown-sheep-m cooldown-for-love-sheep
ask turtles with [shape = "sheep"] in-radius 1 [
if gender = 0 and saturation > saturation-for-birth-sheep and love-cooldown-sheep-f = 0 [set love-cooldown-sheep-f contribution-period-sheep]
]
]
]
]
]
end
to check-death-sheep
ask turtles with [shape = "sheep"] [
set age%-sheep (100 * (age / life-exp.-sheep))
if saturation <= 0 [die]
if age%-sheep < 22.5039287 [
if (10 ^(0.00984 *(age%-sheep ^ 2) - 0.25918 * age%-sheep + 2.922))/ life-exp.-sheep > random 10000 [die]
]
if age%-sheep > 156.24733 [
if 10000 / (life-exp.-sheep / 100) > random 10000 [die]
]
if age%-sheep > 22.5039287 and age%-sheep < 156.24733 [
if (10 ^(1.899801588 -(((16 / 75 * (age%-sheep ^ 3)) - (50 * (age%-sheep ^ 2))) / 131250)))/ life-exp.-sheep > (random 10000) [die]
]
]
end
to regrow-grass
ask patches with [pcolor = brown] [
set next-to count neighbors4 with [pcolor = green]
if (random 1000000 / 10000) <= (grass-growth% * count neighbors4 with [pcolor = green]) [set pcolor green]
]
end
Thanks for your help <3
This is my first project with NetLogo 6.0.4 and it isn't planned to start any other projects after this one.

You have a bracketing problem in your move-sheep procedure. You have a structure like this:
to move-sheep
ask turtles with [shape = "sheep"]
[ right random 60
...
if gender = 0 and love-cooldown-sheep-f > 0
[
]
]
if gender = 1
[ if love-cooldown-sheep-m > 0
[ set love-cooldown-sheep-m love-cooldown-sheep-m - 1
]
]
end
So you accidentally closed the ask turtles before dealing with the if gender = 1. As soon as you have if gender = 1 then it switches to turtle context.

Related

Netlogo. Update an history list when turtles birth and

I will be very grateful if someone could give me any kind of advice about a problem that I have in my code. I am working on a model with four kind of agents. Each type of agents uses a different strategy. These strategies are Prisoner Dilemma variations. Two of these strategies (tit for tat and unforgiving) need to record (in a list) who was the partner of interaction, and depending if that partner defected or not, will be the behave (cooperative or defect) of the agent in the next encounter with the same partner. Agents move randomly through the world. The problem come when agents die or birth according of their resources level. At this point these strategies that require to record who was the previous partner and how was his behave (cooperative or defect) do not work. This is the message that show up.
I am really appreciate any support!!!!.
number of initial turtles is 42, but two ticks later the number is 52
Below is a code that reproduces the error. In order to run it, it is necessary to create the sliders: n-tit-for-tat-com; n-unforgiving-com; inc-ecological-resources; energy-consume-companies:
globals
[
;;Number of companies with each strategy¨
num-tit-for-tat-com
num-unforgiving-com
;;number of interactions by each strategy
num-tit-for-tat-com-games
num-unforgiving-com-games
;; Total score of all companies playing each strategy
tit-for-tat-com-score
unforgiving-com-score
; Total companies en each ticks
num-companies
]
breed [companies company]
;;create companies variables
companies-own [
score-com
score-com-round
strategy-com
defect-now?-com
partner-defected?-com ;;action of the partner
partnered?-com ;;am I partnered?
partner-com ;;WHO of my partner (nobody if not partnered)
partner-history-com ;;a list containing information about past interactions with other turtles (indexed by WHO values)
earnings-tit-for-tat-Com
earnings-unforgiving-Com
earnings-com
tit-for-tat-com-score-round
unforgiving-com-score-round
]
patches-own
[
resources-amount ;; resources amount in each patches
resources-to ;; aux variable to count resources taken
]
;;;Setup Procedures;;;
to setup
clear-all
setup-patches
setup-companies ;;setup the turtles and distribute them randomly
reset-ticks
end
; Setup patches
;===============
to setup-patches
ask patches [set resources-amount random 4] ;; patches represent ecological system. Resources are distributed randomly. [0,1,2 or 3] 0 -> non resources; 3 -> plenty of resources
ask patches [
set pcolor (ifelse-value
resources-amount = 0 [49]
resources-amount = 1 [58]
resources-amount = 2 [67]
resources-amount = 3 [65]
[63] ;; this case never happen. Because 4 means integer number in range [0 to 3]
)]
end
to setup-companies
make-companies ;;create the appropriate number of turtles playing each strategy
setup-common-variables-com ;;sets the variables that all turtles share
end
;;create the appropriate number of turtles playing each strategy
to make-companies
create-companies n-tit-for-tat-com
[ set strategy-com "tit-for-tat-com"
set color 135
set earnings-tit-for-tat-Com random 4 + 1 ;;randomly initial resources in the range [ 1 - 4 ]. It is sum + 1 to enforce never inicial resource = 0
]
create-companies n-unforgiving-com
[ set strategy-com "unforgiving-com"
set color 4
set earnings-unforgiving-Com random 4 + 1 ;;randomly initial resources in the range [ 1 - 4 ]. It is sum + 1 to enforce never inicial resource = 0
]
end
; Setup common variables
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
;;set the variables that all turtles share
to setup-common-variables-com
ask companies [
set shape "pentagon"
set size 1.3
set tit-for-tat-com-score-round 0
set unforgiving-com-score-round 0
set score-com 0
set partnered?-com false
set partner-com nobody
setxy random-xcor random-ycor
]
end
;;;Runtime Procedures;;;
to go
ask companies [birth-die-com]
store-initial-companies-counts ;;record the number of turtles for each strategy
setup-history-lists-com
clear-last-round
ask companies [ partner-up-com ] ;;have turtles try to find a partner
let partnered-com companies with [ partnered?-com ]
ask partnered-com [ select-strategy-com ] ;;all partnered turtles select action
ask partnered-com [ play-a-round-com ]
adjust-patches
tick
end
;Birth-die-com ; According to the level of resources companies can die or birth
;======================
to birth-die-com
(ifelse
strategy-com = "tit-for-tat-com"
[
set earnings-com earnings-tit-for-tat-com
(if earnings-com > 2 * energy-consume-companies [
hatch 1 [set earnings-tit-for-tat-com random 2 + 1 ] ;;randomly initial resources in the range [ 1 - 2 ]. It is sum + 1 to enforce never inicial resource = 0
set earnings-com (earnings-com - energy-consume-companies )])
( if earnings-com < energy-consume-companies [ die ])
]
strategy-com = "unforgiving-com"
[
set earnings-com earnings-unforgiving-com
(if earnings-com > 2 * energy-consume-companies [
hatch 1 [set earnings-unforgiving-com random 2 + 1 ] ;;randomly initial resources in the range [ 1 - 2 ]. It is sum + 1 to enforce never inicial resource = 0
set earnings-com (earnings-com - energy-consume-companies )])
( if earnings-com < energy-consume-companies [ die ])
]
)
end
;;STORE INITIAL COMPANIES¨
;===========================
;;record the number of turtles at the begining of each tick
;;The number of turtles of each strategy is used when calculating average payoffs.
to store-initial-companies-counts
set num-tit-for-tat-com (count companies with [strategy-com = "tit-for-tat-com"])
set num-unforgiving-com (count companies with [strategy-com = "unforgiving-com"])
end
;Setup-History-Lists-com;; initialize PARTNER-HISTORY list in all turtles
;========================
to setup-history-lists-com
set num-companies (count companies)
let default-history-com [] ;;initialize the DEFAULT-HISTORY variable to be a list
;create a list with NUM-TURTLE elements for storing partner histories
repeat (count companies) [ set default-history-com (fput false default-history-com) ]
;give each turtle a copy of this list for tracking partner histories
ask companies [ set partner-history-com default-history-com ]
end
;Clear-last-round
;================
to clear-last-round
let partnered-com companies with [ partnered?-com ]
ask partnered-com [ release-partners-com ]
end
; release partner between companies and turn around
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
to release-partners-com
set partnered?-com false
set partner-com nobody
rt 180
set label ""
end
;;have turtles try to find a partner
;;Since other turtles that have already executed partner-up may have
;;caused the turtle executing partner-up to be partnered,
;;a check is needed to make sure the calling turtle isn't partnered.
;;partner-up. Find partner
;===========================
to partner-up-com ;;turtle procedure
if (not partnered?-com) [ ;;make sure still not partnered
rt (random-float 90 - random-float 90) fd 1 ;;move around randomly
set partner-com one-of other (companies in-radius 1 ) with [ not partnered?-com ]
if partner-com != nobody [ ;;if successful grabbing a partner, partner up
set partnered?-com true
set heading 270 ;;face partner
ask partner-com [
set partnered?-com true
set partner-com myself
set heading 90
]
]
]
end
;Select stratey company
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
;;choose an action based upon the strategy being played
to select-strategy-com ;;turtle procedure
if strategy-com = "tit-for-tat-com" [ tit-for-tat-com ]
if strategy-com = "unforgiving-com" [ unforgiving-com ]
end
;Play a round-companies
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
to play-a-round-com ;;turtle procedure
get-payoff-com ;;calculate the payoff for this round
update-history-com ;;store the results for next time
end
; get-payoff-com
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
;;calculate the payoff for this round and
;;display a label with that payoff.
;; Strategy-companies
;Turtles l l
;Action l C l D
;__________l________ l__________
; C l 3 l -3
;----------l---------l----------
; D l 5 l -2
to get-payoff-com
set partner-defected?-com [defect-now?-com] of partner-com
ifelse partner-defected?-com [
ifelse defect-now?-com
[ set score-com (score-com + 1 ) set label 1 set score-com-round 1 ]
[set score-com (score-com + 0) set label 0 set score-com-round 0]
]
[ifelse defect-now?-com
[set score-com (score-com + 5) set label 5 set score-com-round 5]
[set score-com (score-com + 3) set label 3 set score-com-round 3]
]
end
;Update-history
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨
;;update PARTNER-HISTORY based upon the strategy being played
to update-history-com
if strategy-com = "tit-for-tat-com" [ tit-for-tat-com-history-update ]
if strategy-com = "unforgiving-com" [ unforgiving-com-history-update ]
end
;;;Strategies;;;
; Tit-for-tat-com
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
to tit-for-tat-com
set num-tit-for-tat-com-games num-tit-for-tat-com-games + 1
set partner-defected?-com item ([who] of partner-com) partner-history-com
ifelse (partner-defected?-com)
[set defect-now?-com true]
[set defect-now?-com false]
ask companies in-radius 1 [
ask patches in-radius 1 [set resources-to (resources-amount * 1)]
ask patches in-radius 1 [set resources-amount (resources-amount - resources-to)]
set tit-for-tat-com-score-round ( tit-for-tat-com-score-round + score-com-round )
set earnings-tit-for-tat-com (earnings-tit-for-tat-Com + ((sum [ resources-to ] of patches in-radius 1)/ 2) + tit-for-tat-com-score-round - energy-consume-companies )
ask patches in-radius 1 [set resources-to 0 ]
set tit-for-tat-com-score-round 0
]
end
;Tit-for-tat-com-history-update¨
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
to tit-for-tat-com-history-update
set partner-history-com
(replace-item ([who] of partner-com) partner-history-com partner-defected?-com)
end
;unforgiving-com ; Works similar to tit-for-tat, but once the another defect, always defect
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
to unforgiving-com
set num-unforgiving-com-games num-unforgiving-com-games + 1
set partner-defected?-com item ([who] of partner-com) partner-history-com
ifelse (partner-defected?-com)
[set defect-now?-com true]
[set defect-now?-com false]
ask companies in-radius 1 [
ask patches in-radius 1 [set resources-to (resources-amount * 1)]
ask patches in-radius 1 [set resources-amount (resources-amount - resources-to)]
set unforgiving-com-score-round ( unforgiving-com-score-round + score-com-round )
set earnings-unforgiving-com (earnings-unforgiving-Com + ((sum [ resources-to ] of patches in-radius 1)/ 2) + unforgiving-com-score-round - energy-consume-companies)
ask patches in-radius 1 [set resources-to 0 ]
set unforgiving-com-score-round 0
]
end
;unforgiving-com-history-update
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
to unforgiving-com-history-update
if partner-defected?-com [
set partner-history-com
(replace-item ([who] of partner-com) partner-history-com partner-defected?-com)
]
end
;; Adjusting Patches
;; Put limits
to adjust-patches
ask patches [ set resources-amount resources-amount + random-float Inc-Ecological-resources ] ;; Resources are renewable. They grow up again between [0-3). Use Slider
ask patches [ ;; Resources range [0-3)
set resources-amount (ifelse-value
resources-amount < 0 [0] ;;
resources-amount > 3 [3] ;;
[resources-amount]
)
]
;; Patches are colored according their level
ask patches [
set pcolor (ifelse-value
resources-amount < 0 [ black ]
resources-amount = 0 [ 38 ]
resources-amount > 0 and resources-amount <= 0.5 [ 49 ]
resources-amount > 0.5 and resources-amount <= 2 [ 67 ]
resources-amount > 2 and resources-amount <= 3 [ 65 ]
resources-amount > 3 and resources-amount <= 4 [ 63 ]
[ white ])
]
end

how to solve "no such plot" error while plotting in netlogo?

I am new to netlogo and facing the following error while plotting the mean of properties associated with patches:
no such plot: " patch 0 0"
error while patch 0 0 running SET-CURRENT-PLOT
called by procedure GO
called by Button 'go'
But patch 0 0 clearly exists and is predefined in the code as follows:
'globals [ k ] ; interaction constant
patches-own [ a b c d' e' ] ; state variables of properties
; a is the Proportion and variety of Blend of land use
; b is the Land uses with supportiveness for complimentary activities
; c is the Vehicular and Pedestrian Intensity
; d is the Intensity of Nodes in urban web
; e' is the Frequency of Enforced Vigilance
to setup
clear-all
set k initial-k
setup-patches
reset-ticks
end
to setup-patches
ask patches [ set pcolor yellow ] ; defines the patches as built up in an area
; to define road patches (horizontal)
ask patches [ if pycor = 0 [ set pcolor grey ] ]
ask patches [ if pxcor = 0 [ set pcolor grey ] ]
ask patches [if pycor = 9 [ set pcolor grey ] ]
ask patches [ if (pycor = 6) and (pxcor < -4 )[ set pcolor grey ] ]
ask patches [ if (pycor = 3) and (pxcor < -4 ) [ set pcolor grey ] ]
ask patches [ if (pycor = 4) and (pxcor > 3 ) [ set pcolor grey ] ]
ask patches [ if (pycor = -6) and (pxcor > 7 ) [ set pcolor grey ] ]
; to define road patches (vertical)
ask patches [ if (pycor > 0) and (pxcor = -10 ) [ set pcolor grey ] ]
ask patches [ if (pycor > 0) and (pxcor = -5 ) [ set pcolor grey ] ]
ask patches [ if (pycor < 0) and (pxcor = -7 ) [ set pcolor grey ] ]
ask patches [ if (pycor < 0) and (pxcor = -3 ) [ set pcolor grey ] ]
ask patches [ if (pycor < -3) and (pxcor = 4 ) [ set pcolor grey ] ]
ask patches [ if (pycor > 3) and (pxcor = 4 ) [ set pcolor grey ] ]
ask patches [ if (pycor > 0) and (pxcor = 7 ) [ set pcolor grey ] ]
; to define nodes as patches
ask patches [ if pxcor = 0 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = 7 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = -3 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = -5 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = -7 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = -10 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = 4 and pycor = 4 [ set pcolor red ] ]
ask patches [ if pxcor = 7 and pycor = 4 [ set pcolor red ] ]
ask patches [ if pxcor = 7 and pycor = 9 [ set pcolor red ] ]
ask patches [ if pxcor = 4 and pycor = 9 [ set pcolor red ] ]
ask patches [ if pxcor = 0 and pycor = 9 [ set pcolor red ] ]
ask patches [ if pxcor = -5 and pycor = 9 [ set pcolor red ] ]
ask patches [ if pxcor = -10 and pycor = 9 [ set pcolor red ] ]
ask patches [ if pxcor = -10 and pycor = 6 [ set pcolor red ] ]
ask patches [ if pxcor = -10 and pycor = 3 [ set pcolor red ] ]
ask patches [ if pxcor = -5 and pycor = 6 [ set pcolor red ] ]
ask patches [ if pxcor = -5 and pycor = 3 [ set pcolor red ] ]
; to set intial values of properties for patches
ask patches with [pcolor = yellow] [ set a random-float 0.9] ; initial a
ask patches with [pcolor = yellow] [ set b random-float 0.9] ; initial b
ask patches with [pcolor = grey] [ set c random-float 0.9] ; initial c
ask patches with [pcolor = red] [ set d' random-float 0.9] ; initial d'
ask patches with [pcolor = grey] [ set e' random-float 0.9] ; initial e'
end
to go
tick
if ticks >= 52 [ stop ]
ask patches with [pcolor = yellow]
[
let fc [c] of one-of patches with [pcolor = grey] ; reports c of any one
grey patch of neighbours
let fe' [e'] of one-of patches with [pcolor = grey] ; reports e' of any one grey patch of neighbours
let fd' [d'] of one-of patches with [pcolor = red] ; reports d' of any one red patch of neighbours
if a < 0.1 [ set a 0.1
if a > 0.9 [ set a 0.9 ] ]
if b < 0.9 [ set b b + (k * a) + (k * fc) + (k * fd')
if b > 0.9 [ set b 0.9 ] ]
if b > 0.1 [ set b b - (k * fe')
if b < 0.1 [ set b 0.1 ] ]
]
ask patch 0 0
[ let fa [a] of one-of patches with [pcolor = yellow]
let fb [b] of one-of patches with [pcolor = yellow]
let fc [c] of one-of patches with [pcolor = grey]
let fe' [e'] of one-of patches with [pcolor = grey]
let eeep (fa + fb + fc + d' + 1 / fe') / 5
let deep (1 / fa + 1 / fb + 1 / fc + 1 / d' + fe') / 5
output-print eeep
output-print deep
set-current-plot " patch 0 0"
set-current-plot-pen "eeep"
plot eeep
set-current-plot-pen "deep"
plot deep
]
end'
I have been trying to solve this for quite sometime and will be grateful for any help.
Thank you!
The patch named patch 0 0 exists. However, that does not mean that the plot named " patch 0 0" exists. You have simply mistyped the name of the plot (perhaps you have the incorrect number of spaces).
I suggest you rename your plot to something that doesn't look like a patch identifier to reduce confusion. Try something like "plot-0-0", renaming both on the interface in the plot dialogue, and also in the code.

Color progression issue in netlogo

I have three different turtles: red, white, and green. I am trying to get these turtles to couple up (like people in relationships) and then uncouple. While a red turtle is coupled with a green or white turtle I want the patch color to sometimes randomly change colors, but for some reason the patch color color progression is not working.
to go
ask turtles
[ if coupled? = true
[ set couple-length couple-length + 1 ] ]
ask turtles
[ if coupled? = false
[ move ] ]
ask turtles
[ if coupled? = false and shape = "person righty" and (random-float 10.0 < coupling-tendency)
[ couple ]
let potential-intervener one-of (turtles-on neighbors) with [ green-dotter? = true]
if (coupled? = true and potential-intervener != nobody and "person righty" = true)
[ifelse (random-float 10.0 < resting-tendency)
[;;decides to stay
ask potential-intervener [move-to patch-here] ;; this is possibly what is causing the lack of intervention?
; does not intervene, start the color progression
ifelse (random-float 10.0 < intervening-tendency)
[;; intervenes
uncouple
]
[set couple-length couple-length + 1 ;; increments the couple length by 1
if (couple-length = 2)
[
ask patch-here [set pcolor yellow]
ask patch-at -1 0 [set pcolor yellow] ]
if (couple-length = 4)
[
ask patch-here [set pcolor orange]
ask (patch-at -1 0) [set pcolor orange] ]
if (couple-length = 6)
[
ask patch-here [set pcolor red]
ask (patch-at -1 0) [set pcolor red] ] ]
]
[
;;decides to move
ask potential-intervener [move]
set couple-length couple-length + 1 ;; increments the couple length by 1
if (couple-length = 2)
[
ask patch-here [set pcolor yellow]
ask patch-at -1 0 [set pcolor yellow] ]
if (couple-length = 4)
[
ask patch-here [set pcolor orange]
ask (patch-at -1 0) [set pcolor orange] ]
if (couple-length = 6)
[
ask patch-here [set pcolor red]
ask (patch-at -1 0) [set pcolor red] ] ]
]
; will green dotter intervene?
ifelse (random-float 10.0 < intervening-tendency)
[;; intervenes
uncouple
]
[;; does not intervene, start the color progression
set couple-length couple-length + 1 ;; increments the couple length by 1
if (couple-length = 2)
[
ask patch-here [set pcolor yellow]
ask patch-at -1 0 [set pcolor yellow] ]
if (couple-length = 4)
[
ask patch-here [set pcolor orange]
ask (patch-at -1 0) [set pcolor orange] ]
if (couple-length = 6)
[
ask patch-here [set pcolor red]
ask (patch-at -1 0) [set pcolor red] ] ]
]
check-sliders
tick
end
For one thing, your line if (coupled? = true and potential-intervener != nobody and "person righty" = true) is inside a command block that is only reached through if coupled? = false and shape = "person righty" and (random-float 10.0 < coupling-tendency). That is, it doesn't get reached because coupled? would need to be both true and false. Better formatting would make this immediately clear. I have reformatted the top part of your code so you can see this:
to go
ask turtles
[ ifelse coupled?
[ set couple-length couple-length + 1 ] ]
[ move
if shape = "person righty" and (random-float 10.0 < coupling-tendency)
[ couple ]
let potential-intervener one-of (turtles-on neighbors) with [ green-dotter?]
if (coupled? and potential-intervener != nobody and "person righty")
[ ifelse (random-float 10.0 < resting-tendency)
[;;decides to stay
ask potential-intervener [move-to patch-here]
A couple of other notes. You don't need to say if coupled? = true, it is sufficient to say if coupled?. Since you have the same colouring code three times, it would be better to have it only once as a separate procedure and call it from the three locations, so it is much easier to change.

Netlogo Sprouting turtles at regular intervals

I want to place turtles on each of the black patches(below Figure) at a specified step size:
Therefore if step size less more turtles will be created/sprouted and more step size will result in less turtles.
Code I use right now:
ask patches with [pcolor = black][sprout-dead-turtles wall-agents [set color red]]
This gives the following result:
Previous question asked on same lines:Netlogo Sprouting turtles spaced at less than one patch
Here:
to fill-wall [ d ]
set d precision d 1 ; make sure d is a multiple of 0.1
let n precision (d / 0.1) 0 ; interval at which to hatch
ask one-of possible-next-patches [
sprout 1 [
hatch 1
let i 0
let next-patch my-next-patch
while [ next-patch != nobody ] [
face next-patch
while [ patch-ahead 0.55 != nobody and [ pcolor ] of patch-ahead 0.55 = black ] [
fd 0.1
setxy precision xcor 1 precision ycor 1 ; avoid floating point imprecisions
set i i + 1
if i mod n = 0 [ hatch 1 ]
]
set next-patch my-next-patch
]
die
]
]
end
to-report possible-next-patches
let empty-black-patches patches with [ pcolor = black and not any? turtles-here ]
report empty-black-patches with [
count neighbors4 with [ member? self empty-black-patches ] = 1
]
end
to-report my-next-patch
report one-of possible-next-patches with [ member? self [ neighbors4 ] of myself ]
end
Here is how you would use it:
to setup
ca
; draw the background:
ask patches with [ abs pxcor != max-pxcor and abs pycor != max-pycor ] [ set pcolor grey ]
ask patches with [ pycor = max-pycor and abs pxcor <= 1 ] [ set pcolor white ]
set-default-shape turtles "circle 2"
fill-wall 0.3
end
Constraints:
d has to be a multiple of 0.1
world wrapping needs to be turned off

How can I include the effect of patches age in netlogo?

How can I accomplish the following in the code below:
patches change color reflective of their distance from the row "min-pycor"
For example, colors alternate from yellow to red and then to black (signifying death).
But this should take into account that the production of yellow patches > red > black.
turtles-own
[
stem? ;; true for stem cells, false for transitory cells
age ;; age of cell. changes color with age
metastatic? ;; false for progeny of stem cell 0, true for progeny of stem cell 1
]
globals
[
cell-count
]
to setup
clear-all
set-default-shape turtles "square"
ask patches[
if pycor = min-pycor [
ifelse random 10 <= 2
[set pcolor white]
[sprout 1 [set shape "square" set color blue] ]
]
]
evaluate-params
reset-ticks
end
to go
ask patches with [pcolor = yellow]
[if count neighbors with [pcolor = black] > 0
[ask one-of neighbors with [pcolor = black][set pcolor yellow]
]
]
ask patches with [pcolor = white]
[if count neighbors with [pcolor = black] > 0
[ask one-of neighbors with [pcolor = black][set pcolor yellow]
]
]
tick
end
;;transitional cells move and hatch more. Turtle proc.
to move-transitional-cells
if (not stem?)
[
set color ( red + 0.25 * age )
fd 1
if (age < 6)
[
hatch 1
[ ;amplification
rt random-float 360
fd 1
]
]
]
end
to mitosis ;; turtle proc. - stem cells only
if stem?
[
hatch 1
[
fd 1
set color red
set stem? false
ifelse (who = 1)
[ set age 16 ]
[ set age 0 ]
]
]
end
to death ;; turtle proc.
if (not stem?) and (not metastatic?) and (age > 20)
[ die ]
if (not stem?) and metastatic? and (age > 4)
[ die ]
end
to evaluate-params
set cell-count count turtles ;cell count
if (cell-count <= 0)
[ stop ]
end
to kill-original-stem-cell
ask turtle 0
[ die ]
end
to kill-moving-stem-cell
ask turtle 1
[ die ]
end
to kill-transitory-cells
ask turtles with [ age < 10 and not stem? ]
[ die ]
end
You seem to have two conflicting requirements, the color change based on proximity in your code, and the color change based on PYCOR that you ask about.
Ignoring the code for a moment, we can set color based on PYCOR in many ways. For example, we can create bands of color, we can create dithered interminglings of color, or we can create a "smooth" transition between colors.
The first is easy. We can use an IFELSE structure. This example creates even bands, but you can change the "divide" variables to create bands of any height.
let color1 red
let color2 yellow
let color3 black
let divide1 (min-pycor + world-height * 0.33)
let divide2 (min-pycor + world-height * 0.66)
ask patches
[ ifelse pycor < divide1 [ set pcolor color1 ][
ifelse pycor < divide2 [ set pcolor color2 ][
set pcolor color3
]]
]
We can also do it in a mathy way. This example creates even bands.
let colors [ red yellow black ]
let bands length colors
let band-height floor ( world-height / bands + .5 )
;; pycor - min-pycor shifts the range from 0 to world-height
ask patches [ set pcolor item ( floor ( ( pycor - min-pycor ) / band-height ) ) colors ]
We can create dithered bands by introducing a random element to the pycor. we also have to add some tests to keep the random numbers in range.
let colors [ red yellow black ]
let bands length colors
let band-height floor (world-height / bands + .5)
let dither band-height * .5 ;; adjust this to change dithery-ness
ask patches
[ let py pycor - min-pycor + dither - random-float ( dither * 2 )
;; you might want to really study the above line to fully grok what's happening there
if py < 0 [ set py 0 ]
if py > world-height [ set py world-height ]
set pcolor item ( floor ( py / band-height ) ) colors
]
Graduated (gradiant) bands are tougher, because the NetLogo color space doesn't do gradual shifts in hue, only tint and shade, so there's really no way to get from red to yellow that way. So we would have to use RGB (three value list)colors, instead of NetLogo (single value) colors. And that's beyond what I'm willing to type out at the moment, so there you go--left as an exersize.