Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.cmm.msu.ru/trac/cca/changeset/49
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Sun Apr 10 17:26:58 2016
Êîäèðîâêà: IBM-866
Changeset 49:94406d1874a2 òÀÓ Cyclyc Cell Automata

Changeset 49:94406d1874a2


Ignore:
Timestamp:
12/06/10 12:36:59 (5 years ago)
Author:
darkhan
Branch:
default
Children:
50:9cbbff6dbbaf, 51:f411a1e0a5cb
Message:

repr in State, little optimized Automata, cell_size = 8, delay = 1

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • Automata.py

    r47 r49 ˆà
    1010                self.height = heightˆà
    1111                if states == None:ˆà
    12ˆà                        self.states = [State("Dead", ' ', "white", [5]),ˆà
    ˆà12                        self.states = [State("Dead", '-', "white", [5]),ˆà
    1313                                                        State("Alive", '+', "black", [0, 1] + range(4, 9))]ˆà
    1414                else:ˆà
    òÀæ òÀæ ˆà
    2525        def next_step(self):ˆà
    2626                changed = []ˆà
    27ˆà                new_state = []ˆà
    2827                for row in range(self.height):ˆà
    29ˆà                        new_state.append([])ˆà
    3028                        for col in range(self.width):ˆà
    3129                                symbol = self.field[row][col]ˆà
    òÀæ òÀæ ˆà
    3937                                                if self.field[vert][horiz] == symbol:ˆà
    4038                                                        num += 1ˆà
    41ˆà                                new_state[row].append(ˆà
    42ˆà                                                self.states[self.symbols[symbol]].next_state(num - 1))ˆà
    ˆà39                                if self.states[self.symbols[symbol]].next_state(num - 1):ˆà
    ˆà40                                        changed.append((row, col))ˆà
    4341                                                ˆà
    44ˆà                for row in range(self.height):ˆà
    45ˆà                        for col in range(self.width):ˆà
    46ˆà                                if new_state[row][col]:ˆà
    47ˆà                                        changed.append((row, col))ˆà
    48ˆà                                        index = (self.symbols[self.field[row][col]] + ˆà
    ˆà42                for row, col in changed:ˆà
    ˆà43                        index = (self.symbols[self.field[row][col]] + ˆà
    4944                                                                                                                1) %  len(self.states)ˆà
    50ˆà                                        self.field[row][col] = self.states[index].symbolˆà
    ˆà45                        self.field[row][col] = self.states[index].symbolˆà
    5146                return changedˆà
    5247ˆà
  • Interface.py

    r48 r49 ˆà
    77class Handlers(object):ˆà
    88        ˆà
    9ˆà        def __init__(self, cell_size=10, line_width=1 ,delay=100, offset_x=0, offset_y=0):# cell_size is size of cell, including line width, if there is itˆà
    ˆà9        def __init__(self, cell_size=8, line_width=1 ,delay=1, offset_x=0, offset_y=0):# cell_size is size of cell, including line width, if there is itˆà
    1010                self.cell_size = cell_sizeˆà
    1111                self.line_width = line_widthˆà
    òÀæ òÀæ ˆà
    250250canvas.config(width=500, height=400)ˆà
    251251ˆà
    252ˆàautomata = Automata(50, 50) ˆà
    ˆà252automata = Automata() ˆà
    253253handlers = Handlers()ˆà
    254254ˆà
  • State.py

    r38 r49 ˆà
    1717ˆà
    1818        def __repr__(self):ˆà
    19ˆà                return self.name + " " + self.symbolˆà
    ˆà19                return self.symbol + " " + self.nameˆà
Note: See TracChangeset for help on using the changeset viewer.