AIprojekt-wozek/Finding_fields.py

31 lines
996 B
Python

import math
from Empty import Empty
from Package import Package
from Shelf import Shelf
class Finding_fields:
def __init__(self, enviroment_2d):
self.enviroment_2d = enviroment_2d
def find_closest_shelf(self, start_field, type):
shelves = []
for row in self.enviroment_2d:
for field in row:
if isinstance(field,Shelf):
shelves.append(field)
min_distance = math.inf
closest_shelf = None
for shelf in shelves:
if shelf.type == type:
distance = abs(start_field.x - shelf.x) + abs(start_field.y - shelf.y)
if distance < min_distance:
min_distance = distance
closest_shelf = shelf
return closest_shelf
def find_package(self):
for row in self.enviroment_2d:
for field in row:
if isinstance(field,Package) and not field.is_placed:
return field