added function that calulates the closest shelf

This commit is contained in:
Anna Śmigiel 2022-04-28 21:50:25 +02:00
parent 2494d7ef66
commit 5a728385d2

View File

@ -1,10 +1,10 @@
import numpy as np
import glob2 import glob2
import pygame import pygame
import random import random
from Field import Field from Field import Field
from Global_variables import Global_variables as G_var from Global_variables import Global_variables as G_var
from Package_types import Package_types from Package_types import Package_types
import math
class Package(Field): class Package(Field):
@ -34,3 +34,13 @@ class Package(Field):
elif package_type == Package_types.priority: elif package_type == Package_types.priority:
color = (10, 34, 255) color = (10, 34, 255)
return color return color
def choose_the_closest_shelf(self, shelves):
array = []
for shelf in shelves:
if shelf.type == self.type:
segment = math.sqrt((shelf.x - self.x)**2 + (shelf.y - self.y)**2)
array.append((segment, shelf))
array.sort(key=lambda y: y[0])
print(array)
return array[0]