Return dirty plate to the kitchen

This commit is contained in:
s450026 2020-06-09 20:43:27 +02:00
parent 5be76f9a4b
commit 356d5af77e
4 changed files with 28 additions and 14 deletions

17
main.py
View File

@ -45,6 +45,7 @@ if __name__ == "__main__":
go = 0 go = 0
randomPlate = None randomPlate = None
plate = 0 plate = 0
changePlateVar = 0
waitPos = [[1, 2], [1, 5], [1, 8], [5, 4], [5, 8], waitPos = [[1, 2], [1, 5], [1, 8], [5, 4], [5, 8],
[8, 2], [8, 5], [8, 8], [12, 3], [12, 7]] [8, 2], [8, 5], [8, 8], [12, 3], [12, 7]]
@ -169,6 +170,7 @@ if __name__ == "__main__":
waiterX = waiter.X + (x * 0.1) waiterX = waiter.X + (x * 0.1)
graphics.clear(waiterX, waiter.Y - 1) graphics.clear(waiterX, waiter.Y - 1)
print(randomPlate) print(randomPlate)
changePlateVar = 0
# if this plate is exists # if this plate is exists
goal = (randomPlate.table[0], randomPlate.table[1]) goal = (randomPlate.table[0], randomPlate.table[1])
path = waiter.findPath(goal) path = waiter.findPath(goal)
@ -185,10 +187,11 @@ if __name__ == "__main__":
if predict == 1: if predict == 1:
predict = 'EMPTY' predict = 'EMPTY'
randomPlate.clearTable() randomPlate.clearTable()
plateArr.remove(randomPlate) plateArr.remove(randomPlate)
tree.TasksList('goToBar', barNode, [waiter.X, waiter.Y])
queue = tree.ReturnQueueList()
changePlateVar = 1
else: else:
predict = 'FOOD' predict = 'FOOD'
print('sec-3') print('sec-3')
@ -229,17 +232,21 @@ if __name__ == "__main__":
if task[0] == "goToBar": if task[0] == "goToBar":
path = waiter.findPath(barNode) path = waiter.findPath(barNode)
fromBar = 1 fromBar = 1
else: else:
changePlateVar = 0
path = waiter.findPath(node) path = waiter.findPath(node)
path = waiter.translatePath(path) path = waiter.translatePath(path)
if path == '' and fromBar == 1: if path == '' and fromBar == 1 and changePlateVar == 0:
path = waiter.findPath(node) path = waiter.findPath(node)
path = waiter.translatePath(path) path = waiter.translatePath(path)
fromBar = 0 fromBar = 0
plate = 1 plate = 1
if path == '' and fromBar == 1:
path = waiter.findPath(node)
path = waiter.translatePath(path)
fromBar = 0
print(plate)
# AStar # AStar
if path == '' and actions: if path == '' and actions:
print('Goal: {}'.format(actions[0][1])) print('Goal: {}'.format(actions[0][1]))

View File

@ -21,7 +21,7 @@ class DecisionTree:
def BuildDf(self): def BuildDf(self):
actionName = 'order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check'.split(',') actionName = 'order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check'.split(',')
distance = '0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27'.split(',') distance = '0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27'.split(',')
priority = '1,1,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4'.split(',') priority = '1,1,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4'.split(',')
dataset ={'actionName':actionName,'distance':distance,'priority':priority} dataset ={'actionName':actionName,'distance':distance,'priority':priority}
df = pd.DataFrame(dataset,columns=['actionName','distance','priority']) df = pd.DataFrame(dataset,columns=['actionName','distance','priority'])
@ -90,20 +90,25 @@ class DecisionTree:
#Dodawanie zadan do listy zadan #Dodawanie zadan do listy zadan
def TasksList(self, name, coordinate, waiterPos): def TasksList(self, name, coordinate, waiterPos):
distance = [] distance = []
if name != "goToBar": name1 = ''
if self.matrix.matrix[coordinate[0] + 1][coordinate[1]].walk_through == 1: if name == "goToBar":
distance.append([abs(coordinate[0] - (coordinate[0] + 1)) + abs(waiterPos[1] - coordinate[1]), [coordinate[0] + 1, coordinate[1] ]]) name1 = name
if self.matrix.matrix[coordinate[0] - 1][coordinate[1]].walk_through == 1:
distance.append([abs(coordinate[0] - (coordinate[0] - 1)) + abs(waiterPos[1] - coordinate[1]), [coordinate[0] - 1, coordinate[1] ]])
else:
if self.matrix.matrix[coordinate[0] + 1][coordinate[1]].walk_through == 1: if self.matrix.matrix[coordinate[0] + 1][coordinate[1]].walk_through == 1:
distance.append([abs(waiterPos[0] - 3) + abs(waiterPos[1] - 12), [coordinate[0] + 1, coordinate[1] ]]) distance.append([abs(waiterPos[0] - 3) + abs(waiterPos[1] - 12), [coordinate[0] + 1, coordinate[1] ]])
if self.matrix.matrix[coordinate[0] - 1][coordinate[1]].walk_through == 1: if self.matrix.matrix[coordinate[0] - 1][coordinate[1]].walk_through == 1:
distance.append([abs(waiterPos[0] - 3) + abs(waiterPos[1] - 12), [coordinate[0] - 1, coordinate[1] ]]) distance.append([abs(waiterPos[0] - 3) + abs(waiterPos[1] - 12), [coordinate[0] - 1, coordinate[1] ]])
else:
name1 = name
if self.matrix.matrix[coordinate[0] + 1][coordinate[1]].walk_through == 1:
distance.append([abs(coordinate[0] - (coordinate[0] + 1)) + abs(waiterPos[1] - coordinate[1]), [coordinate[0] + 1, coordinate[1] ]])
if self.matrix.matrix[coordinate[0] - 1][coordinate[1]].walk_through == 1:
distance.append([abs(coordinate[0] - (coordinate[0] - 1)) + abs(waiterPos[1] - coordinate[1]), [coordinate[0] - 1, coordinate[1] ]])
distance.sort(key=lambda x: x[0]) distance.sort(key=lambda x: x[0])
tasksList.append([name, distance[0][0], distance[0][1]]) tasksList.append([name1, distance[0][0], distance[0][1]])
#Kolejkowanie zadan #Kolejkowanie zadan
def Queue(self, tasksList): def Queue(self, tasksList):

View File

@ -88,6 +88,8 @@ class Graphics:
self.screen.blit(pygame.image.load(relative_path + picture), self.screen.blit(pygame.image.load(relative_path + picture),
(x * self.block_size, y * self.block_size)) (x * self.block_size, y * self.block_size))
def clearPlate(self, x, y): def clearPlate(self, x, y):
self.screen.blit(self.image['floor'],
(x * self.block_size, y * self.block_size))
self.screen.blit(self.image['table'], self.screen.blit(self.image['table'],
(x * self.block_size, y * self.block_size)) (x * self.block_size, y * self.block_size))