def testAdvanceBoard(self): board_string = '....\n.XXX\nXXX.' actual = generateBoard(board_string) expected_string = '..X.\nX..X\nX..X\n.X..' expected_0 = generateBoard(board_string) expected_1 = generateBoard(expected_string) for _ in range(3): self.assertEqual(expected_0, actual) actual = advanceBoard(actual) self.assertEqual(expected_1, actual) actual = advanceBoard(actual)
def testToString(self): board_string = '..X.\n.XXX\nXXX.' board = generateBoard(board_string) self.assertEqual(boardToString(board), board_string)
def testGenerateBoard(self): alive_string = 'X.\n.X' expected = set([Cell(0, 0), Cell(1, 1)]) actual = generateBoard(alive_string) self.assertEqual(expected, actual)
from game_of_life import generateBoard, advanceBoard import time import bpy import os from createGrass import * from changeGrow import * bpy.app.debug = True if __name__ == '__main__': f = generateBoard("......X.\nXX......\n.X...XXX") oldf = [] out = "" grass = bpy.context.selected_objects[0] grasses = [] steps = 5 fps = 5 secPerStep = 4 #constant bpy.context.scene.render.fps = fps framesPerStep = secPerStep * fps bpy.data.scenes['Scene'].frame_end = (steps - 1) * framesPerStep for i in range(steps): for el in f: changed = False for g in grasses: if el.x == g[1] and el.y == g[2]: grasses = changeGrow(el.x, el.y, el.grow, grasses) changed = True if changed == False: grasses = createGrass(el.x, el.y, 0, el.grow, grass, grasses) oldf = f f = advanceBoard(f)