Complexity Explorer Santa Few Institute

Introduction to Agent-Based Modeling

Lead instructor:

This course is no longer in session.

Unit 2: Building a Simple Model

Michael DeBellis
17 Jun 2024 7pm UTC
2
in Unit 2: Building a Simple Model

I'm trying to do the Heroes and Cowards example. I'm working on Windows 11 pro, NetLogo 6.4.0 (November 14, 2023). I think setxy isn't working. I'll put my current code at the end (is there a way to include a screen print? I wanted to include a print of what my UI looks like after setup). When I hit setup, rather than seeing the turtles at random places on the screen they are all grouped together at 0,0. When I click on Go (regardless of whether I choose the hero or coward personality) I get the following error:
"OF expected input to be a turtle agentset or turtle but got the number 0 instead.
error while turtle 65 running OF
called by procedure ACT-COWARDLY
called by procedure GO
called by Button 'go'"

When I click on the small blob in the center I get a menu of all 100 turtles and when I inspect any of them their xpos and ypos are both set to 0. I think what is happening is they aren't getting initialized so the default value shows up but when I go to set the value it is an error because the property hasn't been initialized. Here is my code:

turtles-own [ friend enemy ]
to setup
clear-all
ask patches [set pcolor white] ;; create blank background
create-turtles 100 [
setxy random-xcor random-ycor
if (personalities = "cowards" ) [set color blue ]
if (personalities = "heroes" ) [set color red ]
set friend one-of other turtles
set enemy one-of other turtles
]
reset-ticks
end

to go
ask turtles [
if (color = blue) [act-cowardly]
if (color = red) [act-bravely]
]
tick
end

to act-cowardly
;; move away from the enemy
facexy [xcor] of friend + ([xcor] of friend - [xcor] of enemy)
[ycor] of friend + ([ycor] of friend - [ycor] of enemy)
fd 0.1
end

to act-bravely
;; Move toward midpoint of your friend and enemy
facexy ([xcor] of friend + [xcor] of enemy) / 2
([ycor] of friend + [ycor] of enemy) / 2
fd 0.1
end

Michael DeBellis
17 Jun 2024 7:41pm UTC
in Unit 2: Building a Simple Model

I figured it out. It wasn't a problem with the code but with the UI. When I created the "setup" button I set the title rather than the command so when I clicked it nothing happened. It works now.

Sani Gildenhuys
22 Jun 2024 1:17pm UTC
in Unit 2: Building a Simple Model

Well done for figuring it out! The little things can drive me up the wall with frustration. :)

Ho Phuoc Thanh
19 Jun 2024 8:48pm UTC
2
in Unit 2: Building a Simple Model

1. Do we use [set pcolor red] or [set color red] to set colors to turtles?
2. I tried Netlogo with random-seed 29 but I cannot see the results as the test showed.

Peter Muller
20 Jun 2024 6:18pm UTC
in Unit 2: Building a Simple Model

1. [set pcolor red] will turn the patch the turtle is on red if the command is being directed at turtle(s). [set color red] will turn the turtle itself red.
2. where are you using random-seed 29? if you enter it in the text box below the Command Center in the Interface tab, then things will display in the Command Center window. random-seed 29 only sets the seed. You then need to enter a command to generate a random number from 0 to 10 to have a random number then display in the Command Center

Alexander Tolley
21 Jun 2024 9:05pm UTC
in Unit 2: Building a Simple Model

Q 2. after you have set the "random-seed 29" in the "observer>" input, the Command Center box above it should show the command. Then type in the observer> text entry "random 10". The Command box will show first: "show random 10" and then on the next line the value, e.g. "3". Repeat the "random 10" in the observer input and the Command Center should keep adding the 2 lines, with your command and the value below it. Are you seeing both the "Command Center" display box and below it the "Observer" input? - Alex Tolley