Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/cca/diff/a40cbd127d39/Automata.py
Дата изменения: Unknown
Дата индексирования: Fri Feb 28 17:20:03 2014
Кодировка: Windows-1251
cca: Automata.py diff

cca

diff Automata.py @ 11:a40cbd127d39

Deleted key from States. Automata: symbols{}, init, next_step. A little modifications for PEP-8
author darkhan<darkhan.rus@gmail.com>
date Sat, 04 Dec 2010 21:22:08 +0300
parents c86adbd7d440
children 38f357feb56e
line diff
     1.1 --- a/Automata.py	Sat Dec 04 18:36:35 2010 +0300
     1.2 +++ b/Automata.py	Sat Dec 04 21:22:08 2010 +0300
     1.3 @@ -1,12 +1,48 @@
     1.4  class Automata(object):
     1.5 -	#field[][]
     1.6 +	#field[][]  - Хранит символ состояния
     1.7  	#states[]
     1.8 -	#все изменеия состояния клеток поля и изменения в списке состояний предлагаю делать через непосредственное обращение к соответствующим спискам экземпляра класса, который будет храниться в интрефейсе
     1.9 -	def __init__(self,width,height,states):
    1.10 +	#symbols = {}  - символ: номер_в_states
    1.11 +
    1.12 +	def __init__(self, width, height, states):
    1.13 +		self.width = width
    1.14 +		self.height = height
    1.15 +		self.states = states
    1.16 +		self.symbols = {}
    1.17 +		for num, st in enumerate(self.states):
    1.18 +			self.symbols[st.symbol] = num
    1.19 +		self.field = []
    1.20 +		for row in range(height):
    1.21 +			self.field.append([])
    1.22 +			for col in range(width):
    1.23 +				self.field[row].append(states[0].symbol)
    1.24 +
    1.25 +	def next_step():
    1.26 +		new_state = []
    1.27 +		for row in range(self.height):
    1.28 +			new_state.append([])
    1.29 +			for col in range(self.width):
    1.30 +				symbol = field[row][col]
    1.31 +				num = 0
    1.32 +				for vert_long in range(row + self.height - 1, 
    1.33 +										row + self.height + 2):
    1.34 +					for horiz_long in range(col + self.width - 1, 
    1.35 +											col + self.width + 2):
    1.36 +						vert = vert_long % self.height
    1.37 +						horiz = horiz_long % self.width
    1.38 +						if (vert == row) & (horiz = col): continue
    1.39 +						if self.field[vert][horiz] == symbol:
    1.40 +							num += 1
    1.41 +				new_state[row].append(
    1.42 +						self.states[self.symbols[symbol]].next_state(num))
    1.43 +						
    1.44 +		for row in range(self.height):
    1.45 +			for col in range(self.width):
    1.46 +				if new_state[row][col]:
    1.47 +					self.field[row][col] = self.states[(self.symbols[symbol]
    1.48 +													+ 1) % len(states)].symbol
    1.49 +
    1.50 +	def change_size(value, side):
    1.51  		pass
    1.52 -	def nextStep():
    1.53 -		pass
    1.54 -	def changeSize(width,height):
    1.55 -		pass
    1.56 -	def containState(symbol):
    1.57 +
    1.58 +	def contain_state(symbol):
    1.59  		return False