Customize your Robot - jetstreamc/PySimbot Wiki

You can code your own robot in Python, make it move, and configure to use it in a simulation.

Extend the Robot class

PySimbot is designed based on the Object-Oriented Programming (OOP) concept.

You can create your own Robot class by extends the PySimbot's default robot class pysimbotlib.core.Robot. Then customize the update() method by override it by your logic. For the rest, your class will inherit the ability from the default robot class that will handle the methods such as drawing in simulation map, checking for robot collision, eating food etc.

from pysimbotlib.core import PySimbotApp, Robot

class CircularRobot(Robot):
    def update(self):
        self.move(5)
        self.turn(15)

Configure simulation to run your robot

By passing your robot class as a parameter of PySimbotApp constructor, the simulation will replace the default robot with your own robot.

if __name__ == '__main__':
    app = PySimbotApp(robot_cls=CircularRobot)
    app.run()

Put it together

To combine all code segments into one, you can simply create a new script file e.g. main.py and put it together.

from pysimbotlib.core import PySimbotApp, Robot

class CircularRobot(Robot):
    def update(self):
        self.move(5)
        self.turn(15)

if __name__ == '__main__':
    app = PySimbotApp(robot_cls=CircularRobot)
    app.run()

Then, in the command window, run the command

python main.py

Now, you should see the robot moving in the map by your own robot.