Game - Map data structures

Dan Bishop danb_83 at
Sat Jun 19 08:08:27 CEST 2004

Innocence <innocence(a)klog(dot)dk> wrote in message news:<lts5d0pi0nhk02ri15pofo6k7b52n1fi3r at>...
> 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):

class LandTile(Tile):
   def __init__(self, ...):
      Tile.__init__(self, ...)
      # data specific to land tiles
      self.building = ...

More information about the Python-list mailing list