--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/58040dd8-3562-4d32-95a2-9c1967bfecfan%40googlegroups.com.
to abandon-cacao
ask highlanders with [ cacao-grower = true ] [
let owner-id who
if cacao-profit < 1 [set cacao-grower falseset color redask patches with [ owner = owner-id ] [recolor-patchset owner 999999]]]end
Who always returns a number.Self always returns an agent (an object, never a number).An agent can never be equal to a number....Another issue is that the code stores a WHO number in OWNER. That's a bad practice.It's almost always a code smell [I think he meant something to the effect of "bad practice"?] to use who numbers, except maybe for setting color.
to abandon-cacao
ask highlanders with [ cacao-grower = true ] [
;; let owner-id who
if cacao-profit < 1 [set cacao-grower falseset color red
ask patches with [ owner = self ] [
recolor-patchset owner 999999]]]end
to market-actions;; new cacao growers are picked, randomly but inversely proportional to the weight given by their distance from the market. The number of them per tick determined by slider.ask markets [let max-dist distance max-one-of patches [distance myself];show word "max distance to market is " max-distif any? highlanders with [ cacao-grower = false ] [ ask highlanders with [ cacao-grower = false ] [ ; "if any?" was needed b/c an error occurred if all were cacao-growerslet my-distance distance (one-of markets) + .001 ; to avoid division by zero problem when "my-distance / max-distance = 0";show word "my distance to market is " my-distanceset percent-max-distance 1 / (my-distance / max-dist) ; actually the reciprocal so it works with rnd:weighted-one-of, below;show percent-max-distance]while [ new-cacao-growers > count highlanders with [ cacao-grower = false ] ] ; decrement slider if there's not enough potential new cacao-growers to run commands[ set new-cacao-growers new-cacao-growers - 1 ]let new-grower rnd:weighted-n-of new-cacao-growers highlanders with [ cacao-grower = false ] [ percent-max-distance ]ask new-grower [if any? patches with [cacao-crop = false and max-resource-here >= 1] [set color blueset cacao-grower truelet radius-new-cfarm 5 ; try to move to non-cacao patch within radius 5, otherwise increment that radius until suitable patches are found; show word "number of non-cacao patches in radius 5 is " count patches in-radius radius-new-cfarm with [cacao-crop = false]while [1 > count patches in-radius radius-new-cfarm with [cacao-crop = false and max-resource-here >= 1] ] [ set radius-new-cfarm radius-new-cfarm + 1 ]; show word "number of non-cacao patches in radius 5 is " count patches in-radius radius-new-cfarm with [cacao-crop = false]move-to one-of patches in-radius radius-new-cfarm with [cacao-crop = false and max-resource-here >= 1] ; move to random non-cacao-crop patch within 5 (arbitrary, for starters) patches away, if possible, incrementing further out if necessary.];; thought this would be obsolete with "set owner self" below (as per Steiner suggestion?) instead of "set owner owner-number", but I get weird behavior I don't understand?; let owner-number who ; create variable out of who number (turtle ID);let neighbor-patches-to-cacao extra-cacao-patches ; equivalent to that set in slider, to be decremented here if necessary. Decrement the EQUIVALENT OF slider (so slider is NOT changed for every case)while [ neighbor-patches-to-cacao > count neighbors with [cacao-crop = false and max-resource-here >= 1] ] ; decrement if there's not enough potential new patches to turn into cacao crops[ set neighbor-patches-to-cacao neighbor-patches-to-cacao - 1 ];; slider "extra-cacao-patches" determines number of extra neighboring patches made into cacao farmsask n-of neighbor-patches-to-cacao neighbors with [cacao-crop = false and max-resource-here >= 1] [ ; turn neighbor-patches-to-cacao neighboring patches, and patch-here (below) cacao-crop variable to "true" and mark who owns them.set cacao-crop trueset owner self]ask patch-here [set cacao-crop trueset owner self]]]]end
You received this message because you are subscribed to a topic in the Google Groups "netlogo-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/netlogo-users/Z5Ff7l2k8fI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/CACv-4rDBuHZdhwMgvUcuZUSCzwS3hp8v7dQcs7wt%3DKnu2aVt6w%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/18ccf9ae-8a7b-4072-b501-93dcf55f4da2n%40googlegroups.com.
;; cacao-growers move among their private patches, accumulate more according to wealth and accumulators-per-tick sliderto cacao-grower-actionsif max-wealth > 0 [ ; just to prevent division by zero error.let percent-wealth (wealth / max-wealth) ; percent of max wealth; show word "my percent of max wealth is" percent-wealthlet accumulator rnd:weighted-n-of accumulators-per-tick highlanders with [ cacao-grower = true ] [ percent-wealth ]
if any? patches with [cacao-crop = false and max-resource-here >= 1] [
let radius-new-cfarm 5 ; try to accumulate non-cacao patch within radius 5, otherwise we'll increment until suitable patches are found; show word "number of non-cacao patches in radius 5, BEFORE while loop, is " count patches in-radius radius-new-cfarm with [cacao-crop = false]
while [1 > count patches in-radius radius-new-cfarm with [cacao-crop = false and max-resource-here >= 1] ] [ set radius-new-cfarm radius-new-cfarm + 1 ]
; show word "number of non-cacao patches in radius 5, AFTER while loop, is " count patches in-radius radius-new-cfarm with [cacao-crop = false]
move-to one-of patches in-radius radius-new-cfarm with [cacao-crop = false and max-resource-here >= 1]
]if any? neighbors with [cacao-crop = false and max-resource-here >= 1] [let extra-cacao-patches-temp extra-cacao-patches ; setting up a temporary substitute for extra-cacao-patches b/c don't want to permanently change slider just b/c the number is too much for one instance.while [extra-cacao-patches-temp > count neighbors with [cacao-crop = false and max-resource-here >= 1] ] [ set extra-cacao-patches-temp extra-cacao-patches-temp - 1 ]
;; slider "extra-cacao-patches" determines number of extra neighboring patches made into cacao farms
ask n-of extra-cacao-patches-temp neighbors with [cacao-crop = false and max-resource-here >= 1] [set cacao-crop trueset owner myselfshow word "My owner is " owner
]ask patch-here [set cacao-crop true
set owner myselfshow word "My owner is " owner]]]
ask highlanders with [ cacao-grower = true ] [
if any? other patches with [ owner = myself ] [ move-to one-of patches with [ owner = myself ]] ; not quite what I want but close. …I don’t want it to be random, ideally.; It should move to the other patch if there are two, as now, and when I make for accumulation of patches, I’ll want it to go through the list of them, or ideally move to the one with the highest resource? (As with "To turn-towards-resource"); Tried to change this:; if any? other patches with [ owner = owner-number ] [ move-to one-of patches with [ owner = owner-number ] and max resource-here ]; or:; if any? other patches with [ owner = owner-number ] [ move-to one-of patches with [ owner = owner-number ] and max [ resource-here ] ]]set cacao-crops count patches with [ owner = myself ] ;; cacao-crops variable defined by number of patches owned for cacao growing ;; 6-30-22, if I did this right, "self" should work;; changed to myself. Confusing!show word "my number of cacao-crops is " cacao-cropsset owned-patches [self] of patches with [owner = myself] ; makes a list of patches owned by each cacao grower, for debugging. Actually converts the agentset into a list.show word "my owned patches are " owned-patches; abandon-cacaoend
ask highlanders with [ cacao-grower = true ] [ cacao-grower-actions]
to cacao-grower-actionsif max-wealth > 0 [ ; just to prevent division by zero error.let percent-wealth (wealth / max-wealth) ; percent of max wealth; show word "my percent of max wealth is" percent-wealth
let accumulators rnd:weighted-n-of accumulators-per-tick highlanders with [ cacao-grower = true ] [ percent-wealth ]ask accumulators [show word "accumulator code test1: I am an accumulator " self
if any? patches with [cacao-crop = false and max-resource-here >= 1] [let radius-new-cfarm 5 ; try to accumulate non-cacao patch within radius 5, otherwise we'll increment until suitable patches are found; show word "number of non-cacao patches in radius 5, BEFORE while loop, is " count patches in-radius radius-new-cfarm with [cacao-crop = false]while [1 > count patches in-radius radius-new-cfarm with [cacao-crop = false and max-resource-here >= 1] ] [ set radius-new-cfarm radius-new-cfarm + 1 ]; show word "number of non-cacao patches in radius 5, AFTER while loop, is " count patches in-radius radius-new-cfarm with [cacao-crop = false]move-to one-of patches in-radius radius-new-cfarm with [cacao-crop = false and max-resource-here >= 1]]if any? neighbors with [cacao-crop = false and max-resource-here >= 1] [let extra-cacao-patches-temp extra-cacao-patches ; setting up a temporary substitute for extra-cacao-patches b/c don't want to permanently change slider just b/c the number is too much for one instance.while [extra-cacao-patches-temp > count neighbors with [cacao-crop = false and max-resource-here >= 1] ] [ set extra-cacao-patches-temp extra-cacao-patches-temp - 1 ];; slider "extra-cacao-patches" determines number of extra neighboring patches made into cacao farmsask n-of extra-cacao-patches-temp neighbors with [cacao-crop = false and max-resource-here >= 1] [set cacao-crop trueset owner myself
show word "accumulator code test2: My owner is " owner
]ask patch-here [set cacao-crop trueset owner myself
show word "accumulator code test3: My owner is " owner]]show word "accumulator code test4: my number of ownened patches is " patches with [owner = self]
]]set cacao-crops count patches with [ owner = myself ] ;; cacao-crops variable defined by number of patches owned for cacao growing
show word "cacao-grower-actions test: my number of cacao-crops is " cacao-crops ; interesting, so this is something all highlanders with [cacao-grower = true] will print out.
ask patches with [ owner = myself ] [
set pcolor brown ;; color cacao-crops owned brown ;; change this so each grower has patches owned a unique color? Complicated, tho. See http://ccl.northwestern.edu/netlogo/docs/programming.html#colors, and alt method of James Steiner (email).]
if any? other patches with [ owner = myself ] [ move-to one-of patches with [ owner = myself ]] ; not quite what I want but close. …I don’t want it to be random, ideally.; It should move to the other patch if there are two, as now, and when I make for accumulation of patches, I’ll want it to go through the list of them, or ideally move to the one with the highest resource? (As with "To turn-towards-resource"); Tried to change this:; if any? other patches with [ owner = owner-number ] [ move-to one-of patches with [ owner = owner-number ] and max resource-here ]; or:; if any? other patches with [ owner = owner-number ] [ move-to one-of patches with [ owner = owner-number ] and max [ resource-here ] ]
end
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/b5634fd3-e776-42ac-86a7-23711973d1a3n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/ea87fb1a-1386-4787-903e-679186b383afn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/CAGC85OM_%2BUy7ttWd89_qVLAooFm1-bfKR-f%2BedAbRHzftBbnfg%40mail.gmail.com.