Browse Source

nochmals ein kleines Tuning

ateubert 7 years ago
parent
commit
f3baf8317c
1 changed files with 13 additions and 9 deletions
  1. 13 9
      maze_fertig.py

+ 13 - 9
maze_fertig.py

113
 #GENERIERUNG DES LABYRINTHS
113
 #GENERIERUNG DES LABYRINTHS
114
 class Maze(object):
114
 class Maze(object):
115
 
115
 
116
-    def __init__(self, width=21, height=21, exit_cell=(19,1)):	#Initierung des Rahmens des Maze, sowie Start und Ziel Festlegung
116
+    def __init__(self, width=21, height=21, exit_cell=(width - 2,1)):				#Initierung des Rahmens des Maze, sowie Start und Ziel Festlegung
117
         self.width = width
117
         self.width = width
118
         self.height = height
118
         self.height = height
119
         self.exit_cell = exit_cell
119
         self.exit_cell = exit_cell
147
           # # # # # # #     # # # # # # #
147
           # # # # # # #     # # # # # # #
148
           # b # a # b #     # b # # # # #
148
           # b # a # b #     # b # # # # #
149
           # # # # # # #     # # # # # # #
149
           # # # # # # #     # # # # # # #
150
-          # # # b # # #     # # # # # # #
150
+          # # # b # # #     # # # # # # #						
151
           # # # # # # #     # # # # # # #
151
           # # # # # # #     # # # # # # #
152
         """
152
         """
153
         x, y = cell
153
         x, y = cell
154
         neighbors = []
154
         neighbors = []
155
 
155
 
156
-        # links
157
-        if x - 2 > 0:
158
-            neighbors.append((x-2, y))
156
+        # links										#die Koordinaten der Zelle wird mit den Koordinaten der moeglichen
157
+        if x - 2 > 0:									#Nachbarzelle abgeglichen. Sind die Koordinaten verfuegbar,
158
+            neighbors.append((x-2, y))							#entsteht eine Nachbarzelle
159
         # rechts
159
         # rechts
160
         if x + 2 < self.width:
160
         if x + 2 < self.width:
161
             neighbors.append((x+2, y))
161
             neighbors.append((x+2, y))
169
         return neighbors
169
         return neighbors
170
 
170
 
171
     def _remove_wall(self, cell, neighbor):
171
     def _remove_wall(self, cell, neighbor):
172
-        """
172
+        """ 
173
  	Entferne die Wand zwischen den beiden Zellen  
173
  	Entferne die Wand zwischen den beiden Zellen  
174
         Beispiel:
174
         Beispiel:
175
           Die Wand zwischen a und b ist w
175
           Die Wand zwischen a und b ist w
181
         """
181
         """
182
         x0, y0 = cell
182
         x0, y0 = cell
183
         x1, y1 = neighbor
183
         x1, y1 = neighbor
184
-        # vertikal
184
+        # vertikal									#
185
         if x0 == x1:
185
         if x0 == x1:
186
             x = x0
186
             x = x0
187
             y = (y0 + y1) / 2
187
             y = (y0 + y1) / 2
191
             y = y0
191
             y = y0
192
         self.maze[y][x] = 0 
192
         self.maze[y][x] = 0 
193
 
193
 
194
+
195
+#RUECKVERFOLGUNG DES WEGES	
194
     def _update_start_cell(self, cell, depth):
196
     def _update_start_cell(self, cell, depth):
195
         if depth > self.recursion_depth:
197
         if depth > self.recursion_depth:
196
             self.recursion_depth = depth
198
             self.recursion_depth = depth
213
             print "Steps from A to B:", self.steps
215
             print "Steps from A to B:", self.steps
214
 
216
 
215
 
217
 
216
-if __name__ == '__main__':
217
 
218
 
219
+#ZUSATZ: OPTIONEN/HILFEN
220
+if __name__ == '__main__':								#optparse wird eingesetzt, um den jeweiligen Stand/Status abzufragen 
221
+											
218
      from optparse import OptionParser
222
      from optparse import OptionParser
219
 
223
 
220
      parser = OptionParser(description="Random maze game")
224
      parser = OptionParser(description="Random maze game")
226
                        help="cell size (default 10)")
230
                        help="cell size (default 10)")
227
      args, _ = parser.parse_args()
231
      args, _ = parser.parse_args()
228
 
232
 
229
-     for arg in ('width', 'height'):
233
+     for arg in ('width', 'height'):							#Option verfuegbar, die Hoehe und Breite zu aendern
230
          if getattr(args, arg) % 2 == 0:
234
          if getattr(args, arg) % 2 == 0:
231
              setattr(args, arg, getattr(args, arg) + 1)
235
              setattr(args, arg, getattr(args, arg) + 1)
232
              print "Warning: %s muss ungerade sein, benutze %d stattdessen" % \
236
              print "Warning: %s muss ungerade sein, benutze %d stattdessen" % \