TiledLand: A Polygon-Based Simulation Engine.

This project is a Python package oriented toward multi-agent simulation relying on convex polygonal objects. The main idea is to model a planar world (the land) as a collection of convex-polygon cells (the tiles). Then, the land is mainly composed of a tabletop - interconnected tiles - and agents distributed inside it.

To notice that, TiledLand is more a sandbox project to test approaches than an optimized, ready-to-use and well documented toolbox.

Not what are you looking for ?

You can look at concurrent/complementary projects:

  • box2d - 2d physics game engine (in C language but with a lot of binds)
  • pygame - python-based game engine
  • raylib - simple cross language game engine
  • shapely to manipulate, in python geometric objects in the Cartesian plane (based on GEOS).
  • cgal another Computational Geometry Algorithms Library (c++)

Install

The project and its dependencies can be installed with the pip tool.

pip install tiledland

For information, TiledLand relies on pyyaml to read yaml configuration files, on hacka for distributed game programming, and on Cairo library for PNG image rendering.

You can also install TiledLand from source: github.com - tiledland.

Get started

Then, as an example, the following code will generate a grid-tabletop with several entities. The tabletop is then rendered as a png graphic.

#!/usr/bin/python3
import tiledland as tll

# Create a new land (a tiled tabletop and entities inside it) :
tabletop= tll.Tabletop()
tabletop.initGrid([
    [0, 1, 1, -1, 0, 0, 0, 0], # -1 : means no cell at this selector
    [5, -1, 0, 2, 0, -1, 5, 0], # 0 - n : give the group identifier
    [0, 0, 0, -1, 0, 1, 1, 0], # of the cell to create.
    [0, 4, 0, -1, 0, 2, 1, 6],
    [-1, -1, 0, 0, 0, -1, -1, -1]
])

# Define a small shape for our entities...
shape= tll.Convex().initRegular( 0.4, 5 )

# Add several entities associate to different groups...
tabletop.tileAppendEntity( 8, tll.Entity(1, shape, name="A1") )
tabletop.tileAppendEntity( 16, tll.Entity(1, shape, name="A2") )
tabletop.tileAppendEntity( 4, tll.Entity(2, shape, name="B1") )
tabletop.tileAppendEntity( 19, tll.Entity(2, shape, name="B2") )
tabletop.tileAppendEntity( 24, tll.Entity(3, shape, name="C1") )
tabletop.tileAppendEntity( 28, tll.Entity(3, shape, name="C2") )

# Create an artist to render this tabletop:
tll.draw( tabletop, "shot-demo.png", 800, 600 )

print( f"You can open now the './shot-demo.png' file." )

Structure

TiledLand is structured with several sub-modules, each one dedicated to a functionality.

  • geometry : Polygon-based objects and the tabletop definition.
  • artist : for rendering geometry objects
  • core : Build on top of geometry and artist, it defines the main tiledland elements: entities, tiles and tabletops.
  • agent system : A upper-layer built on top of TiledLand core elements with land and agents for agent-based modeling.
  • games : few example games.
  • interfaces : offering tools making TiledLand easily integrable with external solutions like ROS2, Web IHM (with Remi). To notice that TiledLand is not dependent on the Python packages targeted with interface components.