Child of Child of Helping_vs_Harming
No preview image
Model was written in NetLogo 5.2.0
•
Viewed 156 times
•
Downloaded 14 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
turtles-own [ ;;; internal setting variables social-currency p-theft p-protect age my-life-expectancy ;;; color variables r g b ;;; turn variables take-action my-neighbors ;; reproduction variables can-breed? my-mateworthy-neighbors my-mate ;;; helper variables random-choice-num ;;; every turn a turtle uses random to pick what to do; this is so we can pick one random number per turn in the ifelse block my-count ;; this is just a placeholder variable; not at all necessary for logic but is handy to avoid retyping code bloacks ] to setup ca if protect-threshold <= theft-threshold [ user-message "Oops: the protection threshold must be larger than the theft threshold" stop ] ask patches [ set pcolor grey ] ;;; turtles are initialized black and can end up white, so grey background is best crt number-of-turtles [ ;;; initialize color and location. we are going to do some color math so we have to do this a little hamfistedly set r 0 set g 0 set b 0 set color rgb r g b ;; everyone starts off green, randomly placed in the world, with equal social currency set size 2 setxy random-xcor random-ycor ;; internal variables set can-breed? (social-currency > mate-threshold) set social-currency initial-social-currency set p-theft (theft-threshold - 5 + random 11) ;; everyone has their own theft threshold within 5 of the set threshold set p-protect (protect-threshold - 5 + random 11) ;; ditto protection threshold if p-theft >= p-protect [set p-theft (p-protect - 1)] ;; make sure p-theft < p-protect; this gives preference to protection rather than theft. call me old-fashioned. set age 0 set my-life-expectancy (life-expectancy - 5 + random 11) ] reset-ticks end to go if (count turtles = 0) [stop] ifelse population-cap? ;; terminal conditions: do we stop at a population cap, or after a certain number of ticks? [ if (count turtles > 7500) [stop]] ;;; population cap: 7500 [ if (ticks > 1000) [stop]] ;;; otherwise, max 1000 ticks ;;; these population/tick limits were decided upon basically by seeing where the model starts to slow down enormously and by which point clear trends have emerged. ;;; first code block resets internals, moves the turtles, and picks what to do ask turtles [ ;;; reset some information at each tick set my-mate false ;; reset mate info set color rgb r g b ;;; reset color set can-breed? (social-currency > mate-threshold) ;;; reset breeding status set my-neighbors other turtles in-radius social-radius ;; figure out who your neighbors are ;;; move ifelse any? my-neighbors [ face max-one-of my-neighbors [social-currency]] ;; face your most popular neighbor [ rt random 360 ] ;; or wiggle if you have no neighbors fd 1 ;; take a step towards them ;;; pick an action. Actions will actually happen during the resolution phase ;;; this does NOT have to happen after all the turtles have moved because they are just picking what ;;; they WILL do, they are not actually doing it yet set random-choice-num random 100 ifelse (random-choice-num < p-theft) [ set take-action "steal" ] [ ifelse (random-choice-num < p-protect) ;; if we got here that means p-theft < choice-num < p-protect [ set take-action "do-nothing" ] [ set take-action "protect" ]]] ;;; resolve performs the actions and resolves the consequences ;;; has to happen after all turtles have moved and chosen their actions ask turtles [resolve] ;; within resolve, functions to actually perform actions are called ask turtles [ if (max-social-currency? and (social-currency > 100) ) [ set social-currency 100 ] ;; if we want to cap social-currency if (social-currency <= 0) [ die ] ;; turtles at zero die if (age > my-life-expectancy) [ die ] set age (age + 1) ] ask turtles [ if can-breed? [ reproduce-if-possible ]] ;;; after all actions are resolved, turtles reproduce if they can tick end to resolve ;;; this is only its own function out of convenience; could be in-line with go ifelse (take-action = "steal") [ steal ] [ ifelse (take-action = "protect") [ protect ] [ do-nothing ] ] end to steal ;;; note that steal actually handles MOST of what happens to turtles, i.e., both thieves and protectors ;;; in this implementation, a successful thief takes TOTAL social-gain divided amongst the victims. another possibility would be to have it take a social-gain from EACH victim ifelse not any? my-neighbors with [take-action = "protect"] ;; if no one is watching out for thieves [ set my-count (count my-neighbors) if (my-count > 0) ;; provided you have neighbors [ set social-currency (social-currency + social-gain) ;; get social-gain from chumpy neighbors ask my-neighbors [set social-currency (social-currency - (social-gain / [my-count] of myself))] ];; each neighbor loses social-gain/count neighbors ;;; if you have no neighbors, don't sweat it, just wiggle ] ;;; otherwise,someone is watching out for thieves [ set my-count (count my-neighbors with [take-action = "protect"]) set social-currency (social-currency - social-gain) ;; lose social-gain ask my-neighbors with [take-action = "protect"] [ set social-currency (social-currency + (social-gain / [my-count] of myself))] ;;; protectors don't each get social-gain, since the more protectors you have, the less each protection matters ;;; and deal with the consequences of getting caught rt random 360 fd exile-distance ;;; if you get caught stealing, turn around and walk away ] ifelse (r < 230) ;;; thieves turn redder [ set r (r + 25) ] ;;; originally this was just if they got caught but it's a better visualization tool this way [ set r 255 ] end to protect if not any? my-neighbors with [take-action = "steal"] ;; if no one is trying to steal, you are punished for being nosy [ set my-count (count my-neighbors) if (my-count > 0) [ set social-currency (social-currency - social-gain) ;; lose social-gain ask my-neighbors [set social-currency (social-currency + (social-gain / [my-count] of myself))]] ;;; all your neighbors are smugly satisfied with themselves and each other ] ;;; otherwise, someone has tried to steal ;;; but we don't have to do anything because it is handled by the steal function ;;; protectors turn bluer ifelse (b < 230) ;;; turtles who are protectors turn bluer [ set b (b + 25) ] [ set b 255 ] end to do-nothing ;;; the only thing we need to do within this function is change the color a bit ifelse (g < 230) ;;; show the turtle's guilt by turning it redder [ set g (g + 25) ] [ set g 255 ] end to reproduce-if-possible ;; only called with turtles who can reproduce set my-mateworthy-neighbors my-neighbors with [can-breed? and (my-mate = false)] ;; my-mate is set to false at the beginning of each tick if any? my-mateworthy-neighbors [ set my-mate max-one-of my-mateworthy-neighbors [social-currency] ask my-mate [ set my-mate true ] ;;; I know it's a bit odd to have the my-mate variable be a combination of booleans and agents, but this should still work; the point is to have my-mate bound or not ;; we do it this way so that turtles don't mate twice per turn hatch 1 [ set social-currency initial-social-currency set p-protect ((([p-protect] of myself + [p-protect] of [my-mate] of myself) / 2) - 5 + random 11) ;; average p-protect of parents, plus some randomness set p-theft ((([p-theft] of myself + [p-theft] of [my-mate] of myself) / 2) - 5 + random 11) ;; average p-theft of parents, plus some randomness if p-theft >= p-protect [set p-theft (p-protect - 1)] ;; make sure p-theft < p-protect; this gives preference to protection rather than theft. call me old-fashioned. set age 0 set my-life-expectancy ((([my-life-expectancy] of myself + [my-life-expectancy] of [my-mate] of myself) / 2) - 5 + random 11) ;;; placement and color set r 0 set g 0 set b 0 set color rgb r g b ;; no matter who your parents are, you start off innocent rt random 360 fd (exile-distance / 2) ] ] end ;;; reporters for charts to-report num-turtles-that-can-breed report count turtles with [can-breed?] end to-report number-of-thieving-turtles report count turtles with [r > 250] end to-report number-of-protector-turtles report count turtles with [b > 250] end to-report number-of-placid-turtles report count turtles with [g > 250] end to-report number-of-mixed-turtles report count turtles with [(r > 250) and (b > 250)] end to-report turtles-who-just-stole report count turtles with [take-action = "steal"] end to-report turtles-who-just-protected report count turtles with [take-action = "protect"] end to-report turtles-who-just-did-nothing report count turtles with [take-action = "do-nothing"] end to-report proportion-breeding-turtles ifelse (count turtles with [can-breed?] = 0) [report 0] [report ((count turtles with [can-breed?]) / count turtles)] end to-report proportion-thieving-breeders ifelse (count turtles with [can-breed?] = 0) [report 0] [report ((count turtles with [can-breed? and (take-action = "steal")]) / (count turtles with [can-breed?]))] end to-report proportion-protecting-breeders ifelse (count turtles with [can-breed?] = 0) [report 0] [report ((count turtles with [can-breed? and (take-action = "protect")]) / (count turtles with [can-breed?]))] end to-report proportion-complacent-breeders ifelse (count turtles with [can-breed?] = 0) [report 0] [report ((count turtles with [can-breed? and (take-action = "do-nothing")]) / (count turtles with [can-breed?]))] end
There is only one version of this model, created over 9 years ago by Joe Blass.
Attached files
No files
Parent: Child of Helping_vs_Harming
This model does not have any descendants.