Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.fbb.msu.ru/trac/cca/changeset/3ff0fdc7ce7a4b9f7483faa2b992e401cdf52154
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Sun Apr 10 09:48:08 2016
Êîäèðîâêà: IBM-866
Changeset 62:3ff0fdc7ce7a òÀÓ Cyclyc Cell Automata

Changeset 62:3ff0fdc7ce7a


Ignore:
Timestamp:
12/11/10 00:46:25 (5 years ago)
Author:
darkhan
Branch:
default
Message:

Optimization of Automata

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Automata.py

    r49 r62 ˆà
    1515                        self.states = statesˆà
    1616                self.symbols = {}ˆà
    ˆà17                self.st_sym = {}ˆà
    1718                for num, st in enumerate(self.states):ˆà
    1819                        self.symbols[st.symbol] = numˆà
    ˆà20                        self.st_sym[st.symbol] = stˆà
    1921                self.field = []ˆà
    2022                for row in range(height):ˆà
    òÀæ òÀæ ˆà
    2527        def next_step(self):ˆà
    2628                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):ˆà
    2931                                symbol = self.field[row][col]ˆà
    3032                                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):ˆà
    3735                                                if self.field[vert][horiz] == symbol:ˆà
    3836                                                        num += 1ˆà
    39ˆà                                if self.states[self.symbols[symbol]].next_state(num - 1):ˆà
    ˆà37                                if self.st_sym[symbol].next_state(num - 1):ˆà
    4038                                        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))ˆà
    4188                                                ˆà
    4289                for row, col in changed:ˆà
Note: See TracChangeset for help on using the changeset viewer.