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

Mr. Neutron nicktsocanos at
Fri Aug 23 06:53:03 EDT 2002

On Fri, 23 Aug 2002 04:47:04 -0400, Erik Max Francis wrote:

> "Mr. Neutron" wrote:
>>         I am working on a program that uses a list of lists
>>                 MyList = [ [0] * 32767 for i in range(32767) ]
>>         My first realization is that it is incredibly slow just to
>>         create this
>>         list.
> What are you actually trying to do?  You should run out of memory before
> this completes; it would take up more than 4 GB of memory.

4 gb?? No wonder it is taking so long. I was not realizing how big the
structure is. I had not even thought about how big this was. Now I am 
realizing how silly I feel about this. I really have to think about
my problem more carefully. I haven't programmed in a few years, so I am
very rusty right now.

What I am trying to do is build a game. It is a very simple game it is
not fancy like Quake or anything like that. I have a World structure
that contains squares. These squares are just an area of the world
(1 mile x 1 mile) that have interesting features on them. I wanted
to make a big world that would be interesting. I can play the game
in a small world ( 64x64 squares ). That is ok and fast. But I wanted the
idea of huge worlds too (even though it is not necessary for the game).
For my simple game so far, MyLIst = [ [0] * 64 for i in range(64) ]
is fast. Is this 64x64x4 = 16384 bytes in Python memory?

You make a robot, give it a purpose in life,
and send it into the world. The robot starts out new and just like
everybody else. It then has to go into the world and survive. It needs
money (by collecting ore found in the world) and fuel (food). It takes
it's money and finds stores where it can purchase parts and upgrade
itself. Upgardes evolve the robot, making it faster, stronger, or more
efficient at carrying ore and fuel, or adding weapons and armor to it.

Somewhere along the line, the robot begins to realize it's existence is
futile. It needs to find other robots to form teams. Teams form togethor
to form communities. Communities of robots are groups of robots with
unique purposes. Each robot has some function in the community that
contributes to the groups goals. Communities can form based on the
philosophy of the robots perception (Ie do I hate so and so, and want to
make war on this community? Am I pacficist, and want to help disabled
robots? The robot needs to develop it's own personality.). 

Now I have made a very simple robot that can move around a world that is
64x64 miles in area. It finds ore and collects it, finds fuel and gathers
it. It understands that it needs to explore it's world to find resources.
It moves about looking for things to collect. I am working on the store
so that it can go to the store and buy items and upgrade. 

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.


More information about the Python-list mailing list