Skip to content

u-t-autonomous/gridsim

Repository files navigation

gridsim

2D gridworld simulation, grid world, grid-world, pygame, sim, girdworld, simulation, 2D.

Dependencies

  • Python 2.7 or 3+
  • Pygame

Documentation

Instantiating

Simulation(configFile = None)
Parameters:

configFile: String

Returns:

An instance of Simulation()

Usage:
sim = Simulation('path/to/config_file')

Uploading matrix file

Simulation.load_matrix_file('path/to/matrix_file')
Parameters:

matrixFile: String

Returns:

Nothing

Uploading slip file

Simulation.load_slip_file('path/to/slip_file')
Parameters:

slipFile: String

Returns:

Nothing

Slip file structure:
x_pos y_pos action x_result y_result probability

Moving Agents

Simulation.move_agent(actions = None)
Parameters:

actions: List of actions. There are 7 actions to choose from. 'east', 'west', 'north', 'south', 'keyboard', 'matrix'.

The fist four actions are self-explanatory. 'keyboard' takes the input from they keyboard keys to move the agent. 'matrix' moves the agent according to the matrix file used during instantiating the simulation.

Returns:

Boolean: flag whether to terminate simulation. True if terminate, False if not.

Dictionary: Contains the state of the simulation.

Usage:
done, state = sim.move_agent(['east','keyboard'])

Getting Current State

Simulation.get_state()
Parameters:

None

Returns:

Dictionary

Usage:
state = sim.get_state()

Update simulation

Simulation.update()
Parameters:

None

Returns:

Boolean

Usage:
done = sim.update()

Getting the log

Simulation.get_log()

Parameters:

None

Returns:

Dictionary

Usage:
log = sim.get_log()
agents_log = sim.get_log()["agents"]
agent_0_log = sim.get_log()["agents"][0]

Getting history

Simulation.get_history(time_steps)
Parameters:

time_steps

Returns

Dictionary of last [time_steps] time steps

Usage:
histroy_1 = sim.get_log(1)
history_2 = sim.get_log(2)
agents_2_history = sim.get_log(2)["agents"]

Generating agent matrix

Simulation.generate_agent_matrix(file = None)
Parameters:

String: String

Returns:

None

Usage:
sim.generate_agent_matrix("agent_matrix.txt")

Usage Example

from environment import Simulation
from time import sleep

sim = Simulation("config.txt")
sim.load_matrix_file("matrix.txt")
state = sim.get_state()
done = False

while not done:
    
    # move the agent 1 according to the matrix file and agent 2 south
    done, state = sim.move(["matrix", "south"])
    sleep(1)

# to generate a matrix file
sim.generate_agent_matrix("agent_matrix.txt")

Config file maker GUI

Launching GUI
python config_gui.py [configFile]

The GUI prompts for inputs on the command line while running

Parameters:

configFile (optional) - open a config file to edit

Developers

Releases

No releases published

Packages

No packages published

Languages