2020-03-23 10:49:27 +01:00
|
|
|
import pygame
|
2020-04-05 13:50:07 +02:00
|
|
|
import random
|
|
|
|
import time
|
2020-04-05 16:53:59 +02:00
|
|
|
import queue
|
2020-04-26 17:55:59 +02:00
|
|
|
import math
|
2020-04-27 11:43:58 +02:00
|
|
|
from tkinter import messagebox
|
|
|
|
import tkinter as tk
|
|
|
|
root = tk.Tk()
|
|
|
|
root.withdraw() #ukrycie okna tworzonego przez tkinter
|
2020-03-23 10:49:27 +01:00
|
|
|
|
2020-04-05 13:50:07 +02:00
|
|
|
pygame.init()
|
2020-03-23 10:49:27 +01:00
|
|
|
|
2020-04-05 16:53:59 +02:00
|
|
|
|
2020-04-26 17:55:59 +02:00
|
|
|
def heuristic(current, goal):
|
|
|
|
dx = abs(current[0] - goal[0])
|
|
|
|
dy = abs(current[1] - goal[1])
|
|
|
|
return math.sqrt(dx * dx + dy * dy)
|
|
|
|
|
|
|
|
|
|
|
|
class Node():
|
|
|
|
def __init__(self, parent = None, position = None):
|
|
|
|
self.parent = parent
|
|
|
|
self.position = position
|
|
|
|
|
|
|
|
self.g = 0
|
|
|
|
self.h = 0
|
|
|
|
self.f = 0
|
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
return self.position == other.position
|
|
|
|
|
|
|
|
|
|
|
|
def aStar(start, end):
|
|
|
|
if end in cantwalk:
|
|
|
|
print("Wybrano nieodpowiednie pole!")
|
|
|
|
return []
|
|
|
|
|
|
|
|
start_node = Node(None, start)
|
|
|
|
start_node.g = start_node.h = start_node.f = 0
|
|
|
|
end_node = Node(None, end)
|
|
|
|
end_node.g = end_node.h = end_node.f = 0
|
|
|
|
|
|
|
|
open_list = []
|
|
|
|
closed_list = []
|
|
|
|
open_list.append(start_node)
|
|
|
|
|
|
|
|
while len(open_list) > 0:
|
|
|
|
current_node = open_list[0]
|
|
|
|
current_index = 0
|
|
|
|
for index, item in enumerate(open_list):
|
|
|
|
if item.f < current_node.f:
|
|
|
|
current_node = item
|
|
|
|
current_index = index
|
|
|
|
|
|
|
|
open_list.pop(current_index)
|
|
|
|
closed_list.append(current_node)
|
|
|
|
|
|
|
|
if current_node == end_node:
|
|
|
|
path = []
|
|
|
|
current = current_node
|
|
|
|
while current is not None:
|
|
|
|
path.append(current.position)
|
|
|
|
current = current.parent
|
|
|
|
return list(map(lambda t: (t[0], t[1]), path[::-1])) #zwraca odwróconą ściezkę
|
|
|
|
|
|
|
|
children = []
|
|
|
|
# można dodać (-1, -1), (-1, 1), (1, -1), (1, 1) dla poruszania się po przekątnej
|
|
|
|
for new_position in [(0, -1), (0, 1), (-1, 0), (1, 0)]:
|
|
|
|
node_position = (current_node.position[0] + new_position[0], current_node.position[1]
|
|
|
|
+ new_position[1])
|
|
|
|
|
|
|
|
if node_position[0] >= (rows - 1) or node_position[0] <= 0 or node_position[1] >= (rows - 1) \
|
|
|
|
or node_position[1] <= 0: #spr. czy w kracie
|
|
|
|
continue
|
|
|
|
|
|
|
|
if node_position in cantwalk: #spr. czy można przejść
|
|
|
|
continue
|
|
|
|
|
|
|
|
new_node = Node(current_node, node_position)
|
|
|
|
children.append(new_node)
|
|
|
|
|
|
|
|
didBreak = False
|
|
|
|
for child in children:
|
|
|
|
didBreak = False
|
|
|
|
for closed_child in closed_list:
|
|
|
|
if child == closed_child:
|
|
|
|
didBreak = True
|
|
|
|
break
|
|
|
|
|
|
|
|
if didBreak:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if child.position in cantwalk:
|
|
|
|
child.g = current_node.g + 99999
|
|
|
|
elif child.position in puddles:
|
|
|
|
child.g = current_node.g + 3
|
|
|
|
else:
|
|
|
|
child.g = current_node.g + 1
|
|
|
|
|
|
|
|
child.h = heuristic(child.position, end_node.position)
|
|
|
|
child.f = child.g + child.h
|
|
|
|
|
|
|
|
for open_node in open_list:
|
|
|
|
if child == open_node and child.g > open_node.g:
|
|
|
|
didBreak = True
|
|
|
|
break
|
|
|
|
|
|
|
|
if didBreak:
|
|
|
|
continue
|
|
|
|
|
|
|
|
open_list.append(child)
|
|
|
|
|
|
|
|
|
2020-04-05 14:04:55 +02:00
|
|
|
class Dish(object):
|
2020-04-05 18:50:57 +02:00
|
|
|
def __init__(self, dishName, prepTime, eatTime, price):
|
2020-04-05 14:04:55 +02:00
|
|
|
self.dishName = dishName
|
|
|
|
self.preparationTime = prepTime
|
2020-04-05 16:53:59 +02:00
|
|
|
self.eatingTime = eatTime
|
2020-04-05 18:50:57 +02:00
|
|
|
self.price = price
|
2020-04-05 16:53:59 +02:00
|
|
|
|
2020-04-05 14:04:55 +02:00
|
|
|
|
|
|
|
class Plate(object):
|
|
|
|
def __init__(self, dish):
|
|
|
|
self.dishName = dish.dishName
|
|
|
|
self.isEmpty = False
|
|
|
|
self.preparationTime = dish.preparationTime
|
2020-04-05 16:53:59 +02:00
|
|
|
self.eatingTime = dish.eatingTime
|
2020-04-05 19:28:01 +02:00
|
|
|
self.price = dish.price
|
2020-04-05 14:04:55 +02:00
|
|
|
|
|
|
|
def eat(self):
|
2020-04-05 16:53:59 +02:00
|
|
|
time.sleep(self.eatingTime)
|
2020-04-05 14:04:55 +02:00
|
|
|
self.isEmpty = True #zjadanie dania jest oznaczeniem talerza jako pusty (metoda będzie wywoływana przez klienta)
|
|
|
|
|
2020-04-05 16:53:59 +02:00
|
|
|
|
|
|
|
class Kitchen(object):
|
2020-04-25 14:31:02 +02:00
|
|
|
def __init__(self, pos):
|
|
|
|
self.readyDishes = queue.Queue(32) #kolejka o maksymalnej długości 32
|
|
|
|
self.orders = queue.Queue(32) #wyskakiwał mi tu błąd - poprawiłam na dużą literę i jest ok
|
|
|
|
self.pos = pos
|
2020-04-05 16:53:59 +02:00
|
|
|
|
|
|
|
def makeDish(self):
|
|
|
|
if not self.orders.empty():
|
|
|
|
plate = self.orders.get()
|
|
|
|
time.sleep(plate.preparationTime) #kuchnia przygotowuje danie przez określony czas
|
|
|
|
self.readyDishes.put(plate)
|
|
|
|
|
2020-04-05 19:28:01 +02:00
|
|
|
def giveDish(self):
|
|
|
|
if not self.readyDishes.empty():
|
|
|
|
plate = self.readyDishes.get()
|
|
|
|
return plate
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2020-04-25 14:31:02 +02:00
|
|
|
def draw(self, surface):
|
|
|
|
image1 = pygame.image.load(r'kitchen1.png')
|
|
|
|
image1 = pygame.transform.scale(image1, (sizeBetween - 1, sizeBetween - 1))
|
|
|
|
surface.blit(image1, (13*sizeBetween+1, 0*sizeBetween+1))
|
|
|
|
|
|
|
|
image2 = pygame.image.load(r'kitchen2.png')
|
|
|
|
image2 = pygame.transform.scale(image2, (sizeBetween - 1, sizeBetween - 1))
|
|
|
|
surface.blit(image2, (14*sizeBetween+1, 0*sizeBetween+1))
|
|
|
|
|
|
|
|
image3 = pygame.image.load(r'kitchen3.png')
|
|
|
|
image3 = pygame.transform.scale(image3, (sizeBetween - 1, sizeBetween - 1))
|
|
|
|
surface.blit(image3, (13*sizeBetween+1, 1*sizeBetween+1))
|
|
|
|
|
|
|
|
image4 = pygame.image.load(r'kitchen4.png')
|
|
|
|
image4 = pygame.transform.scale(image4, (sizeBetween - 1, sizeBetween - 1))
|
|
|
|
surface.blit(image4, (14*sizeBetween+1, 1*sizeBetween+1))
|
|
|
|
|
2020-04-05 16:53:59 +02:00
|
|
|
|
|
|
|
class Client(object):
|
|
|
|
def __init__(self, age, sex, budget):
|
|
|
|
self.age = age
|
|
|
|
self.sex = sex
|
|
|
|
self.myPlate = None
|
|
|
|
self.budget = budget
|
2020-04-05 18:50:57 +02:00
|
|
|
self.myTable = 0 #domyślnie klient nie siedzi przy żadnym stole
|
2020-04-05 16:53:59 +02:00
|
|
|
|
|
|
|
def takePlateAndEat(self, plate):
|
|
|
|
self.myPlate = plate
|
|
|
|
plate.eat()
|
|
|
|
|
2020-04-05 18:50:57 +02:00
|
|
|
def takeASeat(self, table):
|
|
|
|
self.myTable = table
|
2020-04-05 16:53:59 +02:00
|
|
|
|
2020-04-26 17:55:59 +02:00
|
|
|
|
2020-03-23 10:49:27 +01:00
|
|
|
class Table(object):
|
2020-04-05 18:50:57 +02:00
|
|
|
def __init__(self, pos, capacity):
|
2020-03-23 10:49:27 +01:00
|
|
|
self.pos = pos
|
2020-04-05 18:50:57 +02:00
|
|
|
self.capacity = capacity
|
2020-03-23 10:49:27 +01:00
|
|
|
|
2020-04-05 14:04:55 +02:00
|
|
|
def move(self, newx, newy): #metoda do ustawiania stołów poprzez podanie nowych współrzędnych
|
2020-03-23 10:49:27 +01:00
|
|
|
self.pos[0] = newx
|
|
|
|
self.pos[1] = newy
|
|
|
|
|
|
|
|
def draw(self, surface):
|
|
|
|
image = pygame.image.load(r'Table-croped.png')
|
|
|
|
image = pygame.transform.scale(image, (sizeBetween - 1, sizeBetween - 1))
|
|
|
|
|
|
|
|
i = self.pos[0]
|
|
|
|
j = self.pos[1]
|
|
|
|
|
|
|
|
surface.blit(image, (i*sizeBetween+1, j*sizeBetween+1))
|
|
|
|
|
|
|
|
|
|
|
|
class Waiter(object):
|
2020-04-25 14:31:02 +02:00
|
|
|
def __init__(self, color, pos, direction):
|
2020-03-23 10:49:27 +01:00
|
|
|
self.color = color
|
2020-04-05 13:50:07 +02:00
|
|
|
self.pos = pos #pozycja agenta, zapisana w formie dwuelementowej listy
|
2020-04-26 17:55:59 +02:00
|
|
|
self.posx = pos[0]
|
|
|
|
self.posy = pos[1]
|
2020-04-05 13:50:07 +02:00
|
|
|
self.dirnx = 0 #zmienne dirnx i dirny używane są do ruchu bota i ustalania, w którą stronę jest zwrócony
|
2020-03-23 10:49:27 +01:00
|
|
|
self.dirny = 1
|
2020-04-05 16:57:20 +02:00
|
|
|
self.plates = [] #lista niesionych przez agenta talerzy, planowo lista par: (talerz, klient)
|
2020-04-25 14:31:02 +02:00
|
|
|
self.direction = direction #kierunek, w ktory jest skierowany bot
|
2020-04-26 20:53:57 +02:00
|
|
|
self.currentRotation = 0
|
|
|
|
self.rotate = "forward"
|
|
|
|
self.rotationNumber = 0
|
2020-04-25 14:31:02 +02:00
|
|
|
|
|
|
|
def moveRandomly(self, noWalkable):
|
2020-04-05 13:50:07 +02:00
|
|
|
rand = random.randrange(1, 5, 1) #losuje w zakresie 1-4
|
2020-04-25 14:31:02 +02:00
|
|
|
#print(rand)
|
2020-04-05 13:50:07 +02:00
|
|
|
|
|
|
|
if rand == 1:
|
|
|
|
self.dirnx = -1
|
|
|
|
self.dirny = 0
|
2020-04-25 14:31:02 +02:00
|
|
|
self.direction = 'left'
|
|
|
|
if self.pos[0] == 0 or ([self.pos[0] + self.dirnx, self.pos[1] + self.dirny] in noWalkable): #zabezpieczenie przed wyjściem bota poza obszar okna w ruchu losowym
|
|
|
|
self.dirnx *= (-1) #oraz w miejsce, na ktore nie moze wejsc (stoły, kuchania)
|
|
|
|
self.direction = 'right'
|
|
|
|
self.pos = [self.pos[0] + self.dirnx, self.pos[1] + self.dirny]
|
|
|
|
|
2020-04-05 13:50:07 +02:00
|
|
|
elif rand == 2:
|
|
|
|
self.dirnx = 1
|
|
|
|
self.dirny = 0
|
2020-04-25 14:31:02 +02:00
|
|
|
self.direction = 'right'
|
|
|
|
if self.pos[0] == 14 or ([self.pos[0] + self.dirnx, self.pos[1] + self.dirny] in noWalkable):
|
2020-04-05 13:50:07 +02:00
|
|
|
self.dirnx *= (-1)
|
2020-04-25 14:31:02 +02:00
|
|
|
self.direction = 'left'
|
|
|
|
self.pos = [self.pos[0] + self.dirnx, self.pos[1] + self.dirny]
|
|
|
|
|
2020-04-05 13:50:07 +02:00
|
|
|
elif rand == 3:
|
|
|
|
self.dirnx = 0
|
|
|
|
self.dirny = -1
|
2020-04-25 14:31:02 +02:00
|
|
|
if self.pos[1] == 0 or ([self.pos[0] + self.dirnx, self.pos[1] + self.dirny] in noWalkable):
|
2020-04-05 13:50:07 +02:00
|
|
|
self.dirny *= (-1)
|
2020-04-25 14:31:02 +02:00
|
|
|
self.pos = [self.pos[0] + self.dirnx, self.pos[1] + self.dirny]
|
|
|
|
|
2020-04-05 13:50:07 +02:00
|
|
|
elif rand == 4:
|
|
|
|
self.dirnx = 0
|
|
|
|
self.dirny = 1
|
2020-04-25 14:31:02 +02:00
|
|
|
if self.pos[1] == 14 or ([self.pos[0] + self.dirnx, self.pos[1] + self.dirny] in noWalkable):
|
2020-04-05 13:50:07 +02:00
|
|
|
self.dirny *= (-1)
|
2020-04-25 14:31:02 +02:00
|
|
|
self.pos = [self.pos[0] + self.dirnx, self.pos[1] + self.dirny]
|
2020-04-05 13:50:07 +02:00
|
|
|
|
2020-04-25 14:31:02 +02:00
|
|
|
def moveWithKeyboard(self, noWalkable): #funkcja testowa - bot sterowany z klawiatury
|
2020-03-23 10:49:27 +01:00
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
pygame.quit()
|
|
|
|
quit()
|
|
|
|
|
|
|
|
keys = pygame.key.get_pressed()
|
|
|
|
|
|
|
|
for key in keys:
|
|
|
|
if keys[pygame.K_LEFT]:
|
|
|
|
self.dirnx = -1
|
|
|
|
self.dirny = 0
|
2020-04-25 14:31:02 +02:00
|
|
|
self.direction = 'left'
|
|
|
|
if self.pos[0] == 0 or ([self.pos[0] + self.dirnx, self.pos[1] + self.dirny] in noWalkable): # zabezpieczenie przed wyjściem bota poza obszar okna w ruchu losowym
|
|
|
|
#self.dirnx *= (-1)
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
self.pos = [self.pos[0] + self.dirnx, self.pos[1] + self.dirny]
|
|
|
|
break
|
2020-03-23 10:49:27 +01:00
|
|
|
# te break musiałam dodać, bo w przeciwnym wypadku zamiast jednego kroku robił 303 - jeden za drugim
|
|
|
|
# nie wiem dlaczego tak było, po zmianie sterowania z klawiatury na bota samego w sobie nie powinno
|
|
|
|
# być z tym problemów, to jest na razie tylko, żeby pokazać, że ten ruch jest
|
|
|
|
|
|
|
|
elif keys[pygame.K_RIGHT]:
|
|
|
|
self.dirnx = 1
|
|
|
|
self.dirny = 0
|
2020-04-25 14:31:02 +02:00
|
|
|
self.direction = 'right'
|
|
|
|
if self.pos[0] == 14 or ([self.pos[0] + self.dirnx, self.pos[1] + self.dirny] in noWalkable):
|
|
|
|
#self.dirnx *= (-1)
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
self.pos = [self.pos[0] + self.dirnx, self.pos[1] + self.dirny]
|
|
|
|
break
|
2020-03-23 10:49:27 +01:00
|
|
|
|
|
|
|
elif keys[pygame.K_UP]:
|
|
|
|
self.dirnx = 0
|
|
|
|
self.dirny = -1
|
2020-04-25 14:31:02 +02:00
|
|
|
if self.pos[1] == 0 or ([self.pos[0] + self.dirnx, self.pos[1] + self.dirny] in noWalkable):
|
|
|
|
#self.dirny *= (-1)
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
self.pos = [self.pos[0] + self.dirnx, self.pos[1] + self.dirny]
|
|
|
|
break
|
2020-03-23 10:49:27 +01:00
|
|
|
|
|
|
|
elif keys[pygame.K_DOWN]:
|
|
|
|
self.dirnx = 0
|
|
|
|
self.dirny = 1
|
2020-04-25 14:31:02 +02:00
|
|
|
if self.pos[1] == 14 or ([self.pos[0] + self.dirnx, self.pos[1] + self.dirny] in noWalkable):
|
|
|
|
#self.dirny *= (-1)
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
self.pos = [self.pos[0] + self.dirnx, self.pos[1] + self.dirny]
|
|
|
|
break
|
2020-03-23 10:49:27 +01:00
|
|
|
|
2020-04-05 16:53:59 +02:00
|
|
|
def resetPosition(self, pos):
|
2020-03-23 10:49:27 +01:00
|
|
|
self.pos = pos
|
|
|
|
|
2020-04-05 19:28:01 +02:00
|
|
|
def takePlates(self, kitchen):
|
|
|
|
for i in range(2):
|
|
|
|
plate = kitchen.giveDish()
|
|
|
|
if plate == None:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
self.plates.append(plate)
|
|
|
|
|
|
|
|
def giveClientPlate(self, client):
|
|
|
|
plate = self.plates.pop(0)
|
|
|
|
client.takePlateAndEat(plate)
|
|
|
|
|
2020-04-26 20:53:57 +02:00
|
|
|
def rotateRight(self):
|
|
|
|
self.currentRotation += 90
|
|
|
|
|
|
|
|
def rotateLeft(self):
|
|
|
|
self.currentRotation -= 90
|
|
|
|
|
|
|
|
def goForward(self, movex, movey):
|
|
|
|
self.posx += movex
|
|
|
|
self.posy += movey
|
|
|
|
self.pos = (self.posx, self.posy)
|
|
|
|
|
2020-03-23 10:49:27 +01:00
|
|
|
def draw(self, surface):
|
2020-04-26 17:55:59 +02:00
|
|
|
image = pygame.image.load(r'waiter_right.png')
|
|
|
|
image = pygame.transform.scale(image, (sizeBetween - 1, sizeBetween - 1))
|
2020-03-23 10:49:27 +01:00
|
|
|
|
2020-04-26 20:53:57 +02:00
|
|
|
if self.rotate == "right":
|
|
|
|
self.rotateRight()
|
|
|
|
elif self.rotate == "left":
|
|
|
|
self.rotateLeft()
|
|
|
|
elif self.direction == "forward":
|
|
|
|
pass
|
|
|
|
|
|
|
|
image = pygame.transform.rotate(image, self.currentRotation)
|
2020-04-25 14:31:02 +02:00
|
|
|
|
2020-04-26 17:55:59 +02:00
|
|
|
i = self.pos[0]
|
|
|
|
j = self.pos[1]
|
|
|
|
surface.blit(image, (i * sizeBetween + 1, j * sizeBetween + 1))
|
|
|
|
|
|
|
|
def goByAStar(self, end):
|
|
|
|
positionList = aStar(self.pos, end)
|
|
|
|
print(positionList)
|
2020-04-27 11:43:58 +02:00
|
|
|
if len(positionList) == 0:
|
|
|
|
messagebox.showerror("BŁĄD!", "Wybrano nieosiągalne pole!")
|
|
|
|
pygame.quit()
|
|
|
|
exit()
|
|
|
|
else:
|
|
|
|
lenght = len(positionList) - 1
|
|
|
|
for i in range(lenght):
|
|
|
|
movex = positionList[i + 1][0] - positionList[i][0]
|
|
|
|
movey = positionList[i + 1][1] - positionList[i][1]
|
|
|
|
|
|
|
|
prevDirection = self.direction
|
|
|
|
if movex == -1 and movey == 0:
|
|
|
|
self.direction = 1 #"left"
|
|
|
|
elif movex == 1 and movey == 0:
|
|
|
|
self.direction = 3 #"right"
|
|
|
|
elif movey == 1 and movex == 0:
|
|
|
|
self.direction = 4 #"down"
|
|
|
|
else:
|
|
|
|
self.direction = 2 #"up"
|
|
|
|
|
|
|
|
howToRotate = prevDirection - self.direction #działa!
|
|
|
|
|
|
|
|
if howToRotate < 0:
|
|
|
|
self.rotate = "left"
|
|
|
|
self.rotationNumber = abs(howToRotate)
|
|
|
|
elif howToRotate > 0:
|
|
|
|
self.rotate = "right"
|
|
|
|
self.rotationNumber = abs(howToRotate)
|
|
|
|
elif howToRotate == 0:
|
|
|
|
self.rotate = "forward"
|
|
|
|
self.rotationNumber = 0
|
|
|
|
|
|
|
|
#print(self.rotate)
|
|
|
|
|
|
|
|
for i in range(self.rotationNumber):
|
|
|
|
redrawWindow(window)
|
|
|
|
time.sleep(0.5)
|
2020-04-26 20:53:57 +02:00
|
|
|
self.rotate = "forward"
|
|
|
|
self.rotationNumber = 0
|
|
|
|
|
2020-04-27 11:43:58 +02:00
|
|
|
self.goForward(movex, movey)
|
2020-04-26 20:53:57 +02:00
|
|
|
redrawWindow(window)
|
|
|
|
time.sleep(0.5)
|
2020-03-23 10:49:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
def drawGrid(width, rows, surface):
|
|
|
|
x = 0
|
|
|
|
y = 0
|
|
|
|
|
|
|
|
for i in range(rows):
|
|
|
|
x = x + sizeBetween
|
|
|
|
y = y + sizeBetween
|
|
|
|
|
|
|
|
pygame.draw.line(surface, (255, 255, 255), (x, 0), (x, width))
|
|
|
|
pygame.draw.line(surface, (255, 255, 255), (0, y), (width, y))
|
|
|
|
|
|
|
|
|
|
|
|
def redrawWindow(surface):
|
|
|
|
surface.fill(beige)
|
|
|
|
bot.draw(surface)
|
2020-04-25 14:31:02 +02:00
|
|
|
kitchen.draw(surface)
|
|
|
|
for i in range(len(tables)):
|
|
|
|
tables[i].draw(surface)
|
2020-04-26 17:55:59 +02:00
|
|
|
for i in range(len(puddles)):
|
|
|
|
image = pygame.image.load(r'puddle.png')
|
|
|
|
image = pygame.transform.scale(image, (sizeBetween - 1, sizeBetween - 1))
|
|
|
|
surface.blit(image, (puddles[i][0]* sizeBetween + 1, puddles[i][1]* sizeBetween + 1))
|
2020-03-23 10:49:27 +01:00
|
|
|
drawGrid(width, rows, surface)
|
|
|
|
pygame.display.update()
|
|
|
|
|
2020-04-25 14:31:02 +02:00
|
|
|
def noWalkable(tables, kitchen):
|
|
|
|
list = []
|
|
|
|
for i in range(len(tables)):
|
|
|
|
list.append(tables[i].pos)
|
|
|
|
list.append(kitchen.pos)
|
|
|
|
return list
|
2020-03-23 10:49:27 +01:00
|
|
|
|
|
|
|
def main():
|
2020-04-26 17:55:59 +02:00
|
|
|
global width, rows, bot, beige, white, black, sizeBetween, tables, kitchen, cantwalk, puddles, window
|
2020-03-23 10:49:27 +01:00
|
|
|
# skróty do kolorów
|
|
|
|
beige = (255, 205, 178)
|
|
|
|
white = (255, 255, 255)
|
|
|
|
black = (0, 0, 0)
|
|
|
|
|
|
|
|
width = 600
|
|
|
|
rows = 15
|
2020-04-05 13:50:07 +02:00
|
|
|
sizeBetween = width // rows #wielkość pojedynczej kratki
|
2020-03-23 10:49:27 +01:00
|
|
|
window = pygame.display.set_mode((width, width))
|
2020-04-26 20:53:57 +02:00
|
|
|
bot = Waiter((255, 0, 0), (12, 8), 2)
|
2020-04-25 14:31:02 +02:00
|
|
|
|
|
|
|
tables = []
|
2020-04-26 17:55:59 +02:00
|
|
|
tables.append(Table((0, 3), 1))
|
|
|
|
tables.append(Table((0, 6), 1))
|
|
|
|
tables.append(Table((0, 9), 2))
|
|
|
|
tables.append(Table((0, 12), 2))
|
|
|
|
tables.append(Table((4, 4), 2))
|
|
|
|
tables.append(Table((4, 7), 2))
|
|
|
|
tables.append(Table((4, 10), 2))
|
|
|
|
tables.append(Table((4, 13), 2))
|
|
|
|
tables.append(Table((8, 3), 1))
|
|
|
|
tables.append(Table((8, 6), 1))
|
|
|
|
tables.append(Table((8, 9), 2))
|
|
|
|
tables.append(Table((8, 12), 2))
|
2020-04-25 14:31:02 +02:00
|
|
|
|
2020-03-23 10:49:27 +01:00
|
|
|
flag = True
|
|
|
|
clock = pygame.time.Clock()
|
2020-04-26 17:55:59 +02:00
|
|
|
kitchen = Kitchen((13, 1))
|
|
|
|
|
|
|
|
cantwalk = noWalkable(tables, kitchen) # lista pozycji, na ktore bot nie moze wejsc
|
|
|
|
puddles = []
|
|
|
|
puddles.append((7, 10))
|
|
|
|
puddles.append((2, 5))
|
|
|
|
puddles.append((3, 12))
|
|
|
|
puddles.append((10, 3))
|
|
|
|
puddles.append((6, 2))
|
|
|
|
puddles.append((12, 10))
|
|
|
|
puddles.append((1, 4))
|
2020-03-23 10:49:27 +01:00
|
|
|
|
|
|
|
while flag:
|
2020-04-05 13:50:07 +02:00
|
|
|
pygame.time.delay(100)
|
|
|
|
clock.tick(60)
|
2020-04-26 17:55:59 +02:00
|
|
|
redrawWindow(window)
|
2020-04-26 20:53:57 +02:00
|
|
|
#bot.moveRandomly()
|
2020-04-27 11:43:58 +02:00
|
|
|
goal = (1, 3)
|
2020-04-26 17:55:59 +02:00
|
|
|
bot.goByAStar(goal)
|
2020-04-26 20:53:57 +02:00
|
|
|
time.sleep(60)
|
2020-04-05 13:50:07 +02:00
|
|
|
flag = False
|
2020-03-23 10:49:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
main()
|