import sys from random import choice import cPickle [s1,s2,f1,f2] = [int(i) for i in sys.argv[2:6]] n = int(sys.argv[1]) success = s1,s2 failure = f1,f2 s_count = [] f_count = [] nbrs = [] for i in range(100): s_count.append([0] * 100) f_count.append([0] * 100) x = [] for j in range(100): nb = [] if i>0: nb.append((i-1,j)) if i<99: nb.append((i+1,j)) if j>0: nb.append((i,j-1)) if j<99: nb.append((i,j+1)) x.append(tuple(nb)) nbrs.append(x) count = {} count[success] = s_count count[failure] = f_count #print nbrs[96][12] #print nbrs[0][12] #sys.exit() while n > 0: print n for i0 in range(100): for j in range(100): i = i0 print i,j, locations = [(i,j)] while (i,j) != success and (i,j) != failure: i,j = choice(nbrs[i][j]) locations.append((i,j)) print i,j, len(locations) count_dir = count[i,j] for (i,j) in locations: count_dir[i][j] += 1 n -= 1 for i in range(100): for j in range(100): s = s_count[i][j] f = f_count[i][j] s_count[i][j] = float(s)/(s+f) cPickle.dump(s_count,open(sys.argv[6],'w'))