views:

91

answers:

1

I am interrested in doing a programming game using python, and I would like to do it in the style of GunTactyx (http://apocalyx.sourceforge.net/guntactyx/index.php). Only much simpler, as I am primarily interrested in the parallel execution of python scripts from python.

Gun Tactyx challenges the player to write a program that controls individual units working together in teams, where each instruction carries a time panalty. Each program is executed in its own protected environment, communicating with the game world through functions that can interact with the game world.

I was wondering if there is a Python way of achieving similar effect.

Pseudo code structure of the game engine would be something like:

Instantiate units with individual programs
while 1
   Update game world
   for unit in units:
      unit.tick()

The simulation would run until a timeout or some goal condition.

Kind regards

/Tax

+1  A: 

Maybe you should look into fork of python: stackless, it allows concurrently running thousands of micro-threads without much performance penalty - every "thread" (these aren't real OS threads) could be one Unit.

Also it's very easy to implement Actor model with stackless:

In the actor model, everything is an actor (duh!). Actors are objects (in the generic sense, not necessarily the OO sense) that can: Receive messages from other actors. Process the received messages as they see fit. Send messages to other actors. Create new Actors.

Actors do not have any direct access to other actors. All communication is accomplished via message passing. This provides a rich model to simulate real-world objects that are loosely-coupled and have limited knowledge of each others internals.

from Introduction to concurrent programming with stackless

Alternatively, you could also simulate this behavior by implementing co-routines - using python generators, like shown here. But I'll guess you'll be better off with stackless, as it's all there already.

kurczak