DFS znajduje wszystkie mozliwe sciezki

This commit is contained in:
Arkadiusz 2019-05-07 22:43:21 +01:00
parent 8da63cae25
commit fe478e5ff8
4 changed files with 187 additions and 163 deletions

View File

@ -17,17 +17,17 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/order.py"> <entry file="file://$PROJECT_DIR$/order.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-7"> <state relative-caret-position="132">
<caret line="6" selection-start-line="6" selection-end-line="6" /> <caret line="6" selection-start-line="6" selection-end-line="6" />
</state> </state>
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="true"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/game.py"> <entry file="file://$PROJECT_DIR$/game.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="286"> <state relative-caret-position="273">
<caret line="56" column="52" lean-forward="true" selection-start-line="56" selection-start-column="52" selection-end-line="56" selection-end-column="52" /> <caret line="54" column="8" selection-start-line="54" selection-start-column="8" selection-end-line="54" selection-end-column="8" />
</state> </state>
</provider> </provider>
</entry> </entry>
@ -35,8 +35,8 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/gridElement.py"> <entry file="file://$PROJECT_DIR$/gridElement.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="308"> <state relative-caret-position="154">
<caret line="14" column="59" selection-start-line="14" selection-start-column="59" selection-end-line="14" selection-end-column="59" /> <caret line="7" column="17" selection-start-line="7" selection-start-column="17" selection-end-line="7" selection-end-column="17" />
</state> </state>
</provider> </provider>
</entry> </entry>
@ -53,7 +53,7 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/pool.py"> <entry file="file://$PROJECT_DIR$/pool.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="198"> <state relative-caret-position="176">
<caret line="9" column="26" selection-start-line="9" selection-start-column="26" selection-end-line="9" selection-end-column="26" /> <caret line="9" column="26" selection-start-line="9" selection-start-column="26" selection-end-line="9" selection-end-column="26" />
<folding> <folding>
<element signature="e#0#13#0" expanded="true" /> <element signature="e#0#13#0" expanded="true" />
@ -65,26 +65,27 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/orderTable.py"> <entry file="file://$PROJECT_DIR$/orderTable.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-7"> <state relative-caret-position="374">
<caret line="17" column="58" selection-start-line="17" selection-start-column="58" selection-end-line="17" selection-end-column="58" /> <caret line="17" column="58" selection-start-line="17" selection-start-column="58" selection-end-line="17" selection-end-column="58" />
</state> </state>
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/waiter.py"> <entry file="file://$PROJECT_DIR$/waiter.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1225"> <state relative-caret-position="281">
<caret line="175" column="27" selection-start-line="175" selection-start-column="27" selection-end-line="175" selection-end-column="27" /> <caret line="290" column="53" selection-start-line="290" selection-start-column="53" selection-end-line="290" selection-end-column="53" />
<folding> <folding>
<element signature="e#0#13#0" expanded="true" /> <element signature="e#0#13#0" expanded="true" />
<element signature="e#546#709#0" /> <element signature="e#572#736#0" />
<element signature="e#758#1456#0" /> <element signature="e#778#1419#0" />
<element signature="e#1495#2175#0" /> <element signature="e#1460#2110#0" />
<element signature="e#2213#2975#0" /> <element signature="e#2789#3398#0" />
<element signature="e#3409#3781#0" /> <element signature="e#3436#3808#0" />
<element signature="e#3825#4033#0" /> <element signature="e#3839#4047#0" />
<element signature="e#4080#4470#0" /> <element signature="e#4099#4564#0" />
<element signature="e#4621#8896#0" />
</folding> </folding>
</state> </state>
</provider> </provider>
@ -126,16 +127,15 @@
<option value="$PROJECT_DIR$/table.py" /> <option value="$PROJECT_DIR$/table.py" />
<option value="$PROJECT_DIR$/orderTable.py" /> <option value="$PROJECT_DIR$/orderTable.py" />
<option value="$PROJECT_DIR$/pool.py" /> <option value="$PROJECT_DIR$/pool.py" />
<option value="$PROJECT_DIR$/waiter.py" />
<option value="$PROJECT_DIR$/game.py" /> <option value="$PROJECT_DIR$/game.py" />
<option value="$PROJECT_DIR$/waiter.py" />
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectFrameBounds" extendedState="6"> <component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="716" /> <option name="x" value="-7" />
<option name="y" value="77" /> <option name="width" value="974" />
<option name="width" value="970" /> <option name="height" value="1047" />
<option name="height" value="1050" />
</component> </component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true"> <component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" /> <ConfirmationsSetting value="2" id="Add" />
@ -269,13 +269,13 @@
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" /> <frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
<editor active="true" /> <editor active="true" />
<layout> <layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.18336888" /> <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.18335089" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" /> <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" /> <window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" /> <window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32936078" /> <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 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="Debug" order="3" weight="0.27193934" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" /> <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" weight="0.32936078" /> <window_info anchor="bottom" id="TODO" order="6" weight="0.32936078" />
@ -332,18 +332,6 @@
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <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> <default-breakpoints>
<breakpoint type="python-exception"> <breakpoint type="python-exception">
<properties notifyOnTerminate="true" exception="BaseException"> <properties notifyOnTerminate="true" exception="BaseException">
@ -354,10 +342,19 @@
</breakpoint-manager> </breakpoint-manager>
<watches-manager> <watches-manager>
<configuration name="PythonConfigurationType"> <configuration name="PythonConfigurationType">
<watch expression="grid" /> <watch expression="grid" language="Python" />
</configuration> </configuration>
</watches-manager> </watches-manager>
</component> </component>
<component name="debuggerHistoryManager">
<expressions id="watch">
<expression>
<expression-string>grid</expression-string>
<language-id>Python</language-id>
<evaluation-mode>EXPRESSION</evaluation-mode>
</expression>
</expressions>
</component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$USER_HOME$/Desktop/pygame-elsa/sprites/olaf.py"> <entry file="file://$USER_HOME$/Desktop/pygame-elsa/sprites/olaf.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
@ -417,44 +414,6 @@
<entry file="file://$PROJECT_DIR$/Images/tlo.jpg"> <entry file="file://$PROJECT_DIR$/Images/tlo.jpg">
<provider selected="true" editor-type-id="images" /> <provider selected="true" editor-type-id="images" />
</entry> </entry>
<entry file="file://$PROJECT_DIR$/order.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-7">
<caret line="6" selection-start-line="6" selection-end-line="6" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/table.py">
<provider selected="true" editor-type-id="text-editor">
<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 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" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/orderTable.py">
<provider selected="true" editor-type-id="text-editor">
<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$/gridElement.py">
<provider selected="true" editor-type-id="text-editor">
<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"> <entry file="file://$USER_HOME$/.PyCharmCE2018.3/system/python_stubs/-258859485/builtins.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="299"> <state relative-caret-position="299">
@ -469,27 +428,66 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/waiter.py"> <entry file="file://$PROJECT_DIR$/order.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1225"> <state relative-caret-position="132">
<caret line="175" column="27" selection-start-line="175" selection-start-column="27" selection-end-line="175" selection-end-column="27" /> <caret line="6" selection-start-line="6" selection-end-line="6" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/table.py">
<provider selected="true" editor-type-id="text-editor">
<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 relative-caret-position="176">
<caret line="9" column="26" selection-start-line="9" selection-start-column="26" selection-end-line="9" selection-end-column="26" />
<folding> <folding>
<element signature="e#0#13#0" expanded="true" /> <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> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/orderTable.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="374">
<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$/gridElement.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="154">
<caret line="7" column="17" selection-start-line="7" selection-start-column="17" selection-end-line="7" selection-end-column="17" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/game.py"> <entry file="file://$PROJECT_DIR$/game.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="286"> <state relative-caret-position="273">
<caret line="56" column="52" lean-forward="true" selection-start-line="56" selection-start-column="52" selection-end-line="56" selection-end-column="52" /> <caret line="54" column="8" selection-start-line="54" selection-start-column="8" selection-end-line="54" selection-end-column="8" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/waiter.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="281">
<caret line="290" column="53" selection-start-line="290" selection-start-column="53" selection-end-line="290" selection-end-column="53" />
<folding>
<element signature="e#0#13#0" expanded="true" />
<element signature="e#572#736#0" />
<element signature="e#778#1419#0" />
<element signature="e#1460#2110#0" />
<element signature="e#2789#3398#0" />
<element signature="e#3436#3808#0" />
<element signature="e#3839#4047#0" />
<element signature="e#4099#4564#0" />
<element signature="e#4621#8896#0" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>

Binary file not shown.

View File

@ -51,8 +51,8 @@ class Game(object):
#copyGrid = copy.copy(self.grid) #copyGrid = copy.copy(self.grid)
#copyGrid = [] #copyGrid = []
#kopia = copy.deepcopy(self.grid[9][4]) #kopia = copy.deepcopy(self.grid[9][4])
kopia = [[num for num in line] for line in self.grid] #kopia = [[num for num in line] for line in self.grid]
self.waiter.dfsFind(kopia, [], 2) path = self.waiter.dfsFind([self.waiter.positionX, self.waiter.positionY], [], 2)
#print("Prawdziwa pozycja kelnera: {0}, {1} ", self.waiter.positionX, self.waiter.positionY) #print("Prawdziwa pozycja kelnera: {0}, {1} ", self.waiter.positionX, self.waiter.positionY)
#print(self.waiter.findWaiter(self.grid[:])) #print(self.waiter.findWaiter(self.grid[:]))

164
waiter.py
View File

@ -6,6 +6,7 @@ class Waiter(object):
def __init__(self, game, x, y): def __init__(self, game, x, y):
self.game = game self.game = game
self.grid = game.grid
game.idItem += 1 game.idItem += 1
self.size= self.game.screen.get_size() self.size= self.game.screen.get_size()
self.x = x self.x = x
@ -16,6 +17,7 @@ class Waiter(object):
self.image.set_colorkey((255, 255, 255)) self.image.set_colorkey((255, 255, 255))
self.type = "waiter" self.type = "waiter"
self.lastStep = [] self.lastStep = []
self.tmp = []
self.allPath = [] self.allPath = []
@ -124,8 +126,8 @@ class Waiter(object):
self.game.screen.blit(self.image, (self.x, self.y)) self.game.screen.blit(self.image, (self.x, self.y))
def isMoveInRange(self, move, grid): def isMoveInRange(self, move, position):
position = self.findWaiter(grid)
positionX = position[0] positionX = position[0]
positionY = position[1] positionY = position[1]
@ -143,143 +145,167 @@ class Waiter(object):
return False return False
return True return True
def checkPoss(self, grid, lastOperation): def checkPoss(self, position, lastOperation):
stackMove = [] stackMove = []
position = self.findWaiter(grid)
positionX = position[0] positionX = position[0]
positionY = position[1] positionY = position[1]
if len(lastOperation) == 0: if len(lastOperation) == 0:
if self.isMoveInRange("Up", grid): if self.isMoveInRange("Up", position):
collisionObjectUp = grid[positionY - 1][positionX] collisionObjectUp = self.grid[positionY - 1][positionX]
if collisionObjectUp.type == "gridElement": if collisionObjectUp.type == "gridElement" or collisionObjectUp.type == "waiter":
stackMove.append("Up") stackMove.append("Up")
if self.isMoveInRange("Down", grid): if self.isMoveInRange("Down", position):
collisionObjectDown = grid[positionY + 1][positionX] collisionObjectDown = self.grid[positionY + 1][positionX]
if collisionObjectDown.type == "gridElement": if collisionObjectDown.type == "gridElement" or collisionObjectDown.type == "waiter":
stackMove.append("Down") stackMove.append("Down")
if self.isMoveInRange("Left", grid): if self.isMoveInRange("Left", position):
collisionObjectLeft = grid[positionY][positionX - 1] collisionObjectLeft = self.grid[positionY][positionX - 1]
if collisionObjectLeft.type == "gridElement": if collisionObjectLeft.type == "gridElement" or collisionObjectLeft.type == "waiter":
stackMove.append("Left") stackMove.append("Left")
if self.isMoveInRange("Right", grid): if self.isMoveInRange("Right", position):
collisionObjectRight = grid[positionY][positionX + 1] collisionObjectRight = self.grid[positionY][positionX + 1]
if collisionObjectRight.type == "gridElement": if collisionObjectRight.type == "gridElement" or collisionObjectRight.type == "waiter":
stackMove.append("Right") stackMove.append("Right")
return stackMove return stackMove
else: else:
last = lastOperation[-1] last = lastOperation[-1]
if last == "Left": if last == "Left":
if self.isMoveInRange("Up", grid): if self.isMoveInRange("Up", position):
collisionObjectUp = grid[positionY - 1][positionX] collisionObjectUp = self.grid[positionY - 1][positionX]
if collisionObjectUp.type == "gridElement": if collisionObjectUp.type == "gridElement":
stackMove.append("Up") stackMove.append("Up")
if self.isMoveInRange("Down", grid): if self.isMoveInRange("Down", position):
collisionObjectDown = grid[positionY + 1][positionX] collisionObjectDown = self.grid[positionY + 1][positionX]
if collisionObjectDown.type == "gridElement": if collisionObjectDown.type == "gridElement":
stackMove.append("Down") stackMove.append("Down")
if self.isMoveInRange("Left", grid): if self.isMoveInRange("Left", position):
collisionObjectLeft = grid[positionY][positionX - 1] collisionObjectLeft = self.grid[positionY][positionX - 1]
if collisionObjectLeft.type == "gridElement": if collisionObjectLeft.type == "gridElement":
stackMove.append("Left") stackMove.append("Left")
return stackMove return stackMove
if last == "Right": if last == "Right":
if self.isMoveInRange("Up", grid): if self.isMoveInRange("Up", position):
collisionObjectUp = grid[positionY - 1][positionX] collisionObjectUp = self.grid[positionY - 1][positionX]
if collisionObjectUp.type == "gridElement": if collisionObjectUp.type == "gridElement":
stackMove.append("Up") stackMove.append("Up")
if self.isMoveInRange("Down", grid): if self.isMoveInRange("Down", position):
collisionObjectDown = grid[positionY + 1][positionX] collisionObjectDown = self.grid[positionY + 1][positionX]
if collisionObjectDown.type == "gridElement": if collisionObjectDown.type == "gridElement":
stackMove.append("Down") stackMove.append("Down")
if self.isMoveInRange("Right", grid): if self.isMoveInRange("Right", position):
collisionObjectRight = grid[positionY][positionX + 1] collisionObjectRight = self.grid[positionY][positionX + 1]
if collisionObjectRight.type == "gridElement": if collisionObjectRight.type == "gridElement":
stackMove.append("Right") stackMove.append("Right")
return stackMove return stackMove
if last == "Up": if last == "Up":
if self.isMoveInRange("Up", grid): if self.isMoveInRange("Up", position):
collisionObjectUp = grid[positionY - 1][positionX] collisionObjectUp = self.grid[positionY - 1][positionX]
if collisionObjectUp.type == "gridElement": if collisionObjectUp.type == "gridElement":
stackMove.append("Up") stackMove.append("Up")
if self.isMoveInRange("Left", grid): if self.isMoveInRange("Left", position):
collisionObjectLeft = grid[positionY][positionX - 1] collisionObjectLeft = self.grid[positionY][positionX - 1]
if collisionObjectLeft.type == "gridElement": if collisionObjectLeft.type == "gridElement":
stackMove.append("Left") stackMove.append("Left")
if self.isMoveInRange("Right", grid): if self.isMoveInRange("Right", position):
collisionObjectRight = grid[positionY][positionX + 1] collisionObjectRight = self.grid[positionY][positionX + 1]
if collisionObjectRight.type == "gridElement": if collisionObjectRight.type == "gridElement":
stackMove.append("Right") stackMove.append("Right")
return stackMove return stackMove
if last == "Down": if last == "Down":
if self.isMoveInRange("Down", grid): if self.isMoveInRange("Down", position):
collisionObjectDown = grid[positionY + 1][positionX] collisionObjectDown = self.grid[positionY + 1][positionX]
if collisionObjectDown.type == "gridElement": if collisionObjectDown.type == "gridElement":
stackMove.append("Down") stackMove.append("Down")
if self.isMoveInRange("Left", grid): if self.isMoveInRange("Left", position):
collisionObjectLeft = grid[positionY][positionX - 1] collisionObjectLeft = self.grid[positionY][positionX - 1]
if collisionObjectLeft.type == "gridElement": if collisionObjectLeft.type == "gridElement":
stackMove.append("Left") stackMove.append("Left")
if self.isMoveInRange("Right", grid): if self.isMoveInRange("Right", position):
collisionObjectRight = grid[positionY][positionX + 1] collisionObjectRight = self.grid[positionY][positionX + 1]
if collisionObjectRight.type == "gridElement": if collisionObjectRight.type == "gridElement":
stackMove.append("Right") stackMove.append("Right")
return stackMove return stackMove
def dfsFind(self, grid, currentOperation, idTable): def dfsFind(self, position, currentOperation, idTable):
print("Sprawdzam czy stolik") print("Sprawdzam czy stolik")
position = self.findWaiter(grid)
positionX = position[0] positionX = position[0]
positionY = position[1] positionY = position[1]
if self.isMoveInRange("Up", grid): if self.isMoveInRange("Up", position):
if grid[positionY - 1][positionX].type == "table": if self.grid[positionY - 1][positionX].type == "table":
if grid[positionY - 1][positionX].id == idTable: if self.grid[positionY - 1][positionX].id == idTable:
self.allPath.append(currentOperation)
print("Dodalem do all path sciezke jedna z miliona")
return 0
if self.isMoveInRange("Down", position):
if self.grid[positionY + 1][positionX].type == "table":
if self.grid[positionY + 1][positionX].id == idTable:
self.allPath.append(currentOperation) self.allPath.append(currentOperation)
return 0 return 0
if self.isMoveInRange("Down", grid): if self.isMoveInRange("Left", position):
if grid[positionY + 1][positionX].type == "table": if self.grid[positionY][positionX - 1].type == "table":
if grid[positionY + 1][positionX].id == idTable: if self.grid[positionY][positionX - 1].id == idTable:
self.allPath.append(currentOperation) self.allPath.append(currentOperation)
return 0 return 0
if self.isMoveInRange("Left", grid): if self.isMoveInRange("Right", position):
if grid[positionY][positionX - 1].type == "table": if self.grid[positionY][positionX + 1].type == "table":
if grid[positionY][positionX - 1].id == idTable: if self.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) self.allPath.append(currentOperation)
return 0 return 0
print("Sprawdzilem nie jest to stolik") print("Sprawdzilem nie jest to stolik")
steps = [] steps = []
steps.append(self.checkPoss(grid, currentOperation)) steps.append(self.checkPoss(position, currentOperation))
print("Naszymi mozliwosciami sa ", steps) allstep = steps[-1]
step = steps[-1] print("Naszymi mozliwosciami sa ", allstep)
print("Wybieram : ", step[-1])
if step[-1] == "Left": if len(allstep) != 1:
self.moveLeft(grid) for i in allstep:
newCurrentOperation = currentOperation[:]
newCurrentOperation.append(i)
newPosition = position[:]
if i == "Left":
newPosition[0] -= 1
if i == "Right":
newPosition[0] += 1
if i == "Up":
newPosition[1] -= 1
if i == "Down":
newPosition[1] += 1
self.tmp.append([newPosition, newCurrentOperation, idTable])
while self.tmp:
move = self.tmp.pop()
self.dfsFind(move[0], move[1], move[2])
else:
step = allstep.pop()
print("Wybrałem: ", step)
print("Pozycja tego cwela: ", position)
if step == "Left":
position[0] -= 1
currentOperation.append("Left") currentOperation.append("Left")
if step[-1] == "Right": if step == "Right":
self.moveRight(grid) position[0] += 1
currentOperation.append("Right") currentOperation.append("Right")
if step[-1] == "Up": if step == "Up":
self.moveUp(grid) position[1] -= 1
currentOperation.append("Up") currentOperation.append("Up")
if step[-1] == "Down": if step == "Down":
self.moveDown(grid) position[1] += 1
currentOperation.append("Down") currentOperation.append("Down")
self.dfsFind(grid[:], currentOperation[:], idTable) self.dfsFind(position, currentOperation, idTable)