AIprojekt-wozek/Finding_fields.py

31 lines
1.0 KiB
Python
Raw Permalink Normal View History

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
2022-05-12 21:16:05 +02:00
def find_closest_shelf(self, start_field, type, sector):
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:
2022-05-12 21:16:05 +02:00
if shelf.type == type and shelf.sector == sector:
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