World

The World is where all of the simulation happens. Robots are added to the World, and the Viewer and Logger refer to a World to draw the simulation and save data.

Once the World is created and you have added your robots, you will likely only need to call the step() method.

class gridsim.world.World(width: int, height: int, robots: List[gridsim.robot.Robot] = [], allow_collisions: bool = True)
__init__(width: int, height: int, robots: List[gridsim.robot.Robot] = [], allow_collisions: bool = True)

Create a World for simulating Robots in a grid world

Parameters
  • width (int) – Width of the world (number of cells)

  • height (int) – Height of the world (number of cells)

  • robots (List[Robot], optional) – List of Robots to place in the World to start, by default []. Additional robots can be added after initialization with the add_robot method.

  • allow_collisions (bool, optional) – Whether or not to allow Robots to exist in the same grid cell, by default True

add_robot(robot: gridsim.robot.Robot)

Add a single robot to the World. Robots can also be added in bulk (as a list) when the World is created, using the robots keyword.

Parameters

robot (Robot) – Robot to add to the World

get_dimensions() → Tuple[int, int]

Get the dimensions (in grid cells) of the World

Returns

(width, height) of the World, in grid cells

Return type

Tuple[int, int]

get_robots() → pygame.sprite.Group

Get a list of all the robots in the World

Returns

All Robots currently in the World

Return type

pygame.sprite.Group

get_time() → float

Get the current time of the World. At the moment, that’s just the number of ticks (time steps) since the simulation started, since we’re in a discrete world.

Returns

Number of ticks (steps) since simulation started

Return type

float

step()

Run a single step of the simulation. This moves the robots, manages the clock, and runs the robot controllers.