SHOW:
|
|
- or go back to the newest paste.
1 | import random as r | |
2 | ||
3 | - | EverythingInExistence = [] # doesn't do anything, just a comment in the form of code |
3 | + | |
4 | ||
5 | - | class Bootstrap: |
5 | + | |
6 | print "Hello, Universe!" | |
7 | - | def __init__(self): |
7 | + | |
8 | ||
9 | - | ux = 6 |
9 | + | |
10 | - | uy = 6 |
10 | + | |
11 | - | ut = 3 |
11 | + | |
12 | print "\nInit univ:\n" | |
13 | - | uinput = raw_input(" > (Int) [" + str(ux) + "] Universe X dimension: ") |
13 | + | |
14 | - | if uinput != "": |
14 | + | |
15 | - | ux = int(uinput) |
15 | + | |
16 | print "\nInit timeBuffer:\n" | |
17 | - | uinput = raw_input(" > (Int) [" + str(uy) + "] Universe Y dimension: ") |
17 | + | |
18 | - | if uinput != "": |
18 | + | |
19 | - | uy = int(uinput) |
19 | + | |
20 | if progenitor and deviation: | |
21 | - | uinput = raw_input(" > (Int) [" + str(ut) + "] Universe Timesteps to run: ") |
21 | + | |
22 | - | if uinput != "": |
22 | + | |
23 | - | ut = int(uinput) |
23 | + | |
24 | #else: | |
25 | - | print "\nRun grid [" + str(ux) + ", " + str(uy) + "] for " + str(ut) + " steps.\n" |
25 | + | # pass |
26 | self.x = x-1 | |
27 | - | EverythingInExistence.append(Universe(ux,uy)) |
27 | + | self.y = y-1 |
28 | self.branches = [] | |
29 | - | for t in range(ut): |
29 | + | |
30 | - | for i in EverythingInExistence: |
30 | + | |
31 | - | print "Run all universes (" + str(t) + ", " + str(i) + ") " |
31 | + | if x == self.x or x == 0 or y == self.y or y == 0: # we should implement dynamic sizing soon |
32 | - | i.update(i) |
32 | + | |
33 | ||
34 | sum = r.randint(0,8) #[sum(i) for i in self.univ[y-1:y+1]]# :( this offends my determinist sensibilities | |
35 | ||
36 | if sum == 3: | |
37 | return 1 | |
38 | elif sum == 2 and (self.univ[x][y] == 1): | |
39 | return 1 | |
40 | elif sum > 6: | |
41 | self.branch(sum - 6) | |
42 | return 0 | |
43 | else: | |
44 | return 0 | |
45 | ||
46 | def update(self,univ): | |
47 | print "Update..." | |
48 | temp = univ | |
49 | ||
50 | self.univ = [[self.getNextState(i,j) for i in range(self.y)] for j in range(self.x)] | |
51 | ||
52 | print "\nCGoL Update:\n" | |
53 | for i in self.univ: | |
54 | print i | |
55 | ||
56 | - | pass |
56 | + | |
57 | - | self.x = x+1 |
57 | + | |
58 | - | self.y = y |
58 | + | theRealBranch(self.timeBuffer, self.branches) |
59 | - | self.branches = [] |
59 | + | |
60 | #for i in range(univ.y): # What's this? | |
61 | # for j in range(univ.x): | |
62 | - | if x == self.x or x == 0 or y == self.y or y == 0: |
62 | + | |
63 | ||
64 | branches = [] | |
65 | - | sum = r.randint(0,8) #[sum(i) for i in self.univ[y-1:y+1]] |
65 | + | |
66 | ||
67 | def branch(self, sum): | |
68 | print "Branch!" | |
69 | self.branches.append([self.x,self.y,sum - 6]) | |
70 | self.timeBuffer[self.x][self.y] = (0, sum - 6) | |
71 | ## Code Transplant ## | |
72 | - | self.branch(sum - 6) |
72 | + | |
73 | def theRealBranch(self,timeBuffer, branches): | |
74 | creating = True | |
75 | while creating: | |
76 | counter = 0 | |
77 | list = [0 for i in branches] | |
78 | for i in list: | |
79 | ||
80 | print "Creating branch", str(counter) | |
81 | ||
82 | tempTimeBuffer = self.timeBuffer # There are just temporary variables here | |
83 | tempDevi = self.template # while their universe is being created | |
84 | ||
85 | counter += 1 # keep track of where we are | |
86 | ||
87 | tempDevi[branches[counter][x]][branches[counter][1]] = list[counter] | |
88 | ||
89 | - | #theRealBranch(self.timeBuffer) |
89 | + | for i in branches: # updates timeBuffer to stop weird stuff from happening in the new universe |
90 | tempTimeBuffer[branches[1]][branches[2]] = [list[counter], branches[2]] | |
91 | - | #for i in range(univ.y): |
91 | + | |
92 | EverythingInExistence.append(Universe(self.x, self.y, self.univ, tempDevi)) | |
93 | myCreation = EverythingInExistence(len(EverythingInExistence)-1) | |
94 | myCreation.timeBuffer = tempTimeBuffer | |
95 | ||
96 | list[counter] += 1 | |
97 | ||
98 | if list[counter] == 2: | |
99 | - | print "Do branch" |
99 | + | |
100 | for i in range(list): # list is represented as a binary number, and incremented | |
101 | - | #self.timeBuffer[self.x][self.y] = (0, sum - 6) |
101 | + | |
102 | j = len(list) - i | |
103 | ||
104 | if list[j] == 2 and not j == 0: | |
105 | - | bs = Bootstrap() |
105 | + | |
106 | - | print '[%s]' % ', '.join(map(str, EverythingInExistence)) |
106 | + | list[j] -= 1 |
107 | list[j-1]+=1 | |
108 | ||
109 | elif j == 0 and list[j] == 2: | |
110 | ||
111 | creating = False | |
112 | ||
113 | break | |
114 | ||
115 | else: | |
116 | ||
117 | continue | |
118 | ||
119 | else: | |
120 | ||
121 | continue | |
122 | ||
123 | if __name__ == "__main__": | |
124 | ||
125 | EverythingInExistence = [] | |
126 | ||
127 | ux = 6 | |
128 | uy = 6 | |
129 | ut = 3 | |
130 | ||
131 | uinput = raw_input(" > (Int) [" + str(ux) + "] Universe X dimension: ") | |
132 | if uinput != "": | |
133 | ux = int(uinput) | |
134 | ||
135 | uinput = raw_input(" > (Int) [" + str(uy) + "] Universe Y dimension: ") | |
136 | if uinput != "": | |
137 | uy = int(uinput) | |
138 | ||
139 | uinput = raw_input(" > (Int) [" + str(ut) + "] Universe Timesteps to run: ") | |
140 | if uinput != "": | |
141 | ut = int(uinput) | |
142 | ||
143 | print "\nRun grid [" + str(ux) + ", " + str(uy) + "] for " + str(ut) + " steps.\n" | |
144 | ||
145 | EverythingInExistence.append(Universe(ux,uy)) | |
146 | ||
147 | for t in range(ut): | |
148 | for i in EverythingInExistence: | |
149 | print "Run all universes (" + str(t) + ", " + str(i) + ") " | |
150 | i.update(i) | |
151 | ||
152 | # print '[%s]' % ', '.join(map(str, EverythingInExistence)) |