[Tutor] Livewires Robot-5

Gregor Lingl glingl at aon.at
Fri Nov 21 19:23:47 EST 2003



Leung Cris schrieb:

> I know I should have been more specific: okay, I kinda understand how
> I can add stuff in to my list. The problem is: WAT do I add?

As far as I see, your task is to create several robots, which are not in
collision with
each other and to store them in a list. This list is to be called robots

robots = [] # initially empty
for i in range(number_of_robots_to_create): # number_of_robots_to_create
# for instance may be 5
newrobot = Robot() # a new one
## here check if there are collisions
## with robots already created, something SIMILAR TO
ok = False
while not ok:
ok = True
for oldrobot in robots:
if oldrobot.collides(newrobot):
ok = False
if not ok: # there was a collision
## put newrobot in a new place
.....
## ok is still False here, so the loop has to be done again
## here we come, if there was no collision (ok is True here)
## so the robot is ok and we append it to our list of robots:
robots.append(newrobot)

## Now all our robots are ready to do something:

for robot in robots:
### do something
...

## if you want a specific robot to do something, you have
## to call him via his "index", (you said you know lists from
## reference A, didn't you? E. g.:

robots[2].x, robots[2].y = 150, 250

this changes position of robots[2], actually the third robot in
robots ...


please note, that I don't know the robots worksheet
very well, so I did only outline an idea of what and how to do...

Regards, Gregor





>
>> From: Gregor Lingl <glingl at aon.at>
>> To: Leung Cris <krazie_mu_boi at hotmail.com>
>> CC: tutor at python.org
>> Subject: Re: [Tutor] Livewires Robot-5
>> Date: Sat, 22 Nov 2003 00:02:13 +0100
>>
>>
>>
>> Leung Cris schrieb:
>>
>> > I'm working on Livewires' worksheet 5 -- Robot
>> > (http://www.livewires.org.uk/python/pdf/5-robots.pdf) . I'm 3/4 of the
>> > way through this sheet, and I've got a player moving with a robot
>> > chasing it. But now, I'm stuck on " a List of Robot" . They are saying
>> > something 'bout placing robots inside a list -- but I don't get it!!!
>> > Please help.
>>
>> Hi Leung!
>>
>> I think you are stuck at this point:
>>
>> About the only thing you might need to know is that the way to add a new
>> item to a list is to say something like
>> my_list.append(new_item) .
>>
>> You can only understand this, if you know something about lists, which
>> is one sort of sequence or collection (of objects, eg. robots)
>> in Python. Fortunately there are several Livewires "reference sheets" on
>> certain fundamental topics of Python programming.
>> One of them is Refernce sheet A, lists. There (on page 2) you will learn
>> how to "append" objects to lists.
>> I recommend that you work through this one an you will easily master
>> your robot problem. It's located here:
>>
>> http://www.livewires.org.uk/python/pdf/A-lists.pdf
>>
>> HTH
>>
>> Gregor
>>
>> >
>> > _________________________________________________________________
>> > ¨Ï¥Î MSN Messenger¡A»PªB¤Í¦b½u¤W²á¤Ñ:
>> http://messenger.microsoft.com/tc
>> >
>> > _______________________________________________
>> > Tutor maillist - Tutor at python.org
>> > http://mail.python.org/mailman/listinfo/tutor
>> >
>> >
>>
>
> _________________________________________________________________
> ¨Ï¥Î¥þ²y¥Î¤á³Ì¦hªº¹q¤l¶l¥óªA°È MSN Hotmail¡G http://www.hotmail.com
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>




More information about the Tutor mailing list