AIprojekt-wozek/Packages_spawner.py

43 lines
1.3 KiB
Python

import random
from Global_variables import Global_variables as G_var
from Package import Package
from Package_types import Package_types
from decision_tree.Decision_tree import DecisionTree
import glob2
from neural_network.NeuralNetwork import NeuralNetwork
class Packages_spawner:
def __init__(self, window,enviroment_2d):
self.window = window
self.enviroment_2d = enviroment_2d
def read_photo_and_determine_marking(self): # USING NEURAL NETWORK
image = self.get_marking_photo()
net = NeuralNetwork()
marking = net.use_neural_net(image)
if marking == "fragile":
type = Package_types.fragile
elif marking == "priority":
type = Package_types.priority
return type
def spawn_package(self):
package_x = random.randrange(22, 26)
package_y = random.randrange(1, 13)
# package_type = random.choice(list(Package_types))
package_type = self.read_photo_and_determine_marking()
new_package = Package(self.window, package_x, package_y, package_type)
self.enviroment_2d[package_x][package_y] = new_package
def get_marking_photo(self):
file_path_type = ["resources/markings/*.png"]
images = glob2.glob(random.choice(file_path_type))
random_image = random.choice(images)
return random_image