API - jetstreamc/PySimbot Wiki

This section provides list and description of PySimbot objects.

PySimbotApp

You can configure the PySimbotApp in several ways by passing the parameters to the PySimbotApp's constructor.

Available options

parameter Type description
robot_cls Robot-based Class Class of the robot for initializing all robots in the simulation
num_robots int Number of robots created in the simulation
num_objectives int Number of foods created in the simuation (index of food start at 0)
robot_default_start_pos Tuple[int,int] Starting position of the robot in XY pixels unit.
obj_default_start_pos Tuple[int,int] Starting position of the food in XY pixels unit.
interval float Minimum time interval in seconds between each frame of simulation
max_tick int Maximum number of frame for a simulation
map str Map name as defined in pysimbotlib/maps folder. Default value is 'default'
theme str Theme as defined pysimbotlib/themes folder. Default value is 'default'
customfn_create_robots function Function that returns a list of robots. PySimbotApp will override the robots initialization process by this function
simulation_forever bool Enable/Disable simulation in the infinite loop. If True, you can test your robots multiple times or you can try algorithm that based on the iterative improvement.
customfn_before_simulation function Task to runs before each simulation. You can do things such as managing map, or writing a log file.
customfn_after_simulation function Task to runs after each simulation. You can do things such as writing a log file.
enable_wasd_control bool Enable/Disable the WASD control using keyboard.
food_move_after_eat bool Enable/Disable changing position of food after the robot eat.
save_wasd_history bool Enable/Disable the WASD history. In each simulation, the values of distance(), smell(), move and turn when user control the robots would be recorded to file.
robot_see_each_other bool Enable/Disable the robot to see the other robots. This also related to distance calculation and robot-to-robot collision.

To see how each option works, the fast way is to try the examples. See more in the Examples page.

Robot

We design the robot class based on the concept of Object-Oriented Programming (OOP). Robot is the class in the pysimbotlib.core. It defines the basic functions of the robot such as sensing the distances around, moving and turning.

The Robot Class contains following properties and methods.

Property Type Description
color Tuple[r,g,b,a] color of the robot
eat_count int number of foods that robot has eaten
collision_count int number of collisions that the robot made
just_eat bool flag that would be True if the robot ate food in the last iteration
stuck bool flag that would be True when the robot is stuck to the wall
Method Return Type Description
update() None Update the robot state for each simbot's iteration
set_color(r,g,b,a) None Color the robot. The values of (r, g, b, a) are between 0 to 1. (a is optional, default to 1)
turn(degree) None Turn the robot by the specifying degree (floating point number)
move(step) None Move the robot forward by the specified step (integer number). The robot will not move if collides.
distance() Tuple[float,...,float] Get the 8 sensor distances in pixels from the sensors around the robot side
smell(index) float Get the turning angle to the food corresponding to the food index. (index is optional, default to 0)
smell_nearest() float Get the turning angle to the nearest food