Projekt_KELNER/tiles.py

875 lines
26 KiB
Python
Raw Normal View History

import random
2022-04-05 18:36:43 +02:00
import time
2022-03-21 15:04:00 +01:00
import numpy as np
2022-03-07 10:08:53 +01:00
import pygame
import pytmx
2022-04-05 18:36:43 +02:00
from queue import Queue
2022-05-12 01:21:26 +02:00
import pandas as pd
2022-06-10 04:05:23 +02:00
from pygame import surface
2022-05-12 01:21:26 +02:00
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
import json
2022-05-12 17:06:27 +02:00
import openpyxl
2022-05-26 12:51:36 +02:00
import matplotlib.pyplot as plt
import os
import cv2
from tqdm import tqdm
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Conv2D, MaxPooling2D
import math
2022-03-07 10:08:53 +01:00
pygame.init()
2022-03-21 15:04:00 +01:00
display = pygame.display.set_mode((640, 640))
2022-03-07 10:08:53 +01:00
clock = pygame.time.Clock()
gameMap = pytmx.load_pygame("cafe.tmx")
2022-03-08 11:36:15 +01:00
waiterImg = pygame.image.load("waiter.png")
2022-04-05 18:36:43 +02:00
waiterImgD = pygame.image.load("waiterD.png")
waiterImgL = pygame.image.load("waiterL.png")
waiterImgR = pygame.image.load("waiterR.png")
2022-03-21 15:04:00 +01:00
tableImg = pygame.image.load('table.png')
chairImg = pygame.image.load('chair.png')
2022-06-10 04:05:23 +02:00
messImg = pygame.image.load('mess.png')
messImg2 = pygame.image.load('trash.png')
messImg3 = pygame.image.load('can.png')
clientImg = pygame.image.load('client.png')
image = pygame.image.load('test/0.jpg')
2022-03-21 15:04:00 +01:00
class Waiter:
def __init__(self, loc):
self.loc = loc
def render(self, surface):
surface.blit(waiterImg, (self.loc[0], self.loc[1]))
def handle_events(self):
key = pygame.key.get_pressed()
if key[pygame.K_w] or key[pygame.K_UP]:
self.loc[1] -= 32
elif key[pygame.K_s] or key[pygame.K_DOWN]:
self.loc[1] += 32
elif key[pygame.K_a] or key[pygame.K_LEFT]:
self.loc[0] -= 32
elif key[pygame.K_d] or key[pygame.K_RIGHT]:
self.loc[0] += 32
2022-04-05 18:36:43 +02:00
def up(self):
self.loc[1] -= 32
def down(self):
self.loc[1] += 32
def left(self):
self.loc[0] -= 32
def right(self):
self.loc[0] += 32
class Client:
def __init__(self, loc):
self.loc = loc
def render(self, surface):
surface.blit(clientImg, (self.loc[0], self.loc[1]))
def generate_client():
loc_for_client = []
for i in chairs:
for j in i:
loc_for_client.append(j.loc)
loc = (random.randint(0, len(loc_for_client)))
client_coordinates = (loc_for_client[loc])
return client_coordinates
2022-04-05 18:36:43 +02:00
2022-03-21 15:04:00 +01:00
class Table:
def __init__(self, loc, num):
self.loc = loc
self.number = num
self.num_of_chairs = np.random.randint(1, 5)
2022-03-08 11:36:15 +01:00
2022-03-21 15:04:00 +01:00
def render(self, surface):
surface.blit(tableImg, (self.loc[0], self.loc[1]))
2022-03-08 11:36:15 +01:00
2022-03-21 15:04:00 +01:00
def get_number(self):
return self.number
2022-03-07 10:08:53 +01:00
2022-03-21 15:04:00 +01:00
def get_number_of_chairs(self):
return self.num_of_chairs
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:
answer = True
else:
continue
return answer
2022-03-21 15:04:00 +01:00
class Chair:
def __init__(self, loc):
self.loc = loc
def render(self, surface):
surface.blit(chairImg, (self.loc[0], self.loc[1]))
2022-06-10 04:05:23 +02:00
class Mess:
def __init__(self, loc):
self.loc = loc
def render(self, surface):
surface.blit(messImg, (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),
(table_cor[0] - 32, table_cor[1]),
(table_cor[0] + 32, table_cor[1]))
return pos[k]
def check_collision_with_chair(x, y):
answer = False
for i in chairs:
for j in i:
if j.loc[0] <= x <= j.loc[0] + 32 and j.loc[1] <= y <= j.loc[1] + 32:
answer = True
else:
continue
return answer
2022-03-21 15:04:00 +01:00
2022-03-30 18:24:32 +02:00
class Food:
2022-05-12 01:21:26 +02:00
def __init__(self, name, pos_in_card, price, spiciness, vege, size, allergens, ingridients, drink_in):
2022-03-30 18:24:32 +02:00
self.name = name
2022-05-12 01:21:26 +02:00
self.pos_in_card = pos_in_card
2022-03-30 18:24:32 +02:00
self.price = price
self.spiciness = spiciness
self.vege = vege
self.size = size
self.allergens = allergens
self.ingridients = ingridients
self.drink_in = drink_in
2022-03-30 18:24:32 +02:00
def get_food(self):
return self.name, self.price
2022-03-30 18:24:32 +02:00
class Menu:
def __init__(self, card={}):
self.card = card
def get_menu(self):
return self.card
def add_to_card(self, dish):
self.card[str(len(self.card) + 1)] = dish
2022-03-30 18:24:32 +02:00
class Order(Table):
def __init__(self, status=False, table=0, dishes=[]):
self.table = table
self.dishes = dishes
self.status = status
def take_order(self, foods, table):
self.dishes.append(foods)
self.table = table.number
def deliver(self):
self.status = True
2022-04-05 18:36:43 +02:00
class Graph:
def __init__(self, num_of_nodes, directed=True):
self.m_num_of_nodes = num_of_nodes
self.m_nodes = range(self.m_num_of_nodes)
self.m_directed = directed
self.m_adj_list = {node: set() for node in self.m_nodes}
def add_edge(self, node1, node2, weight=1):
self.m_adj_list[node1].add((node2, weight))
if not self.m_directed:
self.m_adj_list[node2].add((node1, weight))
def print_adj_list(self):
for key in self.m_adj_list.keys():
print("node", key, ": ", self.m_adj_list[key])
def bfs(self, start_node, target_node):
visited = set()
queue = Queue()
queue.put(start_node)
visited.add(start_node)
parent = dict()
parent[start_node] = None
path_found = False
while not queue.empty():
current_node = queue.get()
if current_node == target_node:
path_found = True
break
for (next_node, weight) in self.m_adj_list[current_node]:
if next_node not in visited:
queue.put(next_node)
parent[next_node] = current_node
visited.add(next_node)
path = []
if path_found:
path.append(target_node)
while parent[target_node] is not None:
path.append(parent[target_node])
target_node = parent[target_node]
path.reverse()
return path
2022-04-05 18:36:43 +02:00
def pathFromTo(start, dest):
tab2 = [42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57]
tab4 = [41, 58]
tab3 = []
tab5 = []
for x in range(16):
for num in tab4:
tab5.append(num + x * 20)
for x in range(16):
for num in tab2:
tab3.append(num + x * 20)
graph = Graph(400, directed=False)
for x in tab5:
b = x + 1
c = x + 20
d = x - 20
graph.add_edge(x, b)
graph.add_edge(x, c)
graph.add_edge(x, d)
for x in tab3:
b = x + 1
c = x + 20
d = x - 1
e = x - 20
graph.add_edge(x, b)
graph.add_edge(x, c)
graph.add_edge(x, d)
graph.add_edge(x, e)
graph.add_edge(21, 22)
graph.add_edge(21, 41)
graph.add_edge(378, 358)
graph.add_edge(378, 377)
graph.add_edge(38, 37)
graph.add_edge(38, 58)
graph.add_edge(361, 362)
graph.add_edge(361, 341)
# graph.print_adj_list()
path = []
path = graph.bfs(start, dest)
return path
2022-04-05 18:36:43 +02:00
def numToX(num):
digits = [int(a) for a in str(num)]
if num >= 100:
if digits[1] % 2 == 0:
x = digits[2]
else:
x = digits[2] + 10
else:
if digits[0] % 2 == 0:
x = digits[1]
else:
x = digits[1] + 10
x = x * 32
return x
2022-04-05 18:36:43 +02:00
def numToY(num):
2022-04-24 15:33:59 +02:00
y = (math.floor(num / 20)) * 32
2022-04-05 18:36:43 +02:00
return y
2022-04-05 18:36:43 +02:00
def coordsToNum(coords):
2022-04-24 15:33:59 +02:00
num = ((coords[1] // 32) * 20) + (coords[0] // 32)
2022-04-05 18:36:43 +02:00
return int(num)
2022-04-05 18:36:43 +02:00
def waiterGo(dest):
print("Path: ", (pathFromTo(coordsToNum(waiter.loc), dest)))
go = []
for numb in range(len(pathFromTo(coordsToNum(waiter.loc), dest)) - 1):
go.append(pathFromTo(coordsToNum(waiter.loc), dest)[numb] - pathFromTo(coordsToNum(waiter.loc), dest)[numb + 1])
for x in range(len(go)):
if go[x] == -20:
waiter.down()
display.blit(waiterImgD, (waiter.loc[0], waiter.loc[1]))
2022-04-24 15:33:59 +02:00
# waiter.render(display)
2022-04-05 18:36:43 +02:00
pygame.display.update()
time.sleep(0.2)
elif go[x] == 20:
waiter.up()
display.blit(waiterImg, (waiter.loc[0], waiter.loc[1]))
2022-04-24 15:33:59 +02:00
# waiter.render(display)
2022-04-05 18:36:43 +02:00
pygame.display.update()
time.sleep(0.2)
elif go[x] == 1:
waiter.left()
display.blit(waiterImgL, (waiter.loc[0], waiter.loc[1]))
2022-04-24 15:33:59 +02:00
# waiter.render(display)
2022-04-05 18:36:43 +02:00
pygame.display.update()
time.sleep(0.2)
elif go[x] == -1:
waiter.right()
display.blit(waiterImgR, (waiter.loc[0], waiter.loc[1]))
2022-04-24 15:33:59 +02:00
# waiter.render(display)
2022-04-05 18:36:43 +02:00
pygame.display.update()
time.sleep(0.2)
2022-04-05 18:36:43 +02:00
def mouseToNum():
x = pygame.mouse.get_pos()[0]
y = pygame.mouse.get_pos()[1]
cordTab = [x, y]
squareNum = coordsToNum(cordTab)
return squareNum
2022-04-24 15:33:59 +02:00
class Map:
def __init__(self):
self.arr = np.zeros((20, 20))
self.arr[1:19, 1:19] = 1
def add_chair(self, loc):
self.arr[loc[0] // 32, loc[1] // 32] = 100
2022-06-10 04:05:23 +02:00
def add_mess(self, loc):
self.arr[loc[0] // 32, loc[1] // 32] = 100
2022-04-24 15:33:59 +02:00
def add_table(self, loc):
self.arr[loc[0] // 32, loc[1] // 32] = 200
def get_arr(self):
return self.arr.transpose()
2022-04-24 15:33:59 +02:00
class Tile():
def __init__(self, parent=None, loc=None):
self.parent = parent
self.position = loc
self.g = 0
self.h = 0
self.f = 0
def __eq__(self, other):
return self.position == other.position
2022-04-24 15:33:59 +02:00
def astar(map, start, end):
start_tile = Tile(None, start)
start_tile.g = start_tile.h = start_tile.f = 0
end_tile = Tile(None, end)
end_tile.g = end_tile.h = end_tile.f = 0
open_list = []
closed_list = []
open_list.append(start_tile)
while len(open_list) > 0:
current_tile = open_list[0]
current_index = 0
for index, item in enumerate(open_list):
2022-04-28 21:34:54 +02:00
if item.f <= current_tile.f:
2022-04-24 15:33:59 +02:00
current_tile = item
current_index = index
open_list.pop(current_index)
closed_list.append(current_tile)
if current_tile == end_tile:
path = []
current = current_tile
while current is not None:
path.append(current.position)
current = current.parent
return path[::-1]
children = []
for new_position in [(0, -1), (0, 1), (-1, 0), (1, 0)]:
tile_position = (current_tile.position[0] + new_position[0], current_tile.position[1] + new_position[1])
if map[tile_position[0]][tile_position[1]] == 0:
continue
new_node = Tile(current_tile, tile_position)
children.append(new_node)
2022-04-28 14:42:32 +02:00
2022-04-24 15:33:59 +02:00
for child in children:
2022-04-28 14:42:32 +02:00
skip = False
2022-04-24 15:33:59 +02:00
for closed_child in closed_list:
if child == closed_child:
2022-04-28 14:42:32 +02:00
skip = True
if skip is False:
2022-04-28 21:34:54 +02:00
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])
2022-04-28 14:42:32 +02:00
child.f = child.g + child.h
for open_node in open_list:
if child == open_node and child.g > open_node.g:
continue
open_list.append(child)
2022-04-24 15:33:59 +02:00
2022-05-12 01:21:26 +02:00
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]]
choices = []
for i in possibilities:
choices.append(random.choice(i))
2022-05-12 01:21:26 +02:00
return choices
2022-05-12 01:21:26 +02:00
def evaluate_preferences(preferences):
data = []
if preferences[0] == 30:
data.append(30)
elif preferences[0] == 40:
data.append(40)
elif preferences[0] == 50:
data.append(50)
else:
data.append(random.choice([30, 40, 50]))
if preferences[1] is True:
data.append(1)
elif preferences[1] is False:
data.append(0)
else:
data.append(random.choice([1, 0]))
if preferences[2] is True:
data.append(1)
elif preferences[2] is False:
data.append(0)
else:
data.append(random.choice([1, 0]))
if preferences[3] == 'low':
data.append(30)
elif preferences[3] == 'high':
data.append(50)
else:
data.append(random.choice([30, 50]))
if preferences[4] == 'tomato':
data.append(1)
elif preferences[4] == 'olives':
data.append(3)
elif preferences[4] == 'feta':
data.append(2)
else:
data.append(0)
if preferences[5] == 'salami':
data.append(1)
elif preferences[5] == 'mushrooms':
data.append(2)
elif preferences[5] == 'pineapple':
data.append(3)
elif preferences[5] == 'shrimps':
data.append(4)
elif preferences[5] == 'sausage':
data.append(5)
else:
data.append(0)
if preferences[6] is True:
data.append(1)
elif preferences[6] is False:
data.append(0)
else:
data.append(random.choice([1, 0]))
return data
2022-05-12 14:30:39 +02:00
2022-05-12 01:21:26 +02:00
def choose_pizza(prefernce):
2022-05-12 16:00:04 +02:00
df = pd.read_excel("restaurant.xlsx")
2022-05-12 01:21:26 +02:00
d = {'low': 30, 'high': 50}
df['level of hunger'] = df['level of hunger'].map(d)
d = {'none': 0, 'tomato': 1, 'feta': 2, 'olives': 3}
df['allergy'] = df['allergy'].map(d)
d = {'none': 0, 'salami': 1, 'mushrooms': 2, 'pineapple': 3, 'shrimps': 4, 'sausage': 5}
df['favorite ingridient'] = df['favorite ingridient'].map(d)
d = {'margherita': 0, 'hawajska': 1, 'funghi': 2, 'light': 3, '4 sery': 4, 'pepperoni': 5,
'salami': 6, 'wegetarianska': 7, 'barbecue': 8, 'miesna': 9, 'paprykowa': 10,
'jalapeno': 11, 'barbecue wege': 12, 'kebab': 13, 'grecka': 14, 'piekielna': 15,
'drwala': 16, 'grzybowa': 17, 'staropolska': 18, 'goralska': 19, 'prosciutto': 20,
'broccoli': 21, 'americana': 22, 'farmerska': 23, 'nachos': 24, 'texas': 25,
'kurczak': 26, 'zielona': 27, 'mix': 28}
df['pizza'] = df['pizza'].map(d)
features = ['budget', 'spiciness', 'vege', 'level of hunger', 'allergy', 'favorite ingridient', 'drink in']
x = df[features]
y = df['pizza']
x_train, x_test, y_train, y_test = train_test_split(x, y)
2022-05-12 16:00:04 +02:00
clf = DecisionTreeClassifier(random_state=400)
2022-05-12 01:21:26 +02:00
clf = clf.fit(x_train, y_train)
2022-05-12 17:06:27 +02:00
ans = clf.predict([prefernce])
append_choice(ans, prefernce, d, df)
return ans
2022-05-12 17:06:27 +02:00
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)
2022-05-12 17:06:27 +02:00
def append_choice(ans, pre, d, df):
new_row = pre
new_row.append(list(d.keys())[list(d.values()).index(int(ans))])
if new_row[3] == 30:
new_row[3] = 'low'
if new_row[3] == 50:
new_row[3] = 'high'
if new_row[4] == 0:
new_row[4] = 'none'
if new_row[4] == 1:
new_row[4] = 'tomato'
if new_row[4] == 2:
new_row[4] = 'feta'
if new_row[4] == 3:
new_row[4] = 'olives'
if new_row[5] == 0:
new_row[5] = 'none'
if new_row[5] == 1:
new_row[5] = 'salami'
if new_row[5] == 2:
new_row[5] = 'mushrooms'
if new_row[5] == 3:
new_row[5] = 'pineapple'
if new_row[5] == 4:
new_row[5] = 'shrimps'
if new_row[5] == 5:
new_row[5] = 'sausage'
data = {"budget": new_row[0], "spiciness": new_row[1], "vege": new_row[2], "level of hunger": new_row[3],
"allergy": new_row[4], "favorite ingridient": new_row[5], "drink in": 1, "pizza": new_row[7]}
n_df = pd.DataFrame(data, index=[len(df) + 1])
append_df_to_excel(n_df, "restaurant.xlsx")
2022-05-12 01:21:26 +02:00
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'])
2022-05-12 01:21:26 +02:00
return food
2022-04-28 21:34:54 +02:00
def display_img(surface, image):
surface.blit(image, (120, 120))
2022-06-10 04:05:23 +02:00
def display_sth(surface, image, coordX,coordY):
surface.blit(image, (coordX, coordY))
2022-05-26 12:51:36 +02:00
def create_training_data():
DATADIR = "Images"
CATEGORIES = ["yes", "no"]
IMG_SIZE = 90
training_data = []
for category in CATEGORIES:
path = os.path.join(DATADIR, category)
class_num = CATEGORIES.index(category) # 0 - pepperoni, 1 - no pepperoni
for img in tqdm(os.listdir(path)):
try:
img_array = cv2.imread(os.path.join(path, img), cv2.IMREAD_GRAYSCALE)
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
training_data.append([new_array, class_num])
except Exception as e:
pass
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)
print("Training data created!")
return X, y
2022-05-26 12:51:36 +02:00
def learn_neural_network(X, y):
X = X / 255.0
2022-05-26 12:51:36 +02:00
model = Sequential()
model.add(Conv2D(64, (3, 3), input_shape=X.shape[1:]))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
2022-05-26 21:04:01 +02:00
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
2022-05-26 12:51:36 +02:00
model.add(Flatten())
model.add(Dense(64))
model.add(Dense(1))
model.add(Activation('sigmoid'))
model.compile(loss='binary_crossentropy',
optimizer='adam',
metrics=['accuracy'])
2022-05-26 21:04:01 +02:00
model.fit(X, y, batch_size=32, epochs=10, validation_batch_size=0.1)
2022-05-26 12:51:36 +02:00
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,filepath):
return model.predict([prepare_img(filepath)])
2022-05-26 12:51:36 +02:00
def result(prediction):
2022-05-26 12:51:36 +02:00
if prediction[0][0] >= 0.5:
2022-05-26 21:04:01 +02:00
print(prediction)
2022-05-26 12:51:36 +02:00
print(math.ceil(prediction[0][0]))
print('No pepperoni')
elif prediction[0][0] < 0.5:
2022-05-26 21:04:01 +02:00
print(prediction)
2022-05-26 12:51:36 +02:00
print(math.floor(prediction[0][0]))
print("Pepperoni")
2022-04-24 15:33:59 +02:00
map = Map()
2022-04-05 18:36:43 +02:00
waiter = Waiter([32, 32])
2022-03-21 15:04:00 +01:00
tables = []
tables_coordinates = ((32 * 3, 32 * 2), (32 * 7, 32 * 2), (32 * 12, 32 * 2), (32 * 16, 32 * 2),
(32 * 3, 32 * 6), (32 * 7, 32 * 6), (32 * 12, 32 * 6), (32 * 16, 32 * 6),
(32 * 3, 32 * 13), (32 * 7, 32 * 13), (32 * 12, 32 * 13), (32 * 16, 32 * 13),
(32 * 3, 32 * 17), (32 * 7, 32 * 17), (32 * 12, 32 * 17), (32 * 16, 32 * 17))
chairs = []
2022-03-21 15:04:00 +01:00
for i in range(16):
tables.append(Table(tables_coordinates[i], i))
arr = []
for j in range(0, tables[i].get_number_of_chairs()):
arr.append(Chair(pos_of_chair(tables_coordinates[i], j)))
2022-04-24 15:33:59 +02:00
map.add_chair(Chair(pos_of_chair(tables_coordinates[i], j)).loc)
2022-03-21 15:04:00 +01:00
chairs.append(arr)
2022-04-24 15:33:59 +02:00
for table in tables:
map.add_table(table.loc)
2022-03-21 15:04:00 +01:00
client = Client(generate_client())
2022-05-26 21:04:01 +02:00
neural_prediction_in = False
2022-06-10 04:05:23 +02:00
restaurantIsClean = False
howManyMesses = random.randint(8, 12)
messesArray = [[0 for x in range(2)] for y in range(howManyMesses)]
for i in range(howManyMesses):
whereMessX = random.randint(1, 18)
whereMessY = random.randint(1, 18)
messesArray[i][0] = whereMessX
messesArray[i][1] = whereMessY
#messesArray = [[3, 14], [7, 17], [10, 9], [16, 10], [12, 18], [4, 11], [11, 14], [3, 5], [7, 18], [6, 13], [10, 8], [13, 16], [10, 6], [8, 6], [4, 10], [14, 6], [18, 1], [12, 17], [10, 11], [18, 3]]
#messesArray = [[9, 5], [16, 5], [5, 5], [10, 13], [3, 10], [8, 15], [13, 8], [14, 14], [12, 12], [3, 1]]
#messesArray = [[12, 8], [15, 9], [14, 9], [13, 6], [7, 7], [9, 7], [2, 15], [18, 16], [13, 15], [8, 18], [7, 14]]
#good example below
#messesArray = [[10, 12], [5, 17], [18, 3], [13, 2], [4, 5], [7, 4], [16, 5], [3, 2], [14, 17]]
#messesArray = [[12, 3], [11, 9], [13, 15], [3, 5], [2, 14], [17, 15], [1, 12], [14, 9], [7, 1], [7, 6]]
#this one below!
#messesArray = [[2, 15], [11, 9], [5, 11], [17, 1], [15, 7], [14, 10], [18, 8], [2, 9], [6, 4], [18, 10]]
#print(messesArray)
pygame.font.init()
default_font = pygame.font.get_default_font()
font_renderer = pygame.font.Font(default_font, 12)
def main(trashesList):
2022-04-24 15:33:59 +02:00
direction = []
first_time = True
number = 0
2022-04-05 18:36:43 +02:00
while True:
clock.tick(10)
keys = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
if keys[pygame.K_ESCAPE]:
2022-03-07 10:08:53 +01:00
quit()
2022-04-05 18:36:43 +02:00
for layer in gameMap.visible_layers:
for x, y, gid, in layer:
tile = gameMap.get_tile_image_by_gid(gid)
if tile is not None:
display.blit(tile, (x * gameMap.tilewidth, y * gameMap.tileheight))
2022-06-10 04:05:23 +02:00
key = pygame.key.get_pressed()
messesToDisplay = messesArray
for i in range (len(messesToDisplay)):
currentMessX = messesToDisplay[i][0]
currentMessY = messesToDisplay[i][1]
if i % 3 == 0:
display.blit(messImg, (currentMessX * 32, currentMessY * 32))
elif i % 3 == 1:
display.blit(messImg2, (currentMessX * 32, currentMessY * 32))
elif i % 3 == 2:
display.blit(messImg3, (currentMessX * 32, currentMessY * 32))
2022-04-05 18:36:43 +02:00
waiter.handle_events()
for table in tables:
table.render(display)
for chair_list in chairs:
for chair in chair_list:
chair.render(display)
2022-04-05 18:36:43 +02:00
left, middle, right = pygame.mouse.get_pressed()
if key[pygame.K_e]:
X, y = create_training_data()
model = learn_neural_network(X,y)
2022-05-26 12:51:36 +02:00
if middle:
2022-04-05 18:36:43 +02:00
waiterGo(mouseToNum())
2022-04-24 15:33:59 +02:00
elif right:
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):
print("I can't go there")
break
goal = (x // 32, y // 32)
route = astar(map.get_arr(), (waiter.loc[1] // 32, waiter.loc[0] // 32), goal)
direction = [(x[1] - y[1], x[0] - y[0]) for x, y in zip(route[1:], route)]
break
2022-05-26 12:51:36 +02:00
elif left:
if client.loc[0] in [64, 128, 192, 256, 352, 416, 480, 544]:
while True:
x = client.loc[1] - 32
y = client.loc[0]
goal = (x // 32, y // 32)
route = astar(map.get_arr(), (waiter.loc[1] // 32, waiter.loc[0] // 32), goal)
direction = [(x[1] - y[1], x[0] - y[0]) for x, y in zip(route[1:], route)]
break
elif client.loc[0] in [96, 224, 384, 512]:
while True:
x = client.loc[1]
y = client.loc[0] - 32
goal = (x // 32, y // 32)
route = astar(map.get_arr(), (waiter.loc[1] // 32, waiter.loc[0] // 32), goal)
direction = [(x[1] - y[1], x[0] - y[0]) for x, y in zip(route[1:], route)]
break
2022-05-12 16:00:04 +02:00
print()
print("Hello Sir, tell me yours preferences")
print(
"Pass: 'budget', 'spiciness', 'vege', 'level_of_hunger', 'allergy', 'favorite_ingridient', 'drink_in'\n")
print("Here is my list of preferences")
2022-05-12 01:21:26 +02:00
ingridients = tell_preferences()
print(ingridients)
print()
2022-05-12 16:00:04 +02:00
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))
2022-04-24 15:33:59 +02:00
if len(direction) > 0:
d = direction.pop(0)
if d[0] == 1:
waiter.right()
elif d[0] == -1:
waiter.left()
elif d[1] == 1:
waiter.down()
elif d[1] == -1:
waiter.up()
2022-04-05 18:36:43 +02:00
key = pygame.key.get_pressed()
if key[pygame.K_p]:
pass
waiter.render(display)
client.render(display)
if waiter.loc == [576, 32]:
if first_time:
number = np.random.randint(20)
path = ('test/' + str(number) + '.jpg')
image = pygame.image.load(path)
first_time = False
display_img(display, image)
2022-05-26 21:04:01 +02:00
if neural_prediction_in is False:
prediction = predict(model, path)
result(prediction)
neural_prediction_in = True
else:
first_time = True
2022-05-26 21:04:01 +02:00
neural_prediction_in = False
2022-06-10 04:05:23 +02:00
font = pygame.font.SysFont('Arial', 18, bold=True)
trashesArray = trashesList
trashesLen = len(trashesArray)
#pygame.draw.line(display, (15, 0, 148), (32, 32), (numToX(trashesArray[0]), numToY(trashesArray[0])), 4)
for i in range(len(trashesArray)-1):
img = font.render(str(i), True,
pygame.Color(255, 255, 255),
pygame.Color(10, 148, 0))
pygame.draw.line(display, (10, 148, 0), (numToX(trashesArray[i]),numToY(trashesArray[i])), (numToX(trashesArray[i+1]),numToY(trashesArray[i+1])), 4)
display_sth(display, img, numToX(trashesArray[i]), numToY(trashesArray[i]))
img = font.render(str(trashesLen-1), True, pygame.Color(255, 255, 255), pygame.Color(10, 148, 0))
display_sth(display, img, numToX(trashesArray[trashesLen-1]), numToY(trashesArray[trashesLen-1]))
2022-04-05 18:36:43 +02:00
pygame.display.update()
2022-03-07 10:08:53 +01:00
2022-03-21 15:04:00 +01:00
2022-04-05 18:36:43 +02:00
if __name__ == '__main__':
main()