Reputation: 1
I'm working on this assignment for my university with Netlogo and I'm really stuck. I just started out using Netlogo and I'm trying to recreate Mekka, together with some pilgrims.
I've been trying out a lot of different codes, adding new ones, trying it out, deleting some, but this is what I came up with this far:
turtles-own
[direction ;; 1 follows right-hand wall, -1 follows left-hand wall
way-is-clear? ;; reporter - true if no wall ahead
checked-following-wall?]
globals [halfedge]
breed [agents agent ]
agents-own [ around visible ]
to setup
create-agents 500 [
set color green
set size 2
; distribute agents randomly
setxy pxcor = halfedge pycor = halfedge
set heading random 360
; ensure that each is on its own patch
while [any? other agents-here] [ fd 1 ]
]
end
to bounce
if [pcolor] of patch-at dx 0 = blue [
set heading (- heading)
]
if [pcolor] of patch-at 0 dy = blue [
set heading (180 - heading)
]
end
to go
ask agents [ count-those-around ]
ask agents [ move ]
end
; store the number of agents surrounding me within
; local-radius units
; and the agents that I can see within visible-radius
to count-those-around
set around count agents with [self != myself] in-radius
local-radius
set visible agents with [self != myself] in-radius
visible-radius
end
to move
;; turn right if necessary
if not wall? (90 * direction) and wall? (135 * direction) [ rt 90 * direction ]
;; turn left if necessary (sometimes more than once)
while [wall? 0] [ lt 90 * direction ]
;; move forward
fd 1
end
; face towards the most popular local spot
to face-towards
face max-one-of visible [around]
end
; face away from the most popular local spot
to face-away
set heading towards max-one-of visible [around] - 180
end
to setup-center
clear-all
set halfedge int (edge / 2)
ask patches[
if (pxcor = (- halfedge) and pycor >= (- halfedge) and pycor <= (0 + halfedge) )
[set pcolor blue] ;; ... draws left edge in blue
if ( pxcor = (0 + halfedge) and pycor >= (- halfedge) and pycor <= (0 + halfedge) )
[set pcolor blue] ;; ... draws right edge in blue
if ( pycor = (- halfedge) and pxcor >= (- halfedge) and pxcor <= (0 + halfedge) )
[set pcolor blue] ;; ... draws bottom edge in blue
if ( pycor = (0 + halfedge) and pxcor >= (- halfedge) and pxcor <= (0 + halfedge) )
[set pcolor blue] ;; ... draws upper edge in blue
]
end
Right now the kaaba is successfully drawn, the only problem is that turtles are not supposed to be spawn in there or run into it (therefore the bump code). Also, they are randomly going around, and I have no idea how to make them move in a Counter-Clickwise formation, following one differently coloured leader.
Could any of you guys help me out? I would be eternally thankful!
Upvotes: 0
Views: 139
Reputation: 30453
You may be trying to learn too much all at once by writing a big program all at once.
Start by writing a really small program; get it working; attempt to make a very small improvement to it, and get that working; and so on. If at any point you get stuck, come here, show your code with has at most one thing broken about it, and ask one question about the one issue in particular that you're currently stuck on. That's the most effective way to get help.
A few random coding tips:
This isn't valid code:
setxy pxcor = halfedge pycor = halfedge
setxy
expects two numbers, but you're passing it two booleans: pxcor = halfedge
is true or false, and pycor = halfedge
is true or false, too. I think you might mean just setxy halfedge halfedge
.
agents with [self != myself]
can be replaced with simply other agents
.
Upvotes: 2