#  © Connor Bailey and Nate Delgado import random field_size = 100 elements = field_size ** 2 tiles = [[0,0,0,0,0] for it in range(10000)] # tiles = [x,y,z,temp,texture] ratio = [0,0] delay = [0,0] moves = 0 regenseed = 0 regen = False sets = 0 setup = [0,0] setup[0] = random.choice([303,304,404,403]) setup[1] = 9999 texts = ['danger', 'water', 'dirt', 'stone'] temps = [1750, 66, 55, 47] def neighbors( xy):    n = [ 0, 0, 0, 0]    x = xy[0]    y = xy[1]    n[0] = tile( xr( x), y)    n[1] = tile( xl( x), y)    n[2] = tile( x, ya( y))    n[3] = tile( x, yb( y))    return n def map():    s = ''    y = 99    x = 0    while y >= 0:        while x < field_size:            m = tiles[tile ( x, y)][4]            if m == 'danger':                m = 'D'            elif m == 'stone':                m = ' '            elif m == 'dirt':                m = ' '            elif m == 'water':                m = ' '            s = s + str(m)            x += 1        x = 0        y -= 1        print (s)        s = '' randints = 0 dangers = 0 max = 4 def get_rand():    global randints, dangers, max    n = random.randint(0,3)    randints += 1    if n == 0:        dangers += 1    if dangers / randints > max / 100:        randints -= 1        dangers -= 1        n = get_rand()    return n def dump_tiles():    i = 0    while i < elements:        list = [tiles[i+j] for j in range(field_size)]        print (list)        print ("\n")        i += field_size def xr( x):    r = x+1    if r % field_size == 0:        r = -1    return r def xl( x):    r = x-1    if (r < 0) or (r % field_size == field_size -1):        r = -1    return r def ya( y):    r = y + 1    if r == field_size :        r = -1    return r def yb( y):    r = y - 1    if r < 0 :        r = -1    return r def tile( x, y):    if x < 0 or y < 0:        return -1    return (field_size * y) + x def seed_config():   print('SCC 2012 (Nate Delgado + Connor Bailey)')   in1 = int(input('Run with seed? '))   seed = in1   print('Running with seed "' + str(seed) + '"...')   random.seed(seed)   print('Beggining The Configuation - ') def xy_config():   i = 0   for i in range(10000):       tiles[i][0] = i % 100       tiles[i][1] = i // 100       tiles[i][2] = 1       i += 1   print('20% done...') def temp_seed_config():   x = 0   y = 0   while y < field_size:       while x < field_size:           curtext = tiles[(100 * y) + x][4]           if curtext == 'danger':               tiles[(100 * y) + x][3] = random.randint(1300,2200)           if curtext == 'water':               tiles[(100 * y) + x][3] = random.randint(64,68)           if curtext == 'dirt':               tiles[(100 * y) + x][3] = random.randint(50,55)           if curtext == 'stone':               tiles[(100 * y) + x][3] = random.randint(43,50)           x += 1       x = 0       y += 1   print('100% done...') def temp_avg_config():    x = 0    y = 0    while y < field_size:        while x < field_size:            directions = neighbors( (x, y))            curtemp = tiles[(100 * y) + (x)][3]            sum = 0            num = 0            for i in range(4):                if directions[i] >= 0:                    sum += tiles[directions[i]][3]                    num += 1            avg = round (sum / num, 2)            tiles[(100 * y) + (x)][3] = avg            x += 1        x = 0        y += 1    print("Loading...") def texture_seed_config():   x = 0   y = 0   while y != 100:       while x != 100:           tiles[(100 * y) + x][4] = texts[get_rand()]           x += 4       x = 0       y += 4   print('40% done...') def texture_cross_config():   it = 0   itr = 0   x = 0   y = 0   while itr != len(texts):       curtext = texts[itr]       while y < field_size:           while x < field_size:               while it != 4:                   directions = [(100 * (y)) + ((x) + 1), (100 * (y)) + ((x) - 1), (100 * ((y) + 1)) + (x), (100 * ((y) - 1)) + (x)]                   if x != 0 and x != 99 and y != 99 and y != 0:                       if tiles[(100 * y) + (x)][4] == curtext:                           tiles[(directions[it])][4] = curtext                   it += 1               x += 4               it = 0           y += 4           x = 0       itr += 1       y = 0   print('60% done...') def texture_fill_config():   neartexts = [0,0,0,0]   i = 0   it = 0   lol = 0   itr = 0   x = 0   y = 0   ugh = 0   while lol != 11:       while i != 10000:           if tiles[i][4] == 0:               while it != 4:                   directions = [(100 * (tiles[i][1])) + ((tiles[i][0]) + 1), (100 * (tiles[i][1])) + ((tiles[i][0]) - 1), (100 * ((tiles[i][1]) + 1)) + (tiles[i][0]), (100 * ((tiles[i][1]) - 1)) + (tiles[i][0])]                   if (directions[it] // 100) == 100 or (directions[it] // 100) == -1  or (directions[it] % 100) == 100 or (directions[it] % 100) == -1:                       neartexts[it] = 0                   else:                       neartexts[it] = tiles[(directions[it])][4]                   if neartexts[it] == 1:                       neartexts == get_rand()                   it += 1                   while tiles[i][4] == 0 and ugh < 50:                       tiles[i][4] = random.choice(neartexts)                       ugh += 1                   ugh = 0               it = 0           i += 1       lol += 1       i = 0   print('80% done...') def cmd_config():       print('Welcome to ConfigDebuggerCLI!')       print('Hit "Enter" to skip me...')       while 1:           in1 = input('>>> ')           if in1 == '':               print('Bye! Have fun executing the rest of the program. ;)')               logger()           elif in1 == 'bt':               config.biome_test()           elif in1 == 'tt':               in1 = int(input('Tile #: '))               print(tiles[in1])           elif in1 == 'all':               print(tiles)           elif in1 == 'ct':               x = int(input('X: '))               y = int(input('Y: '))               print((100 * y) + x)               print(tiles[(100 * y) + x])           elif in1 == 'rt':               i = 0               while i != 10000:                   if tiles[i][4] == 0:                       print((tiles[i][1] * 100) + tiles[i][0])                   i += 1               print('Done')           else:               print('Sorry, I did not understand that.') def logger():   print('************************************')   print('Running Logger')   checked = False   while checked == False:       choice = input('Do you want to continue these tests ("n" to setup a test): ')       if choice == '' or choice == 'y':           checked = True       if choice == 'n':           in1 = input('Test type or debug (q,s, debug, regen, reratio): ')           if in1 == 'debug':               cmd_config()           if in1 == 'q':               in2 = input('Haptics: ')               if in2 == 'y':                   checked = True                   qh()               if in2 == 'n':                   checked = True                   qnh()           if in1 == 's':               in2 = input('Haptics: ')               if in2 == 'y' or in1 == '':                   checked = True                   speed_tests()               if in2 == 'n':                   checked = True                   speed_tests()           if in1 == 'regen':               print('Regenerating environment...')               regen(False,0)           if in1 == 'reratio':               #print('Previous ratio: ' + str(ratio[0]) + ' successes, ' + str(ratio[1]) + ' failures!')               ratio = 0           if in1 == 'clear':               ratio = 0               moves = 0               sets = 0               delay = 0               regenseed = 0           else:               checked = False       else:           checked = False def qh():   print('************************************')   print('The coordinates for the goal tile are X: '+ str(tiles[setup[1]][0]) + ' Y: ' + str(tiles[setup[1]][1]))   ftest = 0   i = 0   coords = [0,0]   moves = 0   coords[0] = tiles[setup[0]][0]   coords[1] = tiles[setup[0]][0]   while ftest != setup[1]:       print('X: ' + str(coords[0]) + ' Y: ' + str(coords[1]))       tnum = (coords[1]) * 100 + coords[0]       print('Type: ' + str(tiles[tnum][4]))       print('Temp: ' + str(tiles[tnum][3]))       while i == 0:           in1 = input('WASD: ')           if in1 == 'w':               coords[1] += 1               i = 2           if in1 == 'a':               coords[0] -= 1               i = 2           if in1 == 's':               coords[1] -= 1               i = 2           if in1 == 'd':               coords[0] += 1               i = 2           else:               pass           ftest = coords[1] * 100 + coords[0]       if tiles[tnum][4] == 'danger':           print('Oh no!!! You hit danger')           ratio[1] += 1           print('There have been ' + str(ratio[0]) + ' successes, and ' + str(ratio[1]) + ' failures')       print('************************************')       i = 0       moves += 1   print('Wow you won!! Be sure to record the value below!')   print('It took ' + str(moves) + ' moves to finish this test.') def qnh():   print('The coordinates for the goal tile are X: '+ str(tiles[setup[1]][0]) + ' Y: ' + str(tiles[setup[1]][1]))   ftest = 0   i = 0   coords = [0,0]   moves = 0   coords[0] = tiles[setup[0]][0]   coords[1] = tiles[setup[0]][0]   while ftest != setup[1]:       print('X: ' + str(coords[0]) + ' Y: ' + str(coords[1]))       tnum = (coords[1]) * 100 + coords[0]       print('Type: ' + str(tiles[tnum][4]))       while i == 0:           in1 = input('WASD: ')           if in1 == 'w':               coords[1] += 1               i = 2           if in1 == 'a':               coords[0] -= 1               i = 2           if in1 == 's':               coords[1] -= 1               i = 2           if in1 == 'd':               coords[0] += 1               i = 2           else:               pass           ftest = coords[1] * 100 + coords[0]       if tiles[tnum][4] == 'danger':           print('Oh no!!! You hit danger')           ratio[1] += 1           print('There have been ' + str(ratio[0]) + ' successes, and ' + str(ratio[1]) + ' failures')           logger()       print('************************************')       i = 0       moves += 1   print('Wow you won! Be sure to record the value below!')   print('It took ' + str(moves) + ' moves to finish this test.') def speed_tests(regenseed = 0):   delay = [0.0,0.0]   sets = 0   shratio = [0,0]   snhratio = [0,0]   def sh(delay,shratio):       pretile = [0,0,0,3000,0]       curtile = [0,0,0,0,0]       ftest = 0       i = 0       coords = [0,0]       coords[0] = tiles[setup[0]][0]       coords[1] = tiles[setup[0]][0]       while ftest <= 9999 and curtile[4] != 'danger':           if coords[1] == 99 and coords[0] == 99:               break           curtile = tiles[(coords[1] * 100) + coords[0]]           if curtile[3] > pretile[3] + (pretile[3] * .75):               choice = random.randint(0,1)               if choice == 0:                   coords[1] -= 1                   if coords[1] == 100:                      coords[1] -= 1               if choice == 1:                   coords[0] += 1                   if coords[0] == 100:                      coords[0] -= 1           else:               choice = random.randint(0,1)               if choice == 0:                   coords[1] += 1                   if coords[1] == 100:                       coords[1] -= 1               if choice == 1:                   coords[0] += 1                   if coords[0] == 100:                       coords[0] -= 1           ftest = coords[1] * 100 + coords[0]           #print('X: ' + str(curtile[0]) + ' Y: ' + str(curtile[1]))           pretile = curtile           delay[0] += .12       if curtile[4] == 'danger':           shratio[1] += 1       else:           shratio[0] += 1   def snh(delay,snhratio):       sets = 0       curtile = [0,0,0,0,0]       ftest = 0       i = 0       coords = [0,0]       coords[0] = tiles[setup[0]][0]       coords[1] = tiles[setup[0]][0]       while ftest <= 9999 and curtile[4] != 'danger':           if coords[1] == 99 and coords[0] == 99:               break           curtile = tiles[(coords[1] * 100) + coords[0]]           choice = random.randint(0,1)           if choice == 0:               coords[1] += 1               if coords[1] == 100:                   coords[1] -= 1           if choice == 1:               coords[0] += 1               if coords[0] == 100:                   coords[0] -= 1           ftest = coords[1] * 100 + coords[0]           delay[1] += .19       if curtile[4] == 'danger':           snhratio[1] += 1       else:           snhratio[0] += 1   in1 = 999   print('Now crunching large numbers quickly! (Speed Tests: May take a while.)')   while sets <= in1:       sh(delay = delay,shratio = shratio)       snh(delay = delay,snhratio = snhratio)       sets += 1   print('% % % % % % % % **** Results! **** % % % % % % % %')   print('The sum of the Speed with Haptics Tests were: ' + str(delay[0]))   print('The sum of the Speed without Haptics tests were: ' + str(delay[1]))   print('SPEED WITHOUT HAPTICS HAVE GIVEN THIS RESULT: There have been ' + str(snhratio[0]) + ' successes, and ' + str(snhratio[1]) + ' failures')   print('SPEED WITH HAPTICS HAVE GIVEN THIS RESULT: There have been ' + str(shratio[0]) + ' successes, and ' + str(shratio[1]) + ' failures')   print('Now regenerating to do more tests.')   print('\n\n\n\n')   regenseed += 1   delay = [0.0,0.0]   regen(regen = True, regenseed = regenseed) def regen(regen,regenseed):    if regen == True:        regenseed += 1        random.seed(regenseed)        xy_config()        texture_seed_config()        texture_cross_config()        texture_fill_config()        temp_seed_config()        temp_avg_config()        temp_avg_config()        temp_avg_config()        temp_avg_config()        temp_avg_config()        temp_avg_config()        print ("Configuration Complete")        runlogger = False    else:        seed_config()        xy_config()        texture_seed_config()        texture_cross_config()        texture_fill_config()        temp_seed_config()        temp_avg_config()        temp_avg_config()        temp_avg_config()        temp_avg_config()        temp_avg_config()        temp_avg_config()        print ("Configuration Complete")        runlogger = True    if runlogger == True:        logger()    else:        speed_tests(regenseed) regen(regen = False, regenseed = 0)