Zmienione self; nadal nie dziala

This commit is contained in:
Arkadiusz 2019-05-05 23:07:13 +01:00
parent 9cd93b8047
commit 8da63cae25
6 changed files with 307 additions and 214 deletions

View File

@ -17,20 +17,17 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/order.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<state relative-caret-position="-7">
<caret line="6" selection-start-line="6" selection-end-line="6" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/game.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1475">
<caret line="59" column="26" selection-start-line="59" selection-start-column="19" selection-end-line="59" selection-end-column="26" />
<folding>
<element signature="e#0#18#0" expanded="true" />
</folding>
<state relative-caret-position="286">
<caret line="56" column="52" lean-forward="true" selection-start-line="56" selection-start-column="52" selection-end-line="56" selection-end-column="52" />
</state>
</provider>
</entry>
@ -38,7 +35,7 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/gridElement.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<state relative-caret-position="308">
<caret line="14" column="59" selection-start-line="14" selection-start-column="59" selection-end-line="14" selection-end-column="59" />
</state>
</provider>
@ -47,7 +44,7 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/table.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<state relative-caret-position="308">
<caret line="14" column="15" selection-start-line="14" selection-start-column="15" selection-end-line="14" selection-end-column="15" />
</state>
</provider>
@ -56,7 +53,7 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/pool.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<state relative-caret-position="198">
<caret line="9" column="26" selection-start-line="9" selection-start-column="26" selection-end-line="9" selection-end-column="26" />
<folding>
<element signature="e#0#13#0" expanded="true" />
@ -68,19 +65,26 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/orderTable.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<state relative-caret-position="-7">
<caret line="17" column="58" selection-start-line="17" selection-start-column="58" selection-end-line="17" selection-end-column="58" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/waiter.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="402">
<caret line="249" column="18" lean-forward="true" selection-start-line="249" selection-start-column="18" selection-end-line="249" selection-end-column="18" />
<state relative-caret-position="-1225">
<caret line="175" column="27" selection-start-line="175" selection-start-column="27" selection-end-line="175" selection-end-column="27" />
<folding>
<element signature="e#0#13#0" expanded="true" />
<element signature="e#546#709#0" />
<element signature="e#758#1456#0" />
<element signature="e#1495#2175#0" />
<element signature="e#2213#2975#0" />
<element signature="e#3409#3781#0" />
<element signature="e#3825#4033#0" />
<element signature="e#4080#4470#0" />
</folding>
</state>
</provider>
@ -95,6 +99,11 @@
</list>
</option>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>self.last</find>
</findStrings>
</component>
<component name="Git.Settings">
<option name="PREVIOUS_COMMIT_AUTHORS">
<list>
@ -103,6 +112,9 @@
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="HierarchyBrowserManager">
<option name="SORT_ALPHABETICALLY" value="true" />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
@ -114,8 +126,8 @@
<option value="$PROJECT_DIR$/table.py" />
<option value="$PROJECT_DIR$/orderTable.py" />
<option value="$PROJECT_DIR$/pool.py" />
<option value="$PROJECT_DIR$/game.py" />
<option value="$PROJECT_DIR$/waiter.py" />
<option value="$PROJECT_DIR$/game.py" />
</list>
</option>
</component>
@ -257,11 +269,11 @@
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
<editor active="true" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.18124342" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.18336888" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32936078" />
<window_info active="true" anchor="bottom" id="Run" order="2" sideWeight="0.49894625" visible="true" weight="0.29577464" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.3997833" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
@ -270,7 +282,7 @@
<window_info anchor="bottom" id="Version Control" order="7" sideWeight="0.49947312" weight="0.32936078" />
<window_info anchor="bottom" id="Terminal" order="8" weight="0.32936078" />
<window_info anchor="bottom" id="Event Log" order="9" sideWeight="0.50105375" side_tool="true" weight="0.32936078" />
<window_info anchor="bottom" id="Python Console" order="10" />
<window_info anchor="bottom" id="Python Console" order="10" weight="0.32936078" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
@ -318,6 +330,34 @@
<MESSAGE value="Lada i skromne kolizje" />
<option name="LAST_COMMIT_MESSAGE" value="Lada i skromne kolizje" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/waiter.py</url>
<line>284</line>
<option name="timeStamp" value="36" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/game.py</url>
<line>54</line>
<option name="timeStamp" value="37" />
</line-breakpoint>
</breakpoints>
<default-breakpoints>
<breakpoint type="python-exception">
<properties notifyOnTerminate="true" exception="BaseException">
<option name="notifyOnTerminate" value="true" />
</properties>
</breakpoint>
</default-breakpoints>
</breakpoint-manager>
<watches-manager>
<configuration name="PythonConfigurationType">
<watch expression="grid" />
</configuration>
</watches-manager>
</component>
<component name="editorHistoryManager">
<entry file="file://$USER_HOME$/Desktop/pygame-elsa/sprites/olaf.py">
<provider selected="true" editor-type-id="text-editor">
@ -329,13 +369,6 @@
<entry file="file://$PROJECT_DIR$/Images/waiter.jpg">
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file://$APPLICATION_HOME_DIR$/helpers/pydev/pydevd.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="168">
<caret line="1134" selection-start-line="1134" selection-end-line="1134" />
</state>
</provider>
</entry>
<entry file="file://$APPLICATION_HOME_DIR$/helpers/pydev/_pydev_imps/_pydev_execfile.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289">
@ -386,28 +419,21 @@
</entry>
<entry file="file://$PROJECT_DIR$/order.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<state relative-caret-position="-7">
<caret line="6" selection-start-line="6" selection-end-line="6" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/gridElement.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret line="14" column="59" selection-start-line="14" selection-start-column="59" selection-end-line="14" selection-end-column="59" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/table.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<state relative-caret-position="308">
<caret line="14" column="15" selection-start-line="14" selection-start-column="15" selection-end-line="14" selection-end-column="15" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/pool.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<state relative-caret-position="198">
<caret line="9" column="26" selection-start-line="9" selection-start-column="26" selection-end-line="9" selection-end-column="26" />
<folding>
<element signature="e#0#13#0" expanded="true" />
@ -417,30 +443,55 @@
</entry>
<entry file="file://$PROJECT_DIR$/orderTable.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<state relative-caret-position="-7">
<caret line="17" column="58" selection-start-line="17" selection-start-column="58" selection-end-line="17" selection-end-column="58" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/game.py">
<entry file="file://$PROJECT_DIR$/gridElement.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1475">
<caret line="59" column="26" selection-start-line="59" selection-start-column="19" selection-end-line="59" selection-end-column="26" />
<folding>
<element signature="e#0#18#0" expanded="true" />
</folding>
<state relative-caret-position="308">
<caret line="14" column="59" selection-start-line="14" selection-start-column="59" selection-end-line="14" selection-end-column="59" />
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/.PyCharmCE2018.3/system/python_stubs/-258859485/builtins.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="299">
<caret line="3704" column="8" selection-start-line="3704" selection-start-column="8" selection-end-line="3704" selection-end-column="8" />
</state>
</provider>
</entry>
<entry file="file://$APPLICATION_HOME_DIR$/helpers/pydev/pydevd.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="448">
<caret line="1740" selection-start-line="1740" selection-end-line="1740" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/waiter.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="402">
<caret line="249" column="18" lean-forward="true" selection-start-line="249" selection-start-column="18" selection-end-line="249" selection-end-column="18" />
<state relative-caret-position="-1225">
<caret line="175" column="27" selection-start-line="175" selection-start-column="27" selection-end-line="175" selection-end-column="27" />
<folding>
<element signature="e#0#13#0" expanded="true" />
<element signature="e#546#709#0" />
<element signature="e#758#1456#0" />
<element signature="e#1495#2175#0" />
<element signature="e#2213#2975#0" />
<element signature="e#3409#3781#0" />
<element signature="e#3825#4033#0" />
<element signature="e#4080#4470#0" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/game.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="286">
<caret line="56" column="52" lean-forward="true" selection-start-line="56" selection-start-column="52" selection-end-line="56" selection-end-column="52" />
</state>
</provider>
</entry>
</component>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

12
game.py
View File

@ -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)

370
waiter.py
View File

@ -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)