diff --git a/tiles.py b/tiles.py index 49ffaac..ecbca20 100644 --- a/tiles.py +++ b/tiles.py @@ -18,7 +18,6 @@ from keras.layers import Dense, Dropout, Activation, Flatten from keras.layers import Conv2D, MaxPooling2D import math - pygame.init() display = pygame.display.set_mode((640, 640)) @@ -31,6 +30,7 @@ waiterImgR = pygame.image.load("waiterR.png") tableImg = pygame.image.load('table.png') chairImg = pygame.image.load('chair.png') clientImg = pygame.image.load('client.png') +image = pygame.image.load('test/0.jpg') class Waiter: def __init__(self, loc): @@ -62,6 +62,7 @@ class Waiter: def right(self): self.loc[0] += 32 + class Client: def __init__(self, loc): self.loc = loc @@ -69,6 +70,7 @@ class Client: def render(self, surface): surface.blit(clientImg, (self.loc[0], self.loc[1])) + def generate_client(): loc_for_client = [] for i in chairs: @@ -78,6 +80,7 @@ def generate_client(): client_coordinates = (loc_for_client[loc]) return client_coordinates + class Table: def __init__(self, loc, num): self.loc = loc @@ -93,7 +96,8 @@ class Table: def get_number_of_chairs(self): return self.num_of_chairs -def check_collision_with_table(x,y): + +def check_collision_with_table(x, y): answer = False for i in tables_coordinates: if i[0] <= x <= i[0] + 32 and i[1] <= y <= i[1] + 32: @@ -110,6 +114,7 @@ class Chair: def render(self, surface): surface.blit(chairImg, (self.loc[0], self.loc[1])) + def pos_of_chair(table_cor, k): pos = ((table_cor[0], table_cor[1] - 32), (table_cor[0], table_cor[1] + 32), @@ -117,7 +122,8 @@ def pos_of_chair(table_cor, k): (table_cor[0] + 32, table_cor[1])) return pos[k] -def check_collision_with_chair(x,y): + +def check_collision_with_chair(x, y): answer = False for i in chairs: for j in i: @@ -143,6 +149,7 @@ class Food: def get_food(self): return self.name, self.price + class Menu: def __init__(self, card={}): self.card = card @@ -153,6 +160,7 @@ class Menu: def add_to_card(self, dish): self.card[str(len(self.card) + 1)] = dish + class Order(Table): def __init__(self, status=False, table=0, dishes=[]): self.table = table @@ -166,6 +174,7 @@ class Order(Table): def deliver(self): self.status = True + class Graph: def __init__(self, num_of_nodes, directed=True): self.m_num_of_nodes = num_of_nodes @@ -209,6 +218,7 @@ class Graph: path.reverse() return path + def pathFromTo(start, dest): tab2 = [42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57] tab4 = [41, 58] @@ -250,6 +260,7 @@ def pathFromTo(start, dest): path = graph.bfs(start, dest) return path + def numToX(num): digits = [int(a) for a in str(num)] if num >= 100: @@ -265,14 +276,17 @@ def numToX(num): x = x * 32 return x + def numToY(num): y = (math.floor(num / 20)) * 32 return y + def coordsToNum(coords): num = ((coords[1] // 32) * 20) + (coords[0] // 32) return int(num) + def waiterGo(dest): print("Path: ", (pathFromTo(coordsToNum(waiter.loc), dest))) go = [] @@ -305,6 +319,7 @@ def waiterGo(dest): pygame.display.update() time.sleep(0.2) + def mouseToNum(): x = pygame.mouse.get_pos()[0] y = pygame.mouse.get_pos()[1] @@ -312,6 +327,7 @@ def mouseToNum(): squareNum = coordsToNum(cordTab) return squareNum + class Map: def __init__(self): self.arr = np.zeros((20, 20)) @@ -326,6 +342,7 @@ class Map: def get_arr(self): return self.arr.transpose() + class Tile(): def __init__(self, parent=None, loc=None): self.parent = parent @@ -337,6 +354,7 @@ class Tile(): def __eq__(self, other): return self.position == other.position + def astar(map, start, end): start_tile = Tile(None, start) start_tile.g = start_tile.h = start_tile.f = 0 @@ -379,7 +397,8 @@ def astar(map, start, end): skip = True if skip is False: child.g = current_tile.g + map[child.position[0]][child.position[1]] - child.h = np.absolute(child.position[0] - end_tile.position[0]) + np.absolute(child.position[1] - end_tile.position[1]) + child.h = np.absolute(child.position[0] - end_tile.position[0]) + np.absolute( + child.position[1] - end_tile.position[1]) child.f = child.g + child.h for open_node in open_list: if child == open_node and child.g > open_node.g: @@ -388,19 +407,20 @@ def astar(map, start, end): def tell_preferences(): - possibilities = [[30, 40 ,50, None], - [True, False, None], - [True, False, None], - ["high", "low", None], - ["tomato", "olives", "feta", None], - ["sausage", "pineapple", "mushrooms", "shrimps", "salami", None], - [True, False, None]] + possibilities = [[30, 40, 50, None], + [True, False, None], + [True, False, None], + ["high", "low", None], + ["tomato", "olives", "feta", None], + ["sausage", "pineapple", "mushrooms", "shrimps", "salami", None], + [True, False, None]] choices = [] for i in possibilities: choices.append(random.choice(i)) return choices + def evaluate_preferences(preferences): data = [] if preferences[0] == 30: @@ -499,11 +519,13 @@ def choose_pizza(prefernce): return ans + def append_df_to_excel(df, excel_path): df_excel = pd.read_excel(excel_path) result = pd.concat([df_excel, df], ignore_index=True) result.to_excel(excel_path, index=False) + def append_choice(ans, pre, d, df): new_row = pre new_row.append(list(d.keys())[list(d.values()).index(int(ans))]) @@ -540,15 +562,21 @@ def append_choice(ans, pre, d, df): n_df = pd.DataFrame(data, index=[len(df) + 1]) append_df_to_excel(n_df, "restaurant.xlsx") + def get_pizza(number): with open("dishes.json") as f: data = json.load(f) for i in data: if i["pos_in_card"] == int(number): - food = Food(i['name'], i['pos_in_card'], i['price'], i['spiciness'], i['vege'], i['size'], i['allergens'], i['ingridients'], i['drink_in']) + food = Food(i['name'], i['pos_in_card'], i['price'], i['spiciness'], i['vege'], i['size'], i['allergens'], + i['ingridients'], i['drink_in']) return food -#network + +def display_img(surface, image): + surface.blit(image, (120, 120)) + + def create_training_data(): DATADIR = "Images" CATEGORIES = ["yes", "no"] @@ -575,10 +603,11 @@ def create_training_data(): y = np.array(y) print("Training data created!") - return X,y + return X, y -def learn_neural_network(X,y): - X = X/255.0 + +def learn_neural_network(X, y): + X = X / 255.0 model = Sequential() @@ -605,16 +634,19 @@ def learn_neural_network(X,y): return model + def prepare_img(filepath): IMG_SIZE = 90 img_array = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE) new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE)) return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1) / 255 + def predict(model): return model.predict([prepare_img('directory')]) -def reusult(prediction): + +def result(prediction): if prediction[0][0] >= 0.5: print(math.ceil(prediction[0][0])) print('No pepperoni') @@ -623,16 +655,30 @@ def reusult(prediction): print("Pepperoni") +#####################neural network############################## +DATADIR = "C:/Datasets/Ingridients" +CATEGORIES = ["yes", "no"] +IMG_SIZE = 90 +training_data = [] +create_training_data() +X = [] +y = [] +for features, label in training_data: + X.append(features) + y.append(label) +X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE, 1) +y = np.array(y) +""" +m = learn_neural_network(X, y) +prediction = m.predict([prepare_img('p1.jpg')]) +print(prediction[0][0]) +result(prediction) +""" - - - - - - +####################################################### map = Map() waiter = Waiter([32, 32]) @@ -656,8 +702,11 @@ for table in tables: client = Client(generate_client()) + def main(): direction = [] + first_time = True + number = 0 while True: clock.tick(10) @@ -681,6 +730,7 @@ def main(): for chair_list in chairs: for chair in chair_list: chair.render(display) + key = pygame.key.get_pressed() left, middle, right = pygame.mouse.get_pressed() if middle: @@ -689,7 +739,9 @@ def main(): while True: x = pygame.mouse.get_pos()[1] y = pygame.mouse.get_pos()[0] - if y > 608 or y < 32 or x > 608 or x < 32 or check_collision_with_table(y,x) or check_collision_with_chair(y, x): + if y > 608 or y < 32 or x > 608 or x < 32 or check_collision_with_table(y, + x) or check_collision_with_chair( + y, x): print("I can't go there") break goal = (x // 32, y // 32) @@ -715,16 +767,18 @@ def main(): break print() print("Hello Sir, tell me yours preferences") - print("Pass: 'budget', 'spiciness', 'vege', 'level_of_hunger', 'allergy', 'favorite_ingridient', 'drink_in'\n") + print( + "Pass: 'budget', 'spiciness', 'vege', 'level_of_hunger', 'allergy', 'favorite_ingridient', 'drink_in'\n") print("Here is my list of preferences") ingridients = tell_preferences() print(ingridients) print() pizza = get_pizza(choose_pizza(evaluate_preferences(ingridients))) print("Our proposition:") - print("Name = {}\nprice = {}\nspiciness = {}\nvege = {}\nsize = {}\nallergens = {}\ningridients = {}\ndrink_in = {}\n" - .format(pizza.name,pizza.price, pizza.spiciness,pizza.vege,pizza.size,pizza.allergens,pizza.ingridients,pizza.drink_in)) - + print( + "Name = {}\nprice = {}\nspiciness = {}\nvege = {}\nsize = {}\nallergens = {}\ningridients = {}\ndrink_in = {}\n" + .format(pizza.name, pizza.price, pizza.spiciness, pizza.vege, pizza.size, pizza.allergens, + pizza.ingridients, pizza.drink_in)) if len(direction) > 0: d = direction.pop(0) @@ -742,6 +796,16 @@ def main(): pass waiter.render(display) client.render(display) + + if waiter.loc == [576, 32]: + if first_time: + number = np.random.randint(20) + image = pygame.image.load('test/' + str(number) + '.jpg') + first_time = False + display_img(display, image) + else: + first_time = True + pygame.display.update()