from domain.entities.entity import Entity class World: def __init__(self, width: int, height: int): self.width = width self.height = height self.dust = [ [[] for j in range(height)] for i in range(width) ] self.obstacles = [ [[] for j in range(height)] for i in range(width) ] self.entities = [] self.vacuum = None self.cat = None # move: update position from (start_x, start_y) to (end_x, end_y) # def move(self, entity: Entity, end_x: int, end_y: int): # # no change # if entity.x == end_x and entity.y == end_y: # return # # # check if object moves beyond border # if end_x > self.width - 1 or end_y > self.height - 1 or end_x < 0 or end_y < 0: # print("Cannot move object beyond board") # return # # # check if destination is empty # # if self.is_obstacle_at(end_x, end_y): # # print( # # f"Cannot move object to ({end_x}, {end_y}): position already occupied" # # ) # # return # # # change position in array # self.grid[entity.x][entity.y].remove(entity) # self.grid[end_x][end_y].append(entity) # entity.x = end_x # entity.y = end_y def is_obstacle_at(self, x: int, y: int) -> bool: return bool(self.obstacles[x][y])