def set_up_game(self, init_input): """ This method overrides the inherited set_up_game method, setting up the Game of Life with an initial pattern to be given to the game engine. @param init_input The initial input to give to the GoL game engine. """ GameController.set_up_game(self) # Create the initial input cell_pattern = [] init_input = init_input.split("\n") for row in range(0, len(init_input)): cell_pattern.append([]) for i in init_input[row]: if i == "*": # If the cell is a *, it is meant to be alive, and so set a GoL cell with an alive state. cell_pattern[row].append(GolCell(Alive())) else: # Any other character represents death, and so set a GoL cell with a dead state. cell_pattern[row].append(GolCell()) initial_input = GolGrid() initial_input.set_cells(cell_pattern) # Create the Rule Set rule_set = RuleSetStandard() # Set up game self._game = GameOfLife(rule_set, initial_input)
def test_set_cells(self): """ This method tests the ability of the GoLGrid to store a collection of GoLCells. The expected result of this tests is that a collection of GoLCells can be correctly set. """ test_grid = GolGrid() # Create a collection of GolCell objects # Hard coding the expectation of a 10 x 10 2D array as it will fail # if someone changes the keyword parameters s = 10 cells = [] for x in range(0, s): cells.append([]) for y in range(0, s): c = GolCell() if y % 2 == 0: c.set_state(Alive()) cells[x].append(c) test_grid.set_cells(cells) # Assert that the collection of GoLCells has been set correctly. assert test_grid.get_cells() recieved_cells = test_grid.get_cells() for x, row in enumerate(recieved_cells): # For each row of cells. for y, _column in enumerate(row): # Assert that the GoLCell at these 'coordinates' is the correct GoLCell. assert recieved_cells[x][y] == cells[x][y]