Changeset 62:3ff0fdc7ce7a
- Timestamp:
- 12/11/10 00:46:25 (5 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Automata.py
r49 r62 ˆà 15 15 self.states = statesˆà 16 16 self.symbols = {}ˆà ˆà 17 self.st_sym = {}ˆà 17 18 for num, st in enumerate(self.states):ˆà 18 19 self.symbols[st.symbol] = numˆà ˆà 20 self.st_sym[st.symbol] = stˆà 19 21 self.field = []ˆà 20 22 for row in range(height):ˆà òÀæ òÀæ ˆà 25 27 def next_step(self):ˆà 26 28 changed = []ˆà 27 ˆà for row in range( self.height):ˆà28 ˆà for col in range( self.width):ˆàˆà 29 for row in range(1, self.height - 1):ˆà ˆà 30 for col in range(1, self.width - 1):ˆà 29 31 symbol = self.field[row][col]ˆà 30 32 num = 0ˆà 31 ˆà for vert_long in range(row + self.height - 1, ˆà 32 ˆà row + self.height + 2):ˆà 33 ˆà for horiz_long in range(col + self.width - 1, ˆà 34 ˆà col + self.width + 2):ˆà 35 ˆà vert = vert_long % self.heightˆà 36 ˆà horiz = horiz_long % self.widthˆà ˆà 33 for vert in range(row - 1, row + 2):ˆà ˆà 34 for horiz in range(col - 1, col + 2):ˆà 37 35 if self.field[vert][horiz] == symbol:ˆà 38 36 num += 1ˆà 39 ˆà if self.st ates[self.symbols[symbol]].next_state(num - 1):ˆàˆà 37 if self.st_sym[symbol].next_state(num - 1):ˆà 40 38 changed.append((row, col))ˆà ˆà 39 ˆà ˆà 40 for row in range(1, self.height - 1):ˆà ˆà 41 symbol1 = self.field[row][0]ˆà ˆà 42 symbol2 = self.field[row][self.width - 1]ˆà ˆà 43 num1 = 0ˆà ˆà 44 num2 = 0ˆà ˆà 45 for vert in range(row - 1, row + 2):ˆà ˆà 46 for horiz in [0, 1, self.width - 1]:ˆà ˆà 47 if self.field[vert][horiz] == symbol1:ˆà ˆà 48 num1 += 1ˆà ˆà 49 for horiz in [self.width - 2, self.width - 1, 0]:ˆà ˆà 50 if self.field[vert][horiz] == symbol2:ˆà ˆà 51 num2 += 1ˆà ˆà 52 if self.st_sym[symbol1].next_state(num1 - 1):ˆà ˆà 53 changed.append((row, 0))ˆà ˆà 54 if self.st_sym[symbol2].next_state(num2 - 1):ˆà ˆà 55 changed.append((row, self.width - 1))ˆà ˆà 56 ˆà ˆà 57 for col in range(1, self.width - 1):ˆà ˆà 58 symbol1 = self.field[0][col]ˆà ˆà 59 symbol2 = self.field[self.height - 1][col]ˆà ˆà 60 num1 = 0ˆà ˆà 61 num2 = 0ˆà ˆà 62 for horiz in range(col - 1, col + 2):ˆà ˆà 63 for vert in [0, 1, self.height - 1]:ˆà ˆà 64 if self.field[vert][horiz] == symbol1:ˆà ˆà 65 num1 += 1ˆà ˆà 66 for vert in [self.height - 2, self.height - 1, 0]:ˆà ˆà 67 if self.field[vert][horiz] == symbol2:ˆà ˆà 68 num2 += 1ˆà ˆà 69 if self.st_sym[symbol1].next_state(num1 - 1):ˆà ˆà 70 changed.append((0, col))ˆà ˆà 71 if self.st_sym[symbol2].next_state(num2 - 1):ˆà ˆà 72 changed.append((self.height - 1, col))ˆà ˆà 73 ˆà ˆà 74 for row, col in [(0, 0), (self.height - 1, self.width - 1),ˆà ˆà 75 (0, self.width - 1), (self.height - 1, 0)]:ˆà ˆà 76 symbol = self.field[row][col]ˆà ˆà 77 num = 0ˆà ˆà 78 for vert_long in range(row + self.height - 1, ˆà ˆà 79 row + self.height + 2):ˆà ˆà 80 for horiz_long in range(col + self.width - 1, ˆà ˆà 81 col + self.width + 2):ˆà ˆà 82 vert = vert_long % self.heightˆà ˆà 83 horiz = horiz_long % self.widthˆà ˆà 84 if self.field[vert][horiz] == symbol:ˆà ˆà 85 num += 1ˆà ˆà 86 if self.st_sym[symbol].next_state(num - 1):ˆà ˆà 87 changed.append((row, col))ˆà 41 88 ˆà 42 89 for row, col in changed:ˆà
Note: See TracChangeset
for help on using the changeset viewer.