本文整理匯總了Python中rules.Rules.apply方法的典型用法代碼示例。如果您正苦於以下問題:Python Rules.apply方法的具體用法?Python Rules.apply怎麽用?Python Rules.apply使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rules.Rules
的用法示例。
在下文中一共展示了Rules.apply方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Game
# 需要導入模塊: from rules import Rules [as 別名]
# 或者: from rules.Rules import apply [as 別名]
class Game(object):
"""docstring for Game"""
def __init__(self, board):
super(Game, self).__init__()
self.rules = Rules()
self.board = board
self.xSize = board.getXSize()
self.ySize = board.getYSize()
def iterate(self):
newBoard = Board(self.xSize, self.ySize)
for i in xrange(self.xSize):
for j in xrange(self.ySize):
count = self.board.getAliveNeiburghs(i,j)
state = self.board.isAlive(i,j)
newState = self.rules.apply(count, state)
newBoard.setState(i,j,newState)
self.board = newBoard
def playGame(self):
while(not self.board.isAllDead()):
self.iterate()
self.printBoard()
def printLines(self):
line = '\n'
for i in xrange(self.ySize):
line += '-'
print line + '\n'
def printBoard(self):
os.system('clear')
self.printLines()
print self.board.toString()
self.printLines()