from draw_gol import *
import time

def create_game(input_file):
    """
    Reads from open file input_file the configuration of a Game of Life board
    and creates the resulting Game of Life.  Note that input_file is expected
    to be laid out as follows:
        * The first line consists of the size of the grid.  The number of rows
          should be first, then the number of columns
        * The second line should be the generation number at which to start the
          game.
        * The rest of the file consists of the live cells, one cell per line.
          The row of a cell comes first, then the column.
    Calls seed_game
    """

def seed_game(self, seed):
    """
    self is a dictionary respresenting a game of life.  seed is a list of
    cells which should be set to alive.  A cell is also represented by a
    dictionary - it has a row and a column.
    Changes self so that all of and only the cells in seed are set to alive in
    self.
    Calls blank_board
    """

def blank_board(rows, cols):
    """
    Returns a grid of size rows by cols of all dead cells.  NOTE: Each cell
    must be *unique* in the sense that changing the state of any one cell DOES
    NOT also cause other cells' states to have changed.
    """

def tick(self):
    """
    Applies Conway's rules once to self's current grid configuration to get the
    next configuration.  self's generation value should also be incremented.
    Calls blank_board and live_neighbors.
    """

def get_neighbors(self, cell):
    """
    Given the dimensions of Game of Life self, returns a list of cells which
    are all and only the neighbors of cell.  Remember that the game board
    wraps - e.g. the first and last column of self's board are neighbors, as
    well as the first and last row.
    """

def live_count(self, cells):
    """
    Given Game of Life self and cells, which is a list of cells, returns the
    number of live cells on self's board in the list cells.
    """

def live_neighbors(self, cell):
    """
    Given Game of Life self and grid location cell, returns the number of live
    neighbors of cell.
    Calls live_count and get_neighbors
    """

def write_state(self, out_file):
    """
    Writes out the configuration of Game of Life self to open file out_file.
    The output should follow the same format as the input specified for
    create_game.
    Calls write_cell.
    """

def write_cell(cell, out_file):
    """
    Writes out grid location cell to out_file.  Remember that a cell should
    be on its own line, with it's row followed by its column.  The row and
    column are separated by a space.
    """

def start(fname, ticks):
    """
    Makes a game of life by opening the file at fname and reading the game in
    from that.  Creates a corresponding GameView on which to view the read in
    game, schedules run and then starts the event loop.
    """
    #Game creation code goes below here

    #Game creation code should be above here

    rows = # should be set to the number of rows in created game
    cols = # should be set to the number of columns in created game

    # should be set to the generation on which to stop running the game.  This
    # value should be based on the created game's current generation and the
    # desired number of ticks to run the game.
    stop_generation =

    game_view = GameView(rows, cols)
    
    game_view.after(10, run, game, game_view, stop_generation)
    game_view.mainloop()

def run(game, view, stop_generation):
    """
    Runs game from its current generation until stop_generation, displaying the
    board configuration at each new generation.  When game reaches
    stop_generation, its configuration should be written out to a file called
    endingstate.gol
    """
    # This following line draws the game in its current state
    view.draw_game(game);

if __name__ == '__main__':
    # This line says to read in the machine described in the file
    # 100x100_r-pentomino.gol and run that machine for a total of 1000 ticks
    start('100x100_r-pentomino.gol', 1000)
