Computer Science question (python list is slow with my cruddy algorithm )
keith_s at ntlworld.nospam.com
Fri Aug 23 13:41:22 CEST 2002
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.
More information about the Python-list