Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarío Clavijo <daedalus2027@gmail.com>2011-01-07 01:35:13 (GMT)
committer Darío Clavijo <daedalus2027@gmail.com>2011-01-07 01:35:13 (GMT)
commit609daa11a8b707e983cac2234014ab359985fca0 (patch)
tree38dc1df7d08ccc0c6bcb676984599961c2dcbd0d
parenta4e8e9dc14da89f202faee0235c5633104be83cd (diff)
four space tab missed and some corrections
-rw-r--r--data/misc/lifegame118
1 files changed, 59 insertions, 59 deletions
diff --git a/data/misc/lifegame b/data/misc/lifegame
index 706651a..9f3062d 100644
--- a/data/misc/lifegame
+++ b/data/misc/lifegame
@@ -4,18 +4,18 @@
import os, time, random
#
-# we need a funcion to load
+# we need a funcion to load cells in the neighborhood
#
def LoadCells(rows,cols):
- grid=[]
+ grid = []
col = [0]*cols
- cells=0
-#first we load an empty grid
+ cells = 0
+ #first we load an empty grid
for i in range(rows):
- col = [0]* cols
- grid.append(col)
-#then we load some cells
+ col = [0]* cols
+ grid.append(col)
+ #then we load some cells
for x in range(rows):
for y in range(cols):
cell = random.randint(0,random.randint(0,1))
@@ -31,10 +31,10 @@ def DrawGrid(grid):
cols=len(grid[1])
for x in range(rows):
for y in range(cols):
- if grid[x][y]==0:
- print ".",
- else:
- print "o",
+ if grid[x][y] == 0:
+ print ".",
+ else:
+ print "o",
print "\n",
#
@@ -42,70 +42,70 @@ def DrawGrid(grid):
#
def CountNeighbors(grid,x,y):
- neighbors=0
- rows=len(grid)
- cols=len(grid[1])
+ neighbors = 0
+ rows = len(grid)
+ cols = len(grid[1])
- if x < rows-1 and grid[x+1][y]==1:
- neighbors = neighbors + 1
- if x > 0 and grid[x-1][y]==1:
- neighbors = neighbors + 1
- if y < cols-1 and grid[x][y+1]==1:
- neighbors = neighbors + 1
- if y > 0 and grid[x][y-1]==1:
- neighbors = neighbors + 1
- if x < rows-1 and y < cols-1 and grid[x+1][y+1]==1:
- neighbors = neighbors + 1
- if x > 0 and y > 0 and grid[x-1][y-1]==1:
- neighbors = neighbors + 1
- if x > 0 and y < cols-1 and grid[x-1][y+1]==1:
- neighbors = neighbors + 1
- if x < rows-1 and y > 0 and grid[x+1][y-1]==1:
- neighbors = neighbors + 1
-
- return neighbors
+ if x < rows-1 and grid[x+1][y] == 1:
+ neighbors = neighbors + 1
+ if x > 0 and grid[x-1][y] == 1:
+ neighbors = neighbors + 1
+ if y < cols-1 and grid[x][y+1] == 1:
+ neighbors = neighbors + 1
+ if y > 0 and grid[x][y-1] == 1:
+ neighbors = neighbors + 1
+ if x < rows-1 and y < cols-1 and grid[x+1][y+1] == 1:
+ neighbors = neighbors + 1
+ if x > 0 and y > 0 and grid[x-1][y-1] == 1:
+ neighbors = neighbors + 1
+ if x > 0 and y < cols-1 and grid[x-1][y+1] == 1:
+ neighbors = neighbors + 1
+ if x < rows-1 and y > 0 and grid[x+1][y-1] == 1:
+ neighbors = neighbors + 1
+
+ return neighbors
# here we define a single iteration
# if we have between 3 and 6 neighbors the single cell live
# in other case the cell die
def Iteration(grid):
- rows=len(grid)
- cols=len(grid[1])
- neighbors=0
+ rows = len(grid)
+ cols = len(grid[1])
+ neighbors = 0
for x in range(rows):
- for y in range(cols):
- if grid[x][y] == 1:
- neighbors = CountNeighbors(grid,x,y)
- if neighbors >= 3 and neighbors <= 6:
- xpos = x + random.randint(-1,1)
- if xpos <= 0:
- xpos = 1
- if xpos >= rows:
- xpos = rows-1
- ypos = y + random.randint(-1,1)
- if ypos <= 0:
- ypos = 1
- if ypos >= cols:
- ypos = cols-1
- grid[xpos][ypos]=1
- else:
- grid[x][y]=0
+ for y in range(cols):
+ if grid[x][y] == 1:
+ neighbors = CountNeighbors(grid,x,y)
+ if neighbors >= 3 and neighbors <= 6:
+ xpos = x + random.randint(-1,1)
+ if xpos <= 0:
+ xpos = 1
+ if xpos >= rows:
+ xpos = rows-1
+ ypos = y + random.randint(-1,1)
+ if ypos <= 0:
+ ypos = 1
+ if ypos >= cols:
+ ypos = cols-1
+ grid[xpos][ypos] = 1
+ else:
+ grid[x][y] = 0
#
# this funcion iterate n pulses and draws the result of earch one
#
def Iterator(rows,cols,pulsos):
- pulse=1
+ pulse = 1
grid = LoadCells(rows,cols)
while pulse <= pulses:
- os.system('clear')
- print "Pulse: ",pulse
- Iteration(grid)
- DrawGrid(grid)
- pulse = pulse + 1
- time.sleep(0.2)
+ os.system('clear')
+ print "Pulse: ",pulse
+ Iteration(grid)
+ DrawGrid(grid)
+ pulse = pulse + 1
+ time.sleep(0.2)
number = input("Please imput the number of rows and cols (unique number):")
pulses = input("Please imput the number of pulses:")