On 4/17/2012 2:23 PM, leo degon wrote:
> Ok so I've done a bit of work on the program and rewrote it. I tried
to take everyones advice. I've used more functions,
> I've made it so that it is a list of lists each containing an integer
instead of another list with a single entry.
I'm glad to see you using some of my ideas!
> Im am having problems thinking of how to simply and elegantly
calculate the surrounding cells.
> I could brute force it as i did originally, but I'd like some
pointers of how to avoid that.
> As of now, the script is finished for that 'small' detail. I have it
so that instead of actually calculating the surrounding cells,
> that functions says that all the cells on the board are surrounding
by three cells.
> Therefore setting the entire board alive after the turn zero. I am
still trying to include three different versions of the bounadry conditions.
>Boundary conditions, what happens when a cell on the edge of the board
tries to calculate the number of surrounding live cells.
> Dead- Those nonexistent cells add nothing.
> Live-Those nonexistent cells add one per cell. So add 5 to the
corners, and one to edges.
> Bound- The dimensions are bound. So you get to the end and loop around.
[snip]
I again recommend you add extra rows and columns around the space so you
always use one formula for surround.
For dead initialize the extra cells to 0
For live initialize the extra cells to 1
For bound - every time you change a boundary cell make the same change
to the corresponding extra cell.
I hope that makes sense. Does it?
Also recall my condensed way of summing surrounding cells. I realize I
made a mistake in my original proposal - in that it counted the cell
itself as well as the neighbors. Easy to fix.
Originally I suggested:
for r in range(1,x+1):
for c in range1,(y+1):
surrounding = sum([sum(space[r+z][c-1:c+2]) for z in(-1,0,1)])
New suggestion:
def determinelife(surronding,space,i,j):
return sum(space[i-1][j-1:j+2]) + sum(space[i][j-1:j+2:2]) +
sum(space[i+1][j-1:j+2])
HTH
--
Bob Gailer
919-636-4239
Chapel Hill NC
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor