Reputation: 319
I'm trying to simulate a car factory using robots called carriers
. In my go method i'm trying to ask one carriers who is not on a job to find a cutter
and go to it.
How do I ask the specific carrier to do something?
This is what i've done so far:
metal-sheets
cut-sheets
standard-skeleton
finished-standard-skeleton
prestige-skeleton
finished-prestige-skeleton
]
breed[carriers carrier]
turtles-own [
on-job?
]
patches-own [
processing-time
machine-type ;;cutter, standard-welder, prestige-welder, riveter
status ;;import, export, pending
]
to setup
set-default-shape carriers "circle"
create-carriers number-of-carriers
[set color grey
set on-job? false]
setup-patches
reset-ticks
end
to setup-patches
ask patches [
if pxcor = 1 and pycor = 1 [set machine-type "cutter"]
if pxcor = 1 and pycor = 5 [set machine-type "standard-welder"]
if pxcor = 5 and pycor = 1 [set machine-type "prestige-welder"]
if pxcor = 5 and pycor = 5 [set machine-type "riveter"]
if machine-type = "cutter"
[set pcolor red
set status "import"]
if machine-type = "standard-welder"
[set pcolor green
set status "import"]
if machine-type = "prestige-welder"
[set pcolor blue
set status "import"]
if machine-type = "riveter"
[set pcolor yellow
set status "import"]
]
end
to Go
let cutter patches with [machine-type = "cutter"]
let standard-welder patches with [machine-type = "standard-welder"]
let prestige-welder patches with [machine-type = "prestige-welder"]
let riveter patches with [machine-type = "riveter"]
let free-carriers carriers with [in-job? false]
ask free-carriers [
;;on-job is a carrier-owned variable
ask cutter [
if status = "import" [
set status "pending"
face cutter ;; I want the carrier to face the cutter and move towards it
fd 1
]
]
]
end```
Upvotes: 0
Views: 491
Reputation: 4168
I'm assuming that you want free-carriers
to find a cutter patch with status "import", have that cutter change its status, and then have the carrier move toward it.
ask free-carriers [
;;on-job is a carrier-owned variable
let my-cutter one-of cutter with [status = "import"]
if my-cutter != nobody [
ask my-cutter [ set status "pending" ]
face cutter ;; I want the carrier to face the cutter and move towards it
fd 1
]
]
Since each free-carrier does this in (random) turn, no two free-carriers should go to the same cutter. This will choose an eligible cutter randomly. You could have free-carriers go to the nearest one if you wished.
Upvotes: 1