Exemplo n.º 1
0
def runrecording():
    # reset the checkboxes
    inframe.reset()
    anigrid.delete(ALL)
    recd = open("record.txt")
    ngrid = []
    # get the rows and columns from the first line
    layout = recd.readline().split(" ")
    rows = int(layout[0])
    cols = int(layout[1])

    for line in recd:
        # decode the line
        decode = ""
        for a in line:
            if a == '0':
                space = "0"*int(a)
                decode+=space
            else:
                decode+=a

        ngrid = cagrid(rows, cols, 0, 0 ,0 , decode)
        anigrid.after(100, PrintGrid(ngrid))

        if inframe.interrupt():
            break

    recd.close()
Exemplo n.º 2
0
def startrun():
    """ Start the simulation
    """
    # catch errors
    try:
        time1 = time.time()
        inframe.reset()
        # set grid size, get the values from the entry boxes
        # reset the checkboxes
        rows = int(inframe.rows())
        cols = int(inframe.columns())
        empty = float(inframe.empty())
        lions = float(inframe.lions())
        antelopes = float(inframe.antelopes())
        grid = cagrid(rows, cols, empty, lions, antelopes, False)

        # enter how many generations it should run, if nothing is entered
        # gen stays -1 and the generations loop runs indefinately
        gen = -1
        run = inframe.generations()
        if run:
            gen = int(run)

        # print the initial grid
        PrintGrid(grid)
        # record the initial grid
        firstRecording(grid)

        # run the generation
        stop = 0
        ext = False
        # the generation runs until "gen" or indefinately
        # and while the user has not pressed stop
        while stop!=gen and not ext:
            grid = Generation.run(grid, inframe.features(), inframe.recording())

            # the canvas is only changed after a period of time
            anigrid.after(100, PrintGrid(grid))

            # increment the loop counter
            stop+=1
            # check whether the stop button has been pressed
            ext = inframe.interrupt()

        finished(grid)

        time2 = time.time()
        print (time2-time1)
    # display an error message box
    except ValueError:
        tkMessageBox.showerror(title = "Error",
                                message = "Please enter only numbers")
    except IndexError:
        tkMessageBox.showerror(title = "Error",
                                message = "Please enter positive numbers")
    except TclError:
         pass
    except Exception, e:
        print e
        tkMessageBox.showerror(title = "Error",
                                message = "Unknown error:\nPlease try again")