LOGO-L> Re: Multi-Turtle programming.
Author Message
LOGO-L> Re: Multi-Turtle programming.

Dear Yehuda,
I'm not sure the following will suit your future Math teachers, but
I think it'll at least bring some pleasure for you (if you haven't
found this solution yet by yourself).

Some time ago somebody, I don't remember who, sorry, posted a
nice code for a mouse chasing the other drunk one. I've posted then
the MSWLogo version of it. The same idea used for "Ant problem",
where four ants, initially placed in the corners of the square and
looking inside it,  begin to chase each it's "left" neighbour, leads
to a rather amusing picture.

------ Ant Problem ----------
to ant.main
cs
set
move
end

to set
setturtle 0 st
pu setxy -100 -100 pd label "0
setturtle 1 st
pu setxy -100 100 pd label "1
setturtle 2 st
pu setxy 100 100 pd label "2
setturtle 3 st
pu setxy 100 -100 pd label "3
end

to dx
setturtle 0
localmake "x1 first pos
setturtle 2
localmake "x2 first pos
op :x1-:x2
end

to move
if (abs dx)<2 [stop]
for [i 0 3][setturtle remainder :i+1 4
make "direction pos
setturtle :i
seth towards :direction fd 3]
move
end
--------------------------------------------

-------Chasing Mouse-------------------
to chase
set
drunk.sober
end

to set
cs
setturtle 0 st pu setxy -310 100 seth 90
setturtle 1  st pu setxy -340 0 seth 90
end

to drunk.sober
setturtle 0
fd 6 seth  -30+random 240
make "a pos
; drunk turtle moves off at speed 5 vaguely heading East
setturtle 1
seth towards :a fd 3
; sober turtle moves off at speed 3 with drunk firmly in sights
wait 1
drunk.sober
; recursive line
end
---------------------------------------

Regards,
Olga.

---------------------------------------------------------------

Tue, 14 Mar 2000 03:00:00 GMT
LOGO-L> Re: Multi-Turtle programming.

Quote:
> Date:          Sat, 27 Sep 1997 02:39:17 +0200

> Subject:       Re: LOGO-L> Re: Multi-Turtle programming.

> > Dear Yehuda,
> > I'm not sure the following will suit your future Math teachers, but
> > I think it'll at least bring some pleasure for you (if you haven't
> > found this solution yet by yourself).

> > Some time ago somebody, I don't remember who, sorry, posted a
> > nice code for a mouse chasing the other drunk one. I've posted then
> > the MSWLogo version of it. The same idea used for "Ant problem",
> > where four ants, initially placed in the corners of the square and
> > looking inside it,  begin to chase each it's "left" neighbour, leads
> > to a rather amusing picture.

> > ------ Ant Problem ----------
> > to ant.main
> > cs
> > set
> > move
> > end

> > to set
> > setturtle 0 st
> > pu setxy -100 -100 pd label "0
> > setturtle 1 st
> > pu setxy -100 100 pd label "1
> > setturtle 2 st
> > pu setxy 100 100 pd label "2
> > setturtle 3 st
> > pu setxy 100 -100 pd label "3
> > end

> > to dx
> > setturtle 0
> > localmake "x1 first pos
> > setturtle 2
> > localmake "x2 first pos
> > op :x1-:x2
> > end

> > to move
> > if (abs dx)<2 [stop]
> > for [i 0 3][setturtle remainder :i+1 4
> >             make "direction pos
> >             setturtle :i
> >             seth towards :direction fd 3]
> > move
> > end
> > --------------------------------------------

> Olga,

> Thank you, that was a great help.

> I'll study your programs and see what I can do with them.

> Regards...

> [[Yehuda]]

First of all, in this case the subroutine dx may be shortened. When
there are four ants, one may just compare with the small number
the distance to [0 0] of any turtle. But the problem could be
generalized for any number of turtles. Then, I'm not sure it's easy
to place ants initially around [0 0]. Or, I'm wrong?

Though you asked for "plain vanilla", it would be interesting to
solve this problem in 3D space.

And, when you are ready, would you please share with us what you
are going to do with your new students.

All the best.
Olga.

-------------------------------------------------

Olga Tuzova, Ph.D.
Computer Science teacher,
International School of General Education,
St.Petersburg, Russia,

URL http://www.ort.spb.ru/temp/page_tu/my_main.htm
---------------------------------------------------------------

Wed, 15 Mar 2000 03:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages