def do_action(self, action): if action == 'slow_down': self.change_game_speed(.9) elif action == 'normal_speed': self.set_normal_speed() elif action == 'speed_up': self.change_game_speed(1.11) ''' elif action == 'zoom_out': self.box = self.box*.9 elif action == 'zoom_in': self.box = self.box*1.11 ''' elif action == 'clear': self.restart = True else: new_life = [] pattern = Pattern(action, (90,60)) coordinate_list = pattern.create_pattern() for coordinate in coordinate_list: new_life.append(Cell(coordinate)) self.send_to_game(new_life)
def do_action(self, action): if action == 'slow_down': self.change_game_speed(.9) elif action == 'normal_speed': self.set_normal_speed() elif action == 'speed_up': self.change_game_speed(1.11) ''' elif action == 'zoom_out': self.box = self.box*.9 elif action == 'zoom_in': self.box = self.box*1.11 ''' elif action == 'clear': self.restart = True else: new_life = [] pattern = Pattern(action, (90, 60)) coordinate_list = pattern.create_pattern() for coordinate in coordinate_list: new_life.append(Cell(coordinate)) self.send_to_game(new_life)
def test_rotations(n, transformation): from life import Pattern test_pattern = np.array([ [0, 0, 0, 0, 0, 0, 1, 0], [1, 1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 1, 1, 1] ]) test_flipped = Pattern(test_pattern) assert np.array_equal(test_flipped.rotate(n).grid, transformation), \ "rotate(n) transformation incorrect / wrong dimensions" assert np.array_equal(test_flipped.grid, test_pattern), \ "rotate(n) modifying original pattern"
def test_flip_vertical(): from life import Pattern test_pattern = np.array([ [0, 0, 0, 0, 0, 0, 1, 0], [1, 1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 1, 1, 1] ]) vflip_pattern = np.array([ [0, 1, 0, 0, 0, 1, 1, 1], [1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0]] ) test_flipped = Pattern(test_pattern) assert np.array_equal(test_flipped.flip_vertical().grid, vflip_pattern), \ "flip_vertical() transformation incorrect" assert np.array_equal(test_flipped.grid, test_pattern), \ "flip_vertical() modifying original pattern"
def test_flip_diag(): from life import Pattern test_pattern = np.array([ [0, 0, 0, 0, 0, 0, 1, 0], [1, 1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 1, 1, 1] ]) diag_pattern = np.array([ [0, 1, 0], [0, 1, 1], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 1], [1, 0, 1], [0, 0, 1] ]) test_flipped = Pattern(test_pattern) assert np.array_equal(test_flipped.flip_diag().grid, diag_pattern), \ "flip_diag() transformation incorrect / wrong dimensions" assert np.array_equal(test_flipped.grid, test_pattern), \ "flip_diag() modifying original pattern"
def test_insert(grid_size, coordinates, board): from life import Game, Pattern, glider g = Game(grid_size) g.insert(Pattern(glider), coordinates) assert np.array_equal(g.board, board)
from life import Game, Pattern, glider g = Game(30) g.insert(Pattern(glider), [1, 1]) g.insert(Pattern(glider).flip_horizontal(), [1, 28]) g.play()
def test_pattern_grid(): from life import Pattern, glider assert np.array_equal(Pattern(glider).grid, glider), \ "Pattern.grid incorrectly defined"