diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 882c8a5..28ef5c2 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -17,20 +17,17 @@
-
+
-
+
-
-
-
-
-
+
+
@@ -38,7 +35,7 @@
-
+
@@ -47,7 +44,7 @@
-
+
@@ -56,7 +53,7 @@
-
+
@@ -68,19 +65,26 @@
-
+
-
+
-
-
+
+
+
+
+
+
+
+
+
@@ -95,6 +99,11 @@
+
+
+ self.last
+
+
+
+
+
@@ -257,11 +269,11 @@
-
+
-
+
@@ -270,7 +282,7 @@
-
+
@@ -318,6 +330,34 @@
+
+
+
+
+ file://$PROJECT_DIR$/waiter.py
+ 284
+
+
+
+ file://$PROJECT_DIR$/game.py
+ 54
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -329,13 +369,6 @@
-
-
-
-
-
-
-
@@ -386,28 +419,21 @@
-
+
-
-
-
-
-
-
-
-
+
-
+
@@ -417,30 +443,55 @@
-
+
-
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/__pycache__/DFS.cpython-37.pyc b/__pycache__/DFS.cpython-37.pyc
new file mode 100644
index 0000000..4de343a
Binary files /dev/null and b/__pycache__/DFS.cpython-37.pyc differ
diff --git a/__pycache__/gridAndWaiter.cpython-37.pyc b/__pycache__/gridAndWaiter.cpython-37.pyc
new file mode 100644
index 0000000..f90608f
Binary files /dev/null and b/__pycache__/gridAndWaiter.cpython-37.pyc differ
diff --git a/__pycache__/waiter.cpython-37.pyc b/__pycache__/waiter.cpython-37.pyc
index e130349..446510f 100644
Binary files a/__pycache__/waiter.cpython-37.pyc and b/__pycache__/waiter.cpython-37.pyc differ
diff --git a/game.py b/game.py
index 62863d1..650bff4 100644
--- a/game.py
+++ b/game.py
@@ -5,6 +5,7 @@ from gridElement import GridElement
from pygame.math import Vector2
from orderTable import OrderTable
from pool import Pool
+import copy
class Game(object):
def __init__(self):
@@ -47,7 +48,14 @@ class Game(object):
if i == self.x-1:
self.grid.append(list(self.row))
self.row.clear()
- self.waiter.dfsFind(self, self.waiter.lastStep, 1)
+ #copyGrid = copy.copy(self.grid)
+ #copyGrid = []
+ #kopia = copy.deepcopy(self.grid[9][4])
+ kopia = [[num for num in line] for line in self.grid]
+ self.waiter.dfsFind(kopia, [], 2)
+ #print("Prawdziwa pozycja kelnera: {0}, {1} ", self.waiter.positionX, self.waiter.positionY)
+ #print(self.waiter.findWaiter(self.grid[:]))
+
while True:
for event in pygame.event.get():
@@ -56,7 +64,7 @@ class Game(object):
self.draw()
self.waiter.move(self)
- print(self.waiter.checkPoss(self, self.waiter.lastStep))
+ #print(self.waiter.checkPoss(self.grid, self.waiter.lastStep))
pygame.display.flip()
#print(self.waiterNumberInGrid)
self.fpsClock.tick(10)
diff --git a/waiter.py b/waiter.py
index 7bda2d2..7118110 100644
--- a/waiter.py
+++ b/waiter.py
@@ -16,66 +16,87 @@ class Waiter(object):
self.image.set_colorkey((255, 255, 255))
self.type = "waiter"
self.lastStep = []
+ self.allPath = []
- def moveLeft(self, game):
- if self.positionX != 0:
- collisionObject = game.grid[self.positionY][self.positionX - 1]
+ def findWaiter(self, grid):
+ for y in range(10):
+ for x in range(10):
+ if grid[y][x].type =="waiter":
+ #print(x,y)
+ return [x, y]
+
+
+ def moveLeft(self, grid):
+
+ position = self.findWaiter(grid)
+ positionX = position[0]
+ positionY = position[1]
+ if positionX != 0:
+ collisionObject = grid[positionY][positionX - 1]
if collisionObject.type == "gridElement":
- game.grid[self.positionY][self.positionX - 1].x += 50
- game.grid[self.positionY][self.positionX].x -= 50
- game.grid[self.positionY][self.positionX - 1], \
- game.grid[self.positionY][self.positionX] = \
- game.grid[self.positionY][self.positionX], \
- game.grid[self.positionY][self.positionX - 1]
- self.positionX -= 1
+ grid[positionY][positionX - 1].x += 50
+ grid[positionY][positionX].x -= 50
+ grid[positionY][positionX - 1], \
+ grid[positionY][positionX] = \
+ grid[positionY][positionX], \
+ grid[positionY][positionX - 1]
+
#print(self.positionX)
- self.lastStep.append("Left")
+ return grid
else:
pass
- def moveRight(self, game):
- if self.positionX != game.x-1:
- collisionObject = game.grid[self.positionY][self.positionX + 1]
+ def moveRight(self, grid):
+
+ position = self.findWaiter(grid)
+ positionX = position[0]
+ positionY = position[1]
+ if positionX != 9:
+ collisionObject = grid[positionY][positionX + 1]
if collisionObject.type == "gridElement":
- game.grid[self.positionY][self.positionX + 1].x -= 50
- game.grid[self.positionY][self.positionX].x += 50
- game.grid[self.positionY][self.positionX + 1], \
- game.grid[self.positionY][self.positionX] = \
- game.grid[self.positionY][self.positionX], \
- game.grid[self.positionY][self.positionX + 1]
- self.positionX += 1
- #print(self.positionX)
- self.lastStep.append("Right")
+ grid[positionY][positionX + 1].x -= 50
+ grid[positionY][positionX].x += 50
+ grid[positionY][positionX + 1], \
+ grid[positionY][positionX] = \
+ grid[positionY][positionX], \
+ grid[positionY][positionX + 1]
+
+ # print(self.positionX)
+ return grid
else:
pass
- def moveUp(self, game):
- if self.positionY != 0:
- collisionObject = game.grid[self.positionY - 1][self.positionX]
+ def moveUp(self, grid):
+ position = self.findWaiter(grid)
+ positionX = position[0]
+ positionY = position[1]
+ if positionY != 0:
+ collisionObject = grid[positionY - 1][positionX]
if collisionObject.type == "gridElement":
- game.grid[self.positionY - 1][self.positionX].y += 50
- game.grid[self.positionY][self.positionX].y -= 50
- game.grid[self.positionY - 1][self.positionX], \
- game.grid[self.positionY][self.positionX] = \
- game.grid[self.positionY][self.positionX], \
- game.grid[self.positionY - 1][self.positionX]
- self.positionY -= 1
- self.lastStep.append("Up")
+ grid[positionY - 1][positionX].y += 50
+ grid[positionY][positionX].y -= 50
+ grid[positionY - 1][positionX], \
+ grid[positionY][positionX] = \
+ grid[positionY][positionX], \
+ grid[positionY - 1][positionX]
+ return grid
else:
pass
- def moveDown(self, game):
- if self.positionY != game.y-1:
- collisionObject = game.grid[self.positionY + 1][self.positionX]
+ def moveDown(self, grid):
+ position = self.findWaiter(grid)
+ positionX = position[0]
+ positionY = position[1]
+ if positionY != 9:
+ collisionObject = grid[positionY + 1][positionX]
if collisionObject.type == "gridElement":
- game.grid[self.positionY + 1][self.positionX].y -= 50
- game.grid[self.positionY][self.positionX].y += 50
- game.grid[self.positionY + 1][self.positionX], \
- game.grid[self.positionY][self.positionX] = \
- game.grid[self.positionY][self.positionX], \
- game.grid[self.positionY + 1][self.positionX]
- self.positionY += 1
- self.lastStep.append("Down")
+ grid[positionY + 1][positionX].y -= 50
+ grid[positionY][positionX].y += 50
+ grid[positionY + 1][positionX], \
+ grid[positionY][positionX] = \
+ grid[positionY][positionX], \
+ grid[positionY + 1][positionX]
+ return grid
else:
pass
@@ -85,16 +106,17 @@ class Waiter(object):
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
- self.moveLeft(game)
+ self.moveLeft(game.grid)
if keys[pygame.K_RIGHT]:
- self.moveRight(game)
+ self.moveRight(game.grid)
if keys[pygame.K_UP]:
- self.moveUp(game)
+ self.moveUp(game.grid)
if keys[pygame.K_DOWN]:
- self.moveDown(game)
+ self.moveDown(game.grid)
if keys[pygame.K_s]:
game.showGrid(game.grid)
+
def draw(self):
self.rect1 = pygame.Rect(self.x, self.y, 50, 50)
pygame.draw.rect(self.game.screen, (0, 150, 255), self.rect1)
@@ -102,150 +124,162 @@ class Waiter(object):
self.game.screen.blit(self.image, (self.x, self.y))
- def isMoveInRange(self, move):
+ def isMoveInRange(self, move, grid):
+ position = self.findWaiter(grid)
+ positionX = position[0]
+ positionY = position[1]
+
if move == "Left":
- if self.positionX == 0:
+ if positionX == 0:
return False
if move == "Right":
- if self.positionX == 9:
+ if positionX == 9:
return False
if move == "Up":
- if self.positionY == 0:
+ if positionY == 0:
return False
if move == "Down":
- if self.positionY == 9:
+ if positionY == 9:
return False
return True
- def checkPoss(self, game, lastOperation):
- self.grid = game.grid
- self.lastOperation = lastOperation
- self.stackMove = []
+ def checkPoss(self, grid, lastOperation):
- if len(self.lastOperation) == 0:
- if self.isMoveInRange("Up"):
- self.collisionObjectUp = self.grid[self.positionY - 1][self.positionX]
- if self.collisionObjectUp.type == "gridElement":
- self.stackMove.append("Up")
- if self.isMoveInRange("Down"):
- self.collisionObjectDown = self.grid[self.positionY + 1][self.positionX]
- if self.collisionObjectDown.type == "gridElement":
- self.stackMove.append("Down")
- if self.isMoveInRange("Left"):
- self.collisionObjectLeft = self.grid[self.positionY][self.positionX - 1]
- if self.collisionObjectLeft.type == "gridElement":
- self.stackMove.append("Left")
- if self.isMoveInRange("Right"):
- self.collisionObjectRight = self.grid[self.positionY][self.positionX + 1]
- if self.collisionObjectRight.type == "gridElement":
- self.stackMove.append("Right")
- return self.stackMove
+ stackMove = []
+
+ position = self.findWaiter(grid)
+ positionX = position[0]
+ positionY = position[1]
+
+ if len(lastOperation) == 0:
+ if self.isMoveInRange("Up", grid):
+ collisionObjectUp = grid[positionY - 1][positionX]
+ if collisionObjectUp.type == "gridElement":
+ stackMove.append("Up")
+ if self.isMoveInRange("Down", grid):
+ collisionObjectDown = grid[positionY + 1][positionX]
+ if collisionObjectDown.type == "gridElement":
+ stackMove.append("Down")
+ if self.isMoveInRange("Left", grid):
+ collisionObjectLeft = grid[positionY][positionX - 1]
+ if collisionObjectLeft.type == "gridElement":
+ stackMove.append("Left")
+ if self.isMoveInRange("Right", grid):
+ collisionObjectRight = grid[positionY][positionX + 1]
+ if collisionObjectRight.type == "gridElement":
+ stackMove.append("Right")
+ return stackMove
else:
- self.last = self.lastOperation[-1]
- if self.last == "Left":
- if self.isMoveInRange("Up"):
- self.collisionObjectUp = self.grid[self.positionY - 1][self.positionX]
- if self.collisionObjectUp.type == "gridElement":
- self.stackMove.append("Up")
- if self.isMoveInRange("Down"):
- self.collisionObjectDown = self.grid[self.positionY + 1][self.positionX]
- if self.collisionObjectDown.type == "gridElement":
- self.stackMove.append("Down")
- if self.isMoveInRange("Left"):
- self.collisionObjectLeft = self.grid[self.positionY][self.positionX - 1]
- if self.collisionObjectLeft.type == "gridElement":
- self.stackMove.append("Left")
+ last = lastOperation[-1]
+ if last == "Left":
+ if self.isMoveInRange("Up", grid):
+ collisionObjectUp = grid[positionY - 1][positionX]
+ if collisionObjectUp.type == "gridElement":
+ stackMove.append("Up")
+ if self.isMoveInRange("Down", grid):
+ collisionObjectDown = grid[positionY + 1][positionX]
+ if collisionObjectDown.type == "gridElement":
+ stackMove.append("Down")
+ if self.isMoveInRange("Left", grid):
+ collisionObjectLeft = grid[positionY][positionX - 1]
+ if collisionObjectLeft.type == "gridElement":
+ stackMove.append("Left")
- return self.stackMove
+ return stackMove
- if self.last == "Right":
- if self.isMoveInRange("Up"):
- self.collisionObjectUp = self.grid[self.positionY - 1][self.positionX]
- if self.collisionObjectUp.type == "gridElement":
- self.stackMove.append("Up")
- if self.isMoveInRange("Down"):
- self.collisionObjectDown = self.grid[self.positionY + 1][self.positionX]
- if self.collisionObjectDown.type == "gridElement":
- self.stackMove.append("Down")
+ if last == "Right":
+ if self.isMoveInRange("Up", grid):
+ collisionObjectUp = grid[positionY - 1][positionX]
+ if collisionObjectUp.type == "gridElement":
+ stackMove.append("Up")
+ if self.isMoveInRange("Down", grid):
+ collisionObjectDown = grid[positionY + 1][positionX]
+ if collisionObjectDown.type == "gridElement":
+ stackMove.append("Down")
- if self.isMoveInRange("Right"):
- self.collisionObjectRight = self.grid[self.positionY][self.positionX + 1]
- if self.collisionObjectRight.type == "gridElement":
- self.stackMove.append("Right")
- return self.stackMove
+ if self.isMoveInRange("Right", grid):
+ collisionObjectRight = grid[positionY][positionX + 1]
+ if collisionObjectRight.type == "gridElement":
+ stackMove.append("Right")
+ return stackMove
- if self.last == "Up":
- if self.isMoveInRange("Up"):
- self.collisionObjectUp = self.grid[self.positionY - 1][self.positionX]
- if self.collisionObjectUp.type == "gridElement":
- self.stackMove.append("Up")
+ if last == "Up":
+ if self.isMoveInRange("Up", grid):
+ collisionObjectUp = grid[positionY - 1][positionX]
+ if collisionObjectUp.type == "gridElement":
+ stackMove.append("Up")
- if self.isMoveInRange("Left"):
- self.collisionObjectLeft = self.grid[self.positionY][self.positionX - 1]
- if self.collisionObjectLeft.type == "gridElement":
- self.stackMove.append("Left")
- if self.isMoveInRange("Right"):
- self.collisionObjectRight = self.grid[self.positionY][self.positionX + 1]
- if self.collisionObjectRight.type == "gridElement":
- self.stackMove.append("Right")
- return self.stackMove
+ if self.isMoveInRange("Left", grid):
+ collisionObjectLeft = grid[positionY][positionX - 1]
+ if collisionObjectLeft.type == "gridElement":
+ stackMove.append("Left")
+ if self.isMoveInRange("Right", grid):
+ collisionObjectRight = grid[positionY][positionX + 1]
+ if collisionObjectRight.type == "gridElement":
+ stackMove.append("Right")
+ return stackMove
- if self.last == "Down":
+ if last == "Down":
- if self.isMoveInRange("Down"):
- self.collisionObjectDown = self.grid[self.positionY + 1][self.positionX]
- if self.collisionObjectDown.type == "gridElement":
- self.stackMove.append("Down")
- if self.isMoveInRange("Left"):
- self.collisionObjectLeft = self.grid[self.positionY][self.positionX - 1]
- if self.collisionObjectLeft.type == "gridElement":
- self.stackMove.append("Left")
- if self.isMoveInRange("Right"):
- self.collisionObjectRight = self.grid[self.positionY][self.positionX + 1]
- if self.collisionObjectRight.type == "gridElement":
- self.stackMove.append("Right")
- return self.stackMove
+ if self.isMoveInRange("Down", grid):
+ collisionObjectDown = grid[positionY + 1][positionX]
+ if collisionObjectDown.type == "gridElement":
+ stackMove.append("Down")
+ if self.isMoveInRange("Left", grid):
+ collisionObjectLeft = grid[positionY][positionX - 1]
+ if collisionObjectLeft.type == "gridElement":
+ stackMove.append("Left")
+ if self.isMoveInRange("Right", grid):
+ collisionObjectRight = grid[positionY][positionX + 1]
+ if collisionObjectRight.type == "gridElement":
+ stackMove.append("Right")
+ return stackMove
- def dfsFind(self, game, currentOperation, idTable):
- self.game = game
- self.grid = game.grid
- self.currentOperation = currentOperation
+ def dfsFind(self, grid, currentOperation, idTable):
+
print("Sprawdzam czy stolik")
- if self.isMoveInRange("Up"):
- if self.grid[self.positionY - 1][self.positionX].type == "table":
- if self.grid[self.positionY - 1][self.positionX].id == idTable:
- return self.currentOperation
- if self.isMoveInRange("Down"):
- if self.grid[self.positionY + 1][self.positionX].type == "table":
- if self.grid[self.positionY + 1][self.positionX].id == idTable:
- return self.currentOperation
- if self.isMoveInRange("Left"):
- if self.grid[self.positionY][self.positionX - 1].type == "table":
- if self.grid[self.positionY][self.positionX - 1].id == idTable:
- return self.currentOperation
- if self.isMoveInRange("Right"):
- if self.grid[self.positionY][self.positionX + 1].type == "table":
- if self.grid[self.positionY][self.positionX + 1].id == idTable:
- return self.currentOperation
- print("Sprawdzilem nie stolik")
+ position = self.findWaiter(grid)
+ positionX = position[0]
+ positionY = position[1]
+
+ if self.isMoveInRange("Up", grid):
+ if grid[positionY - 1][positionX].type == "table":
+ if grid[positionY - 1][positionX].id == idTable:
+ self.allPath.append(currentOperation)
+ return 0
+ if self.isMoveInRange("Down", grid):
+ if grid[positionY + 1][positionX].type == "table":
+ if grid[positionY + 1][positionX].id == idTable:
+ self.allPath.append(currentOperation)
+ return 0
+ if self.isMoveInRange("Left", grid):
+ if grid[positionY][positionX - 1].type == "table":
+ if grid[positionY][positionX - 1].id == idTable:
+ self.allPath.append(currentOperation)
+ return 0
+ if self.isMoveInRange("Right", grid):
+ if grid[positionY][positionX + 1].type == "table":
+ if grid[positionY][positionX + 1].id == idTable:
+ self.allPath.append(currentOperation)
+ return 0
+ print("Sprawdzilem nie jest to stolik")
steps = []
- steps.append(self.checkPoss(self.game, self.currentOperation))
+ steps.append(self.checkPoss(grid, currentOperation))
+ print("Naszymi mozliwosciami sa ", steps)
step = steps[-1]
- print(step[-1])
+ print("Wybieram : ", step[-1])
if step[-1] == "Left":
- self.moveLeft(self.game)
- self.currentOperation.append("Left")
+ self.moveLeft(grid)
+ currentOperation.append("Left")
if step[-1] == "Right":
- self.moveRight(self.game)
- self.currentOperation.append("Right")
+ self.moveRight(grid)
+ currentOperation.append("Right")
if step[-1] == "Up":
- self.moveUp(self.game)
- self.currentOperation.append("Up")
+ self.moveUp(grid)
+ currentOperation.append("Up")
if step[-1] == "Down":
- self.moveDown(self.game)
- self.currentOperation.append("Down")
- game.draw()
- time.sleep(.500)
- pygame.display.flip()
- self.dfsFind(self.game, self.currentOperation, idTable)
+ self.moveDown(grid)
+ currentOperation.append("Down")
+
+ self.dfsFind(grid[:], currentOperation[:], idTable)