Microvacuum, a minimalist, command line, Python simulator

Microvacuum

Resources :

sources (Linux, Mac)

Note: the Python2/Python3 compatibility can be obtained by modifying function:
 def input_key(msg):
   return raw_input(msg) # Python 2
   #return input(msg) # Python 3
with :
 def input_key(msg):
   #return raw_input(msg) # Python 2
   return input(msg) # Python 3
in microvacuum.py

Description :

Microvacuum is a minimalist simulation environment written in Python, allowing to test cognitive agents models. This simulator is composed of several elements:

 - the main module (microvacuum.py)
 - a AI module
 - a text file describing the environment
 - a text file describing how to display the environment

The main module initialize and control the simulation, user interface and display panel. It is possible to define the used AI module, the description files and parameters of the visual system in the header of this module. The environment is defined as a number matrix. The agent interacts with the environment using class Robot, that contains functions and methods to act in the environment:

 -position of the agent is defined with two variables x and y, the orientation with variable z (that can have values 0, 1, 2 or 3, corresponding to orientations 0°, 90°, 180° and 270°).
 - feel(self,x,y) returns the value of the cell at coordinates (x,y) in agent's reference
 - see(self) generates the image provided by the visual system of the agent
 - move(self,x,y,z) moves the agent (position {x,y} and rotation z).
 - change(self,x,y,id) replaces the value of cell at coordinates (x,y) in agent's reference, with value id

AI modules (in AI directory) contains algorithms driving the agent. File Min/ai.py is a minimal module, containing all necessary functions. Modules RI1 and PRI1 are examples of AI modules respecting principles of Radical Interactionism models.

 - variable name allows to give a name to the module, that will be used to recognize save files.
 - intend(self) is the method that makes the agent acting in its environment. This method describe the interaction between the agent and its environment. In this example, the agent randomly chooses to move forward, turn left or turn right. Cells with a value of 1 cannot be passed through: when the agent is facing a cell of value 1, it cannot move forward.
 - display(self) allows to return a message to display under the main display screen.
 - getDisplayLine(self,l) allows to display information on the left of the main display. The main module gets this information line by line (l).
 - listCommands(self) returns the list of user command provided by this AI module.
 - commandLine(self,args) processes user commands provided by this AI module. args is a list of strings of characters, containing the command and arguments.
 - getAgentSymbol(self) allows to specify the id of the character to display to represent the agent (that will be found in the display description file). The symbol can change, for example, according to orientation of the agent or according to internal states.
 - load(self,text) loads information from a string of characters text.
 - save(self) gets a string of characters containing information to save in a text file.

The environment description file is a text file that must be placed in env directory. The environment is described as numbers separated with spaces. files env1.txt and env2.txt are two examples of valid descriptive files.

The display description file is a text file that must be placed in skin directory, and that contains symbols to use to display the agent and the environment. The file must contains two lines: the first one contains symbols representing the agent. Note that if getAgentSymbol(self) returns an id greater than the number of symbols, the first symbol will be used. The second line contains symbols to represent cells of the environment. A cell containing number N will be represented with the Nth symbol of the list. If N is greater than the number of symbols, the cell will be displayed as number N. Files skin1.txt and skin2.txt give two examples of valid description files.

Utilization :

Once in microvacuum directory, the simulation is started with command:

python microvacuum.py

The simulator starts in command mode, allowing to edit the simulation. This is the list of commands:
   'c [x] [y] [id]': replaces value of cell (x,y) with 'id'
   'h': lists commands
   'load [file]': loads [file].txt
   'm [x] [y] [rz]': changes position and orientation of the agent with (x;y,rz)
   'q': quits simulator
   'r': runs/pauses simulation
   's': runs simulation of one step
   'save [file]': saves in [file].txt. If the file already exists, it will be replaced.
   'screen [file]': makes a screen capture and save it in [file].txt
   't' [time]: defines a delay of [time] seconds between two steps
   'v': displays/hides visual system

Other commands can be added by AI modules

Microvacuum
The simulation can be started with command 'r'. When running, the simulation can be paused to return to command mode by pressing 'p', and it is possible to quit the simulator by pressing 'q'