[starlogo-users] RE: "min-of-turtles-with" question
Andrew Begel
abegel at eecs.berkeley.edu
Wed Jun 30 11:20:46 EDT 2004
Yes, you want a slightly different command: who-min-of-turtles-with. :)
set closest-and-min-pair who-min-of-turtles-with [color = green]
[distance xcor-of myself ycor-of myself]
show first closest-and-min-pair ;; the closest who number
show second closest-and-min-pair ;;; the distance
Inside a min-of-turtles-with or who-min-of-turtles-with (or any of the
commands that run over all turtles), the list to run is executed by the
other turtle. So to find the distance to the calling turtle, you can
use "myself" as a substitute for the "who" of the calling turtle:
distance xcor-of myself ycor-of myself.
min-of-turtles-with returns the minimum value. who-min-of-turtles-with
returns a list of two elements: the first is the who of the turtle who
had the minimum value (if any) and the second is the minimum value.
Andrew
On Jun 30, 2004, at 6:49 AM, Buck, Peter M wrote:
> Sorry, original example has multiple mistakes. What I meant to ask
> was, instead of this
>
> set distance-to-closest 99
> dolist [ :candidate list-of-turtles-with [ color = green ] ] [
> let [ :distance ( distance ( xcor-of :candidate ) ( ycor-of
> :candidate ) ) ]
> if ( :distance < distance-to-closest ) [
> set distance-to-closest :distance
> set closest :candidate
> ]
> ]
>
>
>
> --is something like this possible?
>
> set closest ( min-of-turtles-with [ color = green ] [ distance
> (xcor-of :this-turtle) (ycor-of :this-turtle) ] )
>
> That is, does min-of-turtles-with provide access to the who number of
> the currently-considered turtle?
>
> - Peter Buck
>
>
>
> _____________________________________________
> From: Buck, Peter M
> Sent: Wednesday, June 30, 2004 9:12 AM
> To: 'starlogo-users at media.mit.edu'
> Subject: "min-of-turtles-with" question
>
> I know I can find the nearest turtle with a certain attribute like this
>
> set distance-to-closest 99
> dolist [:candidate list-of-turtles-with [color = green]] [
> let :distance [(distance (xcor-of :candidate) (ycor-of
> :candidate))]
> if (:distance < distance-to-closest) [set distance-to-closest
> :distance]
> ]
>
> but it would be nice to be able to do it something like this
>
> set distance-to-closest min-of-turtles-with [color = green] [distance
> (xcor-of :this-turtle) (ycor-of :this-turtle)]
>
> What I've written would depend on variable :this-turtle being
> available in min-of-turtles-closest. I haven't seen any suggestion
> that that is so.
>
> Is what I am dreaming of possible?
>
> Thanks,
> Peter
> _______________________________________________
> starlogo-users mailing list
> starlogo-users at media.mit.edu
> http://education.mit.edu/mailman/listinfo/starlogo-users
More information about the starlogo-users
mailing list