views:

36

answers:

1

Inspired from the game GunTactyx, where you write programs controlling fighting robots. Guntactyx used the Small language, that later is called Pawn.

I am looking into using Python as the scripting language.

My concerns are:

  1. Interfacing to C# The scripts should interface into C# through simple functions, doing stuff like scanning for enemies, rotating and firing. I guess each function should be delayed, so they would take x ms to return.

  2. Bad programs. The system should be tolerant to infinite loops or crashes. I would like each virtual machine to be given X ticks to execute at a time.

  3. Limited memory usage Scripts should not be allowed to use unlimited usage. I would like some sort of cap.

  4. Probably alot of other problems

I would like to end up with something in this "pseudo" style.

robots = a list of robots

while(1)
   foreach robot in robots
      robot.tick()
   gameworld.update()
+1  A: 

The answer to your subject question is yes, you can run multiple interpreters in parallel. Generally each script will run in its own ScriptScope, but you can also use isolated ScriptEngines if necessary.

  1. You can inject variables/functions into a script's scope before running it using scope.SetVariable.

  2. Your best bet is to run the Python code on a separate thread and watch it; if it takes too long to return, interrupt the thread. (this is tricky to get right, but that's a different question)

  3. I'm not sure that can enforced easily. It may be possible if you run the scripts in a different AppDomain or process, but that's a lot of extra work for minimal gain.

  4. Just ask!

Jeff Hardy
It is critical that each Virtual Machine has same amount of computing cycles. Do you think there is a way to let it run in a controlled fashion?
The same number of processes, probably not, at least not on .NET. The best you could do is given them a fixed time window.
Jeff Hardy