示例#1
0
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)
示例#2
0
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)
示例#4
0
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')
示例#5
0
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)
示例#6
0
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)
示例#7
0
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)
示例#9
0
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)
示例#10
0
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__init__(self):
     lifegrid = LifeGrid(5, 5)
     self.assertEqual(LifeGrid.DEAD_CELL, 0)
     self.assertEqual(lifegrid.LIVE_CELL, 1)
 def test_setCell(self):
     lg = LifeGrid(5, 5)
     lg.setCell(0, 0)
     self.assertEqual(lg.isLiveCell(0, 0), True)
 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)
 def test_numCols(self):
     lifegrid = LifeGrid(5, 5)
     self.assertEqual(lifegrid.numCols(), 5)