lab

class VacuumAgent:

    def __init__(self, environment):

        self.environment = environment

        self.rows = len(environment)

        self.cols = len(environment[0])

    def clean_cell(self, row, col):

        

        if row >= self.rows or col >= self.cols:

            return

        print(f”Moving to position: ({row}, {col})”)

        

        

        if self.environment[row][col] == 1:

            print(“Dirty spot found, cleaning…”)

            self.environment[row][col] = 0 

            print(“Spot cleaned”)

        else:

            print(“Spot already cleaned”)

        if col + 1 < self.cols:

            self.clean_cell(row, col + 1)

     

        elif row + 1 < self.rows:

            self.clean_cell(row + 1, 0)

    def clean(self):

        print(“Started cleaning process…”)

        self.clean_cell(0, 0)  

        print(“Cleaning complete, environment is clean now.”)

        self.display_env()

    def display_env(self):

        print(“\nCurrent state of the environment:”)

        for row in self.environment:

            print(row)

# Environment setup

environment = [

    [1, 0, 1],

    [0, 1, 0],

    [1, 1, 0]

]

vacuum = VacuumAgent(environment)

vacuum.clean()

Scroll to Top