From 5c0f2d5f151be191f7eafe05b34dacebeb0ea9f5 Mon Sep 17 00:00:00 2001 From: shaaqu Date: Tue, 9 Jun 2020 21:23:10 +0200 Subject: [PATCH] created 20 shelfs --- assigning.py | 5 ++-- board.py | 74 +++++++++++++++++++++++++++++++++++++++++++++++++--- field.py | 3 +++ main.py | 6 ++--- product.py | 4 +-- shelf.py | 17 +++++------- 6 files changed, 86 insertions(+), 23 deletions(-) diff --git a/assigning.py b/assigning.py index 465b27c..5bc4b08 100644 --- a/assigning.py +++ b/assigning.py @@ -3,13 +3,12 @@ import os from codes_recognizer.rocognizer import recognizer from board import get_shelfs -def assigning(product_code_path): +def assigning(product_code_path, board, shelfs): code = recognizer(product_code_path) - shelfs = get_shelfs() for shelf in shelfs: - if shelf.is_empty(): + if shelf.is_empty: shelf.add_product(code) c = shelf.get_coordinates() break diff --git a/board.py b/board.py index 1d2b2f0..620b934 100644 --- a/board.py +++ b/board.py @@ -4,7 +4,7 @@ from field import Field from shelf import Shelf settings = Settings() -shelfs_o = [] + def create_board(screen): board = [] @@ -24,7 +24,6 @@ def create_board(screen): if field.center_x == shelf[0] and field.center_y == shelf[1]: field.is_shelf = True field.image = pygame.image.load('img/shelf.png') - shelfs_o.append(Shelf(x, y)) row.append(field) board.append(row) @@ -52,6 +51,73 @@ def draw_board(board): field.blitme() -def get_shelfs(): - return shelfs_o +def get_shelfs(board): + field_shelfs = [] + shelfs = [] + for row in board: + for field in row: + if field.isShelf(): + field_shelfs.append(field) + + shelf = Shelf(field_shelfs[0], "01") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[1], "01") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[2], "02") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[3], "02") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[4], "03") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[5], "03") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[6], "04") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[7], "04") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[8], "05") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[9], "05") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[10], "06") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[11], "06") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[12], "07") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[13], "07") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[14], "08") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[15], "08") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[16], "09") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[17], "09") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[18], "10") + shelfs.append(shelf) + + shelf = Shelf(field_shelfs[19], "10") + shelfs.append(shelf) + + return shelfs diff --git a/field.py b/field.py index 552c4e0..3f461f1 100644 --- a/field.py +++ b/field.py @@ -52,3 +52,6 @@ class Field: def addShelf(self): shelf = Shelf(len(self.shelves) + 1) self.shelves.append(shelf) + + def isShelf(self): + return self.is_shelf \ No newline at end of file diff --git a/main.py b/main.py index 7da6a01..dc6c3b7 100644 --- a/main.py +++ b/main.py @@ -23,6 +23,7 @@ def run(): # agent = Agent(screen, 550, 450, "Down") agent = Agent(screen, 950, 950, "Left") board = create_board(screen) + shelfs = get_shelfs(board) my_tree = decision_tree.build_tree(data.learning_data) products_from_supply = [] supply_depot = board[9][0] @@ -77,9 +78,8 @@ def run(): Wyznacza patha do polki na ktora ma polozyc produkt. ''' # list [x, y] - dest_shelf = new_product.shelf() - dest_field = board[dest_shelf[0]][dest_shelf[1]] - path = functions.a_star(board[agent.y][agent.x], dest_field, board) + dest_shelf = new_product.shelf(board) + path = functions.a_star(board[agent.y][agent.x], dest_shelf.get_field(), board) '''''' agent.item = new_product diff --git a/product.py b/product.py index 8c62f06..4e9e521 100644 --- a/product.py +++ b/product.py @@ -31,6 +31,6 @@ class FinalProduct: self.img = create_image(self) - def shelf(self): + def shelf(self, board): print(self.img) - return assigning(self.img); + return assigning(self.img, board); diff --git a/shelf.py b/shelf.py index de8eaea..7018ccb 100644 --- a/shelf.py +++ b/shelf.py @@ -3,9 +3,9 @@ import pygame class Shelf: - def __init__(self, x, y): - self.x = x - self.y = y + def __init__(self, field, color): + self.field = field + self.color = color self.level1 = [] self.level2 = [] self.level3 = [] @@ -22,13 +22,8 @@ class Shelf: def get_product(self): return self.products[0] - def get_coordinates(self): - c = [self.x, self.y] - return c + def get_field(self): + return self.field + - def is_empty(self): - if len(self.products) == 0: - return True - else: - return False