Abha Trivedi
Abha Trivedi

Reputation: 205

how to count number of turtles on a set of patches at a particular instance in netlogo

Can we count number of turtles on a set of patches or on a single patch at some particular time instance (say for in a tick).

set turtle-at-setpatches count turtle-on patches with [ (pxcor >= 9 and pxcor <= 13) and (pycor <= 9  and pycor >= 2)]

I gets the count with this code, but is this count is on the basis of ticks by default. what i need is number count on a particular tick(or instance). Thanks in advance.

Upvotes: 1

Views: 1187

Answers (1)

Alan
Alan

Reputation: 9610

Answer to question as asked:

if (ticks = 10) [
  set turtle-at-setpatches 
    count turtles-on patches with [ 
      (pxcor >= 9 and pxcor <= 13) and (pycor <= 9  and pycor >= 2)
]

A possibly better answer: collect the data for every tick in a table. E.g.,

extensions [table]
globals [setpatches turtles-on-setpatches]

to setup
  ;compute setpatches only once
  set setpatches patches with [ (pxcor >= 9 and pxcor <= 13) and (pycor <= 9  and pycor >= 2)]
  crt 500
  set turtles-on-setpatches table:make
  reset-ticks
end

to go
  ask turtles [setxy random-xcor random-ycor]
  table:put turtles-on-setpatches ticks (count turtles-on setpatches)
  tick
end

Upvotes: 2

Related Questions