Esempio n. 1
0
def rule_boring():
    explode = 0
    die = 0
    num_trial = 8

    for i in range(num_trial):
        g.new("")
        g.select([0, 0, 32, 32])
        g.randfill(50)

        g.run(16)

        if int(g.getpop()) == 0:
            die += 1
            continue

        r = g.getrect()

        if r[2] > 60 and r[3] > 60:
            explode += 1
            continue

        return -1

    if explode == num_trial:
        return 0

    if die == num_trial:
        return 1

    return -1
Esempio n. 2
0
def better_randfill():
    g.new('')
    g.select([-10, -10, GRID_SIZE[0], GRID_SIZE[1]])
    g.randfill(random.randrange(50))
    g.select([])
    g.autoupdate(True)

    cnt = 0
    for x in range(0, GENS):
        cnt += 1
        if not g.empty():
            g.run(1)
            if is_static():
                break
            time.sleep(0.05)
        else:
            break
        if cnt % 10 == 0:
            g.fit()
Esempio n. 3
0
def explode_dense():

    num_trial = 2

    for i in range(num_trial):
        g.new("")
        g.select([0, 0, 32, 32])
        g.randfill(50)

        g.run(128)

        total = 0

        for i in range(32):
            total += len(g.getcells([0, 0, 32, 32])) / 2
            g.run(32)

        total /= 32

        if total >= 300:
            return True

    return False
    "What is the maximum number of generations to run each soup?")
rawentry3 = g.getstring("How many soups do you want to test?")

periodlist = map(int, rawentry1.split(','))
maxgens = int(rawentry2)
soups = int(rawentry3)

totalperiod = 1
for period in periodlist:
    totalperiod = lcm(period, totalperiod)

longest = [], 0
for soupnum in range(soups):
    g.new('')
    g.select([0, 0, 5, 5])
    g.randfill(50)
    currsoup = g.getcells([0, 0, 5, 5])
    currpop = g.getpop()
    sameaslast = 0
    totalgens = 0
    success = False
    while totalgens < maxgens:
        g.run(totalperiod)
        totalgens += totalperiod
        if g.getpop() == currpop:
            sameaslast += 1
        else:
            sameaslast == 0
        currpop = g.getpop()
        if sameaslast == 5:
            # We assume it's stabilized
Esempio n. 5
0
soupfilepath = "/home/scorbie/Apps/ptbtest/random"
nsoups = int(g.getstring("How many soups?", "1000"))
soupsize = 10  # int(g.getstring('Soup size?', '10'))

if g.getrule() == "LifeHistory":
    g.setrule("B3/S23")
if g.numstates() > 2:
    g.exit("This script only works with two-state rules.")

soups = []
x, y, w, h = r = [0, 0, soupsize, soupsize]
cellchar = [".", "a"]
while len(soups) < nsoups:
    g.new("Generating Soups")
    g.select(r)
    g.randfill(40)
    g.run(250)
    # To avoid 'Empty Pattern!' messages in status bar.
    if int(g.getpop()) == 0:
        continue
    if not q.testquiescence(60):
        g.reset()
        soupstr = "!".join(
            "".join(cellchar[g.getcell(i, j)] for j in xrange(0, soupsize + 1)) for i in xrange(0, soupsize + 1)
        )
        soups.append(soupstr)
        g.show("Soup {}/{}".format(len(soups), nsoups))
with open(soupfilepath, "w") as soupfile:
    soupfile.write("\n".join(soups))
    g.show("Soups successfully saved in {}.".format(soupfilepath))
Esempio n. 6
0
# -----------------------------------------------------------------------------

# Open Current Generation's Rule Sets to Parse
rulesFileName = "rule_sets" + str(currentGen) + ".txt"
genRules = open(rulesFileName, 'r')

# Update Current Generation
newGen = rootGA.find("CurrentGeneration")
newGen.text = str(int(currentGen) + 1)
tree.write('config.xml')

for j in range(int(numPopulation)):
    # Create New Window and Fill X% of YxY Square Grid with Random Noise
    g.new("test-pattern")
    g.select([0, 0, int(gridSize), int(gridSize)])
    g.randfill(int(fillPerc))

    # Declare Algorithm and Rule
    g.setalgo("QuickLife")

    # Read In Rule Set from File
    rule = genRules.readline().strip()
    g.setrule(rule)

    # Set Directory Back to Parent Folder
    fileLoc = g.getdir("rules") + generationDir
    # Creates Subfolder specific to Rule Set to hold Generation Patterns
    fileLoc += rule.replace("/", "_") + "/"
    if (os.path.isdir(fileLoc) is not True):
        os.mkdir(fileLoc)
Esempio n. 7
0
    def __init__(self):
        try:
            g.show('setting up test')


            testSize = 100 #this is the size of one side of the square testing area
            g.select([-testSize/2,-testSize/2,testSize,testSize])
            #clear the canvas
            g.clear(1)
            g.clear(0)
            g.randfill(50)
            g.update()

            g.show('stressTest started')

            startTime = time()
            lg_envmt = lifegenes_environment()
            endTime = time()
            logging.debug('\tsetup t\t=\t\t'+str(endTime-startTime))
            g.update()

            startTime = time()
            lg_envmt.drawColor()
            endTime = time()
            logging.debug('\tcolorDraw t\t=\t' + str( endTime - startTime))
            g.update()
            
            startTime = time()
            lg_envmt.cellMotions()
            endTime = time()
            logging.debug('\tmovement t\t=\t' + str( endTime - startTime))
            g.update()

            startTime = time()
            lg_envmt.drawColor()
            endTime = time()
            logging.debug('\tcolor update t \t= ' + str( endTime - startTime))
            g.update()

            g.step()

            startTime = time()
            lg_envmt.update()
            endTime = time()
            logging.debug('\tevolve update t\t= ' + str( endTime - startTime))

            startTime = time()
            lg_envmt.cellMotions()
            endTime = time()
            logging.debug('\tmovement t\t=\t' + str( endTime - startTime))
            g.update()

            startTime = time()
            lg_envmt.drawColor()
            endTime = time()
            logging.debug('\tcolor update t\t= ' + str( endTime - startTime))
            g.update()



            g.update()
            g.show('test complete')
        finally:
                logging.info('cycling halted from external source (probably golly)')
Esempio n. 8
0
def fail_cd():
    num_trial = 5
    status = [0, 0, 0, 0]

    for i in range(num_trial):
        g.new("")
        g.select([0, 0, 32, 32])
        g.randfill(50)

        ws = []
        hs = []
        pop = []

        for i in range(20):
            g.run(120)
            w, h, p = getwhp()
            ws.append(w)
            hs.append(h)
            pop.append(p)

        dw = ws[19] - ws[18]
        dh = hs[19] - hs[18]

        if dw < 3 and dh < 3:
            status[2] += 1
            continue

        if len(g.getcells([-64, -64, 128, 128])) == 0:
            status[1] += 1
            continue

        fail = False

        for i in range(14, 19):
            if abs(pop[19] - pop[i]) > 25:
                status[0] += 1
                fail = True
                break

        if fail:
            continue

        for i in range(10, 20):
            w = ws[i] - ws[i - 1]

            if abs(dw - w) > 4:
                fail = True
                status[3] += 1
                break

        if not fail:
            return -1

        for i in range(10, 20):
            h = hs[i] - hs[i - 1]

            if abs(dh - h) > 4:
                fail = True
                break

        if not fail:
            return -1

    maxi = -1
    maxv = 0

    for i in range(4):
        if status[i] > maxv:
            maxi = i
            maxv = status[i]

    return maxi
Esempio n. 9
0
def randfill(x, y):
    g.select([-int(x / 2), -int(y / 2), x, y])
    g.clear(0)
    g.randfill(50)
    g.select([])
    while i < w:
        j = 0
        while j < h:
            g.setcell(i, j, update[i][j])
            j += 1
        i += 1
    g.update()
    return update


try:
    g.new("Conway's Game of life")
    g.setrule("Life")
    g.setcolors([1, 255, 255, 255])
    g.setcolors([0, 0, 0, 0])
    maxsize = 100000
    count = 0
    width = int( g.getstring("Enter a width for the game of life:", "100") )
    height = int( g.getstring("Enter a height for the game of life:", "100") )
    g.select([0, 0, width, height])
    g.randfill(50)
    update = [[0 for x in range(width + 1)] for x in range(height + 1)]
    while count < maxsize:
        g.show("In main " + str(count))
        update = main(width, height, update)
        count += 1


finally:
    g.note("Goodbye")