Reputation: 17
Thank you for earlier input on my question. In this model the boat moves diagonally across the world (which does not wrap, 00 bottom left, max-pycor & max-pxcor 49) and 20 fish move in the opposite diagonal. It is the intention that the boat counts the fish it encounters (i.e. the b-count increases) and the fish turn yellow. When the fish moves off the same patch as the boat, it changes color back to blue. To verify the boat counts, each fish records when it meets the boat, (i.e. the f-count increases) and the fish change shape from star to circle. Again when the fish is no longer on the same patch as the boat, the fish change back to a star shape. It does not matter if the boat does not meet all the fish.
On this specific run, random seed is set, when "boat 0" and "fish 18" encounter each other (inspecting both and at tick 183), they appear to be on the same patch, but the relevant counts do not increase and "fish 18" does not change shape or color. As a beginner with NetLogo, is there something in the coding of "boats-here", "fish-here" or "neighbors" that I am overlooking that is related to the xcor/ycor of the agents? Or is the sequence of commands the source of the problem? Thanks once again for considering my question.
globals [ starting-seed ]
breed [boats boat]
breed [fish a-fish]
boats-own [b-count fuel]
fish-own [f-count]
to setup
clear-all
set starting-seed 91130056
random-seed starting-seed
reset-ticks
create-boats 1
[apply-boat-properties]
create-fish 20
[apply-fish-properties]
end
to apply-boat-properties
ask boats
[
set color red
set size 0.3
set shape "star"
setxy min-pxcor max-pycor
set fuel 710
]
end
to apply-fish-properties
ask fish
[
set color blue
set size 0.3
set shape "star"
setxy random-xcor max-pycor
]
end
to go
if (any? boats with [fuel <= 0 ])
[ stop ]
ask boats
[
follow-route1
survey
]
ask fish
[
check-if-boat
move
]
tick
end
to follow-route1
ask boats
[
facexy 49 0
fd 0.05
pen-down
set fuel fuel - 1
]
end
to survey
ifelse any? fish-here ;; if boat on the same patch as a fish
[ask fish-here [ ;; ask the fish on this patch
if shape = "star"[ ;; with a "star" shape
set shape "circle" ;; change shape to "circle" shape
ask boats-here ;; ask boat on same patch to increase b-count
[set b-count b-count + 1]]
]
]
;; otherwise
[ask fish-on neighbors [ ;; ask fish on neighbouring 8 patches
if shape = "circle"[ ;; if the fish has a "circle" shape
set shape "star" ] ;; change that shape to "star" shape
]]
end
to move
ask fish
[
set heading 225
fd 0.0025
]
end
to check-if-boat
ifelse any? boats-here ;; if boats on same patch as the fish
[
ask fish-here with [color = blue] ;; ask the blue fish to change to yellow
[ set color yellow
set f-count f-count + 1] ;; and increase f-count by 1
]
[ask fish-here with [color = yellow] ;; otherwise ask yellow fish to go blue
[set color blue
] ]
end
Upvotes: 0
Views: 60
Reputation: 2305
For your specific example, they simply are not on the same patch. Fish 18 is on 7 43 while the boat is on 6 43. You can check this quickly by using ask boat 0 [show patch-here]
. At tick 184, they have crossed into 6 42 and 7 42 respectively, neither one ever stepping on the same patch.
Another problem I see is that sometimes a fish changes color but not shape. The problem here is the order in which things happen. Currently it is: The boat moves => the boat scans => the fish move => the fish scan. Because of this, a fish can move onto a patch after the boat has already scanned that patch and determined there was no fish there. Or a fish can move off of a patch and no longer see that boat that scanned it. Simply changing this to boat moves => the fish move => the boat scans => the fish scan will solve this issue.
There is currently also an edge case where a boat and fish could move away from eachother simultanously, causing the boat to be unable to set the fishes shape back to star.
Upvotes: 1