Computer Science question (python list is slow with my cruddy algorithm )

Mr. Neutron nicktsocanos at
Fri Aug 23 14:52:04 CEST 2002

On Fri, 23 Aug 2002 07:41:22 -0400, Keith S. wrote:

> Mr. Neutron wrote:
>> Now that that is out of the way, are there any better ways to represent
>> the world than a list of lists? I just need to be able to say
>> World[Y][X] = ( values ). Or be able to say what is at World[Position].
>> Ideally I could say World[ (X,Y) ] = (Values) but I have not tried
>> this. If World[ (X,Y) ] is empty, than it does not need to store
>> anything in memory at all. I need to go to Idle now and experiment with
>> this.
> Why not represent the 'world' as a graph. Each vertex of the graph is
> one 'location'. Edges of the graph connect locations (this is nice,
> since it means you can control how your robot can move from location to
> location - different edges can have different costs, representing
> distance between vertices).
> Not sure if there's any good books on graph implementation in Python,
> but you can get a good overview from 'Algorithms in C++ Part 5' by
> Robert Sedgewick, published by Addison Wesley.
> - Keith

Thanks to all for help and ideas. I am interested in the graph idea, and
it gives me an oppurtunity to learn a new thing.  The graph is also
useful because moving into a location requires 'time' (it simulates that
the terrain is difficult for example). It is really a simulation in a
very very simple little world.

In the meantime I solved my problem in a quick and dirty way. I can use
maps to do this Map = { }, Map[(X,Y)] = [ list ... ] and it works fine now
and does not require god aweful amount of memory to store a big world in

Right now my Robot is exploring it's world! It is funny to watch it but
it is still very stupid right now (it refuses to accept it's fuel tank is
full, and mines fuel anyways... a bug of course!!).

Well when I am done with PyROBOTS it is a GPL so if anybody is interested
in it you can look at it and play with your own robots. I have a few
plans on building robots in different ways. I have a lot of things I
would like to simulate with Robots just because I think it is
interesting to watch.


More information about the Python-list mailing list