Game - Map data structures
phil hunt
zen19725 at zen.co.uk
Sat Jun 19 19:09:01 EDT 2004
On 18 Jun 2004 23:08:27 -0700, Dan Bishop <danb_83 at yahoo.com> wrote:
>Innocence <innocence(a)klog(dot)dk> wrote in message news:<lts5d0pi0nhk02ri15pofo6k7b52n1fi3r at 4ax.com>...
>> Hi
>>
>> I've been considering how to optimize map data structures for a tile
>> based Python game. However, since I'm a Python newbie I lack
>> experience with Pythons 'exotic' data types like lists and tuples, and
>> thus I'm unsure whether such types could solve my problem.
>>
>> My basic thought is this: If my world map consists of 80% water and
>> 20% land, then why reserve full data-structures for all the water
>> tiles?
>>
>> I'm looking for a way to do the following:
>>
>> My World Map object should likely be a standard (x,y) array of Tiles
>> (unless there's a better way?)
>> Each Tile has a boolean/one-bit value: 0 or False for Water, 1 or True
>> for Land.
>
>A better way is to have the class hierarchy like
>
>class Tile(object):
> def __init__(self, ...):
> # data that any Tile can contain
> self.armies = ...
> ...
>
>class WaterTile(Tile):
> pass
>
>class LandTile(Tile):
> def __init__(self, ...):
> Tile.__init__(self, ...)
> # data specific to land tiles
> self.building = ...
I think you are confusing two separate concepts here: the concept of
a terrain type, and the concept of a location.
A terrain type is something like "water", or "hill", or perhaps
"hill with coal resource". You can ask a terrain type questions like
"how many movement points does it costto move onto / off of a square
of this terrain type?"
A location is something like "grid reference (x=20, y=32) on the
map". You can ask a location things like "what armies are on this
location?", or "return a reference to the location to the north of
this one".
--
"It's easier to find people online who openly support the KKK than
people who openly support the RIAA" -- comment on Wikipedia
(Email: zen19725 at zen dot co dot uk)
More information about the Python-list
mailing list