You are not logged in.
I was unable to find a simple, fast Life implementation, so I wrote my own. Please tell me what you think.
You absolutely must read the README file in the source tree.
AUR package: http://aur.archlinux.org/packages.php?ID=34640
git view: http://peasantoid.org/git/peagol
git clone: git://peasantoid.org/peagol
(And yes, I do name all my projects after myself.)
Last edited by Peasantoid (2010-02-15 02:21:38)
Offline
Very nice!
I guess you really do need to read the README
Here's one I made some time ago because I wanted one in a terminal.
#!/usr/bin/python
import copy
import random
import time
random.seed()
class gameoflife:
def __init__(self, width, height):
self.board = []
for i in range(width):
col = []
for j in range(height):
col.append(random.randint(0, 1))
self.board.append(col)
self.width = width
self.height = height
self.futureboard = copy.deepcopy(self.board)
def checkpoint(self, x, y):
if x < 0 or x >= self.width or y < 0 or y >= self.height:
return 0
return self.board[x][y]
# returns the amount of neighbors that are checked given a point
def neighbors(self, x, y):
xlist = [x - 1, x, x + 1]
ylist = [y - 1, y, y + 1]
total = 0
for i in range(len(xlist)):
for j in range(len(ylist)):
if xlist[i] != x or ylist[j] != y:
total += self.checkpoint(xlist[i], ylist[j])
return total
def run(self):
for i in range(self.height):
for j in range(self.width):
numNeighbors = self.neighbors(j, i)
self.futureboard[j][i] = 0
if numNeighbors == 3:
self.futureboard[j][i] = 1
if numNeighbors == 2 and self.board[j][i] == 1:
self.futureboard[j][i] = 1
# print board
for i in range(self.height):
for j in range(self.width):
#print self.board[j][i],
if self.board[j][i] == 0:
print 0,
else:
print ' ',
print
self.board = copy.deepcopy(self.futureboard)
test = gameoflife(90, 60)
while 1 == 1:
test.run()
print
#time.sleep(0.2)
Offline
Very nice!
I guess you really do need to read the README
Yep. I wanted to make the interface as simple as possible. Would've written the thing in Python, but it ate all my CPU time so I had to switch to something faster.
// Nice script. Not nearly as friendly, though.
Last edited by Peasantoid (2010-02-15 06:45:29)
Offline