def main(): grid = LifeGrid(GRID_WIDTH, GRID_HEIGHT) grid.configure(INIT_CONFIG) #play the game draw(grid) for i in range(NUM_GENS): evolve(grid) draw(grid)
def main(): # Construct the game grid and configure it. grid = LifeGrid(GRID_WIDTH, GRID_HEIGHT) grid.configure(INIT_CONFIG) # Play the game. draw(grid, 0) for i in range(1, NUM_GENS): evolve(grid) draw(grid, i)
def test_numLiveNeighbors(self): lifegrid = LifeGrid(5, 5) lifegrid.configure([(1, 1)]) self.assertEqual(lifegrid.numLiveNeighbors(1, 1), 0) self.assertEqual(lifegrid.numLiveNeighbors(0, 0), 1) self.assertEqual(lifegrid.numLiveNeighbors(3, 3), 0) lifegrid.setCell(0, 0) self.assertEqual(lifegrid.numLiveNeighbors(0, 1), 2)
def main(): grid = LifeGrid(GRID_WIDTH, GRID_HEIGHT) grid.configure(INIT_CONFIG) grid.drawGrid() print('\n') for i in range(NUM_GENS): evolve(grid) grid.drawGrid() print('\n')
def main(): # Construct the game grid and configure it. grid = LifeGrid(GRID_WIDTH, GRID_HEIGHT) grid.configure(INIT_CONFIG) # Play the game. print draw(grid) for i in range(NUM_GENS): evolve(grid) print draw(grid)
def main(): # Construct the game grid and configure it. grid = LifeGrid() grid.configure(coordinateList) # Play the game. draw(grid) for i in range(NUM_GENS): evolve(grid) draw(grid)
def main(): prompt() grid = LifeGrid(GRID_WIDTH, GRID_HEIGHT) grid.configure(INIT_CONFIG) draw(grid) for i in range(NUM_GENS): evolve(grid) draw(grid)
def main(): GRID_WIDTH = int(raw_input("Grid width:")) GRID_HEIGHT = int(raw_input("Grid height:")) NUM_GENS = int(raw_input("Nbr of generations to evolve:")) grid = LifeGrid(GRID_WIDTH, GRID_HEIGHT) grid.configure(INIT_CONFIG) # Play the game. draw(grid) for i in range(NUM_GENS): evolve(grid) draw(grid)
def main(): # Construct the game grid and configure it. grid = LifeGrid(GRID_WIDTH, GRID_HEIGHT) grid.configure(INIT_CONFIG) # Play the game. print('This is the initial generation: ') draw(grid) for i in range(NUM_GENS): print('This is generation %s: ' % (i + 1)) evolve(grid) draw(grid)
def main(): GRID_HEIGHT = GRID_WIDTH = int( input("Enter grid size:") ) NUM_GENS = int( input("Enter generation: ") ) # Construct the game grid and configure it. grid = LifeGrid( GRID_WIDTH, GRID_HEIGHT ) grid.configure( INIT_CONFIG ) # Play the game. draw( grid ) for i in range( NUM_GENS ): evolve( grid ) draw( grid )
def main(): # Construct the game grid and configure it. GRID_WIDTH = int(input("Enter width for the grid: ")) GRID_HEIGHT = int(input("Enter height for the grid: ")) NUM_GENS = int(input("Enter number of generations: ")) INIT_CONFIG = randomInitial(GRID_WIDTH, GRID_HEIGHT) print(INIT_CONFIG) grid = LifeGrid(GRID_WIDTH, GRID_HEIGHT) grid.configure(INIT_CONFIG) # Play the game draw(grid) for i in range(NUM_GENS): evolve(grid) draw(grid)
def main(): # Construct the game grid and configure it. grid = LifeGrid( GRID_WIDTH, GRID_HEIGHT ) grid.configure( INIT_CONFIG ) # Play the game. draw(grid) print(grid._grid[3,2]) # test numLiveNeighbors in LifeGrid class print(grid.numLiveNeighbors(1, 2)) for i in range( NUM_GENS ): print("This is the %d genertion" %i) evolve( grid ) draw( grid )
def main(): ## prompt the user for the grid size and generations GRID_WIDTH = int(raw_input("Enter the width of grid:>>>")) GRID_HEIGHT = int(raw_input("Enter the height of grid:>>>")) NUM_GENS = int(raw_input("Enter the generations of grid:>>>")) #Construct the game grid and configure it. grid = LifeGrid(GRID_WIDTH, GRID_HEIGHT) grid.configure(INIT_CONFIG) # generate the next generation of organisms def evolve(grid): #List for storing the live cells of the next generation. liveCells = list() for i in range(grid.numRows()): for j in range(grid.numCols()): neighbors = grid.numLiveNeighbors(i, j) ##print "(i,j)=(",i,",",j,") ","neighbors= ",neighbors if ( neighbors == 2 and grid.isLive(i,j)) or\ ( neighbors == 3 ): liveCells.append((i, j)) grid.configure(liveCells) def draw(grid): for i in range(grid.numRows()): for j in range(grid.numCols()): if grid.isLive(i, j): print "@", else: print ".", print "" #Start the game. print "Generation = ", 0 draw(grid) for i in range(NUM_GENS): print "Generation = ", i + 1 evolve(grid) draw(grid)
def test_clearCell(self): lifegrid = LifeGrid(5, 5) lifegrid.configure([(0, 0)]) self.assertEqual(lifegrid.isLiveCell(0, 0), True) lifegrid.clearCell(0, 0) self.assertEqual(lifegrid.isLiveCell(0, 0), False)