Browse code

Decluttered code

haywalk authored on 22/08/2019 20:10:59
Showing 1 changed files

... ...
@@ -30,7 +30,7 @@ class Space:
30 30
 
31 31
 def startwin():
32 32
 	'''
33
-	Create the window based on specified size
33
+	Create the window based on specified size, and define the edges
34 34
 	'''
35 35
 	global redge
36 36
 	global tedge
... ...
@@ -58,14 +58,8 @@ def genchars():
58 58
 	'''
59 59
 	Randomly generate living/dead squares
60 60
 	'''
61
-	global redge
62
-	global tedge
63
-	global bedge
64
-	global ledge
65
-	global win
66 61
 	global chars
67
-	global wh
68
-
62
+	
69 63
 	chars = list()
70 64
 
71 65
 	for y in range(0, wh, 10):
... ...
@@ -85,37 +79,33 @@ def checkneighbours():
85 79
 	'''
86 80
 	Check how many living neighbours a square has
87 81
 	'''
88
-	global redge
89
-	global tedge
90
-	global bedge
91
-	global ledge
92 82
 
93 83
 	for i in chars:
94 84
 		neighbours = 0
95 85
 		spot = chars.index(i)
96 86
 		# To the left
97
-		if (not (spot in ledge)) and (chars[spot - 1].living == True):
87
+		if (not (spot in ledge)) and (chars[spot - 1].living):
98 88
 			neighbours += 1
99 89
 		# To the right
100
-		if (not (spot in redge)) and (chars[spot + 1].living == True):
90
+		if (not (spot in redge)) and (chars[spot + 1].living):
101 91
 			neighbours += 1
102 92
 		# Below
103
-		if (not (spot in bedge)) and (chars[spot + (wh // 10)].living == True):
93
+		if (not (spot in bedge)) and (chars[spot + (wh // 10)].living):
104 94
 			neighbours += 1
105 95
 		# Above
106
-		if (not(spot in tedge)) and (chars[spot - (wh // 10)].living == True):
96
+		if (not(spot in tedge)) and (chars[spot - (wh // 10)].living):
107 97
 			neighbours += 1
108 98
 		# Diag. upper left
109
-		if (not (spot in tedge)) and (not (spot in ledge)) and (chars[spot - ((wh // 10) + 1)].living == True):
99
+		if (not (spot in tedge)) and (not (spot in ledge)) and (chars[spot - ((wh // 10) + 1)].living):
110 100
 			neighbours += 1
111 101
 		# Diag. bottom right
112
-		if (not (spot in bedge)) and (not (spot in redge)) and (chars[spot + ((wh // 10) + 1)].living == True):
102
+		if (not (spot in bedge)) and (not (spot in redge)) and (chars[spot + ((wh // 10) + 1)].living):
113 103
 			neighbours += 1
114 104
 		# Diag. upper right
115
-		if (not (spot in tedge)) and (not (spot in redge)) and (chars[spot - ((wh // 10) - 1)].living == True):
105
+		if (not (spot in tedge)) and (not (spot in redge)) and (chars[spot - ((wh // 10) - 1)].living):
116 106
 			neighbours += 1
117 107
 		# Diag. bottom left
118
-		if (not (spot in bedge)) and (not (spot in ledge)) and (chars[spot + ((wh // 10) - 1)].living == True):
108
+		if (not (spot in bedge)) and (not (spot in ledge)) and (chars[spot + ((wh // 10) - 1)].living):
119 109
 			neighbours += 1
120 110
 		i.neighbours = neighbours
121 111
 
... ...
@@ -132,8 +122,6 @@ def evolve():
132 122
 				i.living = True
133 123
 
134 124
 def mainloop():
135
-	gens = 0
136
-
137 125
 	while True:
138 126
 		'''
139 127
 		The main loop
... ...
@@ -146,11 +134,9 @@ def mainloop():
146 134
 		checkneighbours()
147 135
 		evolve()
148 136
 
149
-		pygame.time.delay(500) # Time between generations
150
-		gens += 1
151
-		print(gens)
137
+		pygame.time.delay(100) # Time between generations
152 138
 
153
-wh = 600 # Window width and height
139
+wh = 500 # Window width and height
154 140
 startwin() # Initiate the window
155 141
 genchars() # Generate the initial characters
156 142
 mainloop() # Start the game loop