Hello all, Im trying to learn python and programming in my free time, and I'm trying to do a little personal project to trying and gain some skills. Im trying to do version of John conways game of life. I have a working version of the game. Written for 3.2.2 on a mac to be accessed through terminal. I'm trying to give it a number of options. it dimensions, the max number of turns, initial set up, and boundary conditions. The dimensions and turns were pretty easy to include. The boundary conditions more difficult, and now I'm getting stuck on the initial set up options. I can set it up randomly but Im having problems implementing a checker board pattern.
'''displays: the text of the game of life for a set number of X x Y for a set of R turns. [-][-][-][-][-] [-][-][-][-][-] [-][-][-][-][-] [-][-][-][-][-] [-][-][-][-][-] Get X,Y,T, Initial value Create a data space X x Y Assign initial value print initial value and the text' initial value' do while turns<T: check data space create new data space according to rules and old data space. replace dataspace print data space. print end. ''' import random X,Y,T=0,0,0 while not 4<X<102: X=int(input('How many rows? enter a integer between 5 and 101: ')) while not 4<Y<102: Y=int(input('How many columns? enter a integer between 5 and 101: ')) while not 4<T<102: T=int(input('How many turns? enter a integer between 5 and 101: ')) entry=0 while not (entry=='b' or entry=='l' or entry=='d'): entry=input('Press "b" for bound dimensions, press "l" for live boundry, or press "d" for dead boundry: ') #while not(initial=='r' or initial=='c' or initial=='g' or initial=='e'): # initial=input(' SPACE=[] for i in range(X): SPACE.append([]) for j in range(Y): SPACE[i].append([0]) print(SPACE) #initial set up-random, checker board, glider, eternal. initial=0 while not(initial =='r' or initial =='c' or initial=='g' or initial=='e'): initial=input('Chose inital setup: press "r" for random,"c" for checker, "g" for glider,"e"=eternal') if initial=='c': idex=0 for i in range(X): jdex=0 for j in range(Y): if (idex+jdex)%2==0: SPACE[idex][jdex]=[0,] jdex+=1 else: SPACE[idex][jdex]=[1,] jdex+=1 idex+=1 else: #initial='r' for i in SPACE: for j in i: j[0]=random.randint(0,1) print('initial set up') def printset(SPACE): for i in SPACE: print(i) printset(SPACE) turn=0 while turn<T: #CREATNEWXxY NEW=[] for i in range(int(X)): NEW.append([]) for j in range(int(Y)): NEW[i].append([0]) idex=0 for i in SPACE: jdex=0 for j in i: #Set surronding if entry=='d': if idex==0: if jdex==0: surronding=SPACE[idex+1][jdex][0]+SPACE[idex+1][jdex+1][0]+SPACE[idex][jdex+1][0] elif 0<jdex<Y-1: surronding=SPACE[idex+1][jdex][0]+SPACE[idex+1][jdex+1][0]+SPACE[idex][jdex+1][0]+SPACE[idex+1][jdex-1][0]+SPACE[idex][jdex-1][0] else: surronding=SPACE[idex][jdex-1][0]+SPACE[idex+1][jdex][0]+SPACE[idex+1][jdex-1][0] elif 0<idex<X-1: if jdex==0: surronding=SPACE[idex+1][jdex][0]+SPACE[idex+1][jdex+1][0]+SPACE[idex][jdex+1][0]+SPACE[idex-1][jdex][0]+SPACE[idex-1][jdex+1][0] elif 0<jdex<Y-1: surronding=SPACE[idex+1][jdex][0]+SPACE[idex+1][jdex+1][0]+SPACE[idex][jdex+1][0]+SPACE[idex-1][jdex][0]+SPACE[idex-1][jdex+1][0]+SPACE[idex-1][jdex-1][0]+SPACE[idex][jdex-1][0]+SPACE[idex+1][jdex-1][0] else: surronding=SPACE[idex+1][jdex][0]+SPACE[idex-1][jdex][0]++SPACE[idex-1][jdex-1][0]+SPACE[idex][jdex-1][0]+SPACE[idex+1][jdex-1][0] else: if jdex==0: surronding=SPACE[idex-1][jdex][0]+SPACE[idex-1][jdex+1][0]+SPACE[idex][jdex+1][0] elif 0<jdex<Y-1: surronding=SPACE[idex][jdex+1][0]+SPACE[idex-1][jdex][0]+SPACE[idex-1][jdex+1][0]+SPACE[idex-1][jdex-1][0]+SPACE[idex][jdex-1][0] else: surronding=SPACE[idex][jdex+1][0]+SPACE[idex-1][jdex][0]+SPACE[idex-1][jdex+1][0] elif entry=='l': if idex==0: if jdex==0: surronding=SPACE[idex+1][jdex][0]+SPACE[idex+1][jdex+1][0]+SPACE[idex][jdex+1][0]+5 elif 0<jdex<Y-1: surronding=SPACE[idex+1][jdex][0]+SPACE[idex+1][jdex+1][0]+SPACE[idex][jdex+1][0]+SPACE[idex+1][jdex-1][0]+SPACE[idex][jdex-1][0]+3 else: surronding=SPACE[idex][jdex-1][0]+SPACE[idex+1][jdex][0]+SPACE[idex+1][jdex-1][0]+5 elif 0<idex<X-1: if jdex==0: surronding=SPACE[idex+1][jdex][0]+SPACE[idex+1][jdex+1][0]+SPACE[idex][jdex+1][0]+SPACE[idex-1][jdex][0]+SPACE[idex-1][jdex+1][0]+3 elif 0<jdex<Y-1: surronding=SPACE[idex+1][jdex][0]+SPACE[idex+1][jdex+1][0]+SPACE[idex][jdex+1][0]+SPACE[idex-1][jdex][0]+SPACE[idex-1][jdex+1][0]+SPACE[idex-1][jdex-1][0]+SPACE[idex][jdex-1][0]+SPACE[idex+1][jdex-1][0] else: surronding=SPACE[idex+1][jdex][0]+SPACE[idex-1][jdex][0]++SPACE[idex-1][jdex-1][0]+SPACE[idex][jdex-1][0]+SPACE[idex+1][jdex-1][0]+3 else: if jdex==0: surronding=SPACE[idex-1][jdex][0]+SPACE[idex-1][jdex+1][0]+SPACE[idex][jdex+1][0]+5 elif 0<jdex<Y-1: surronding=SPACE[idex][jdex+1][0]+SPACE[idex-1][jdex][0]+SPACE[idex-1][jdex+1][0]+SPACE[idex-1][jdex-1][0]+SPACE[idex][jdex-1][0]+3 else: surronding=SPACE[idex][jdex+1][0]+SPACE[idex-1][jdex][0]+SPACE[idex-1][jdex+1][0]+5 else: if idex==0: if jdex==0: surronding=SPACE[idex+1][jdex][0]+SPACE[idex+1][jdex+1][0]+SPACE[idex][jdex+1][0]+SPACE[idex-1][jdex][0]+SPACE[idex-1][jdex+1][0]+SPACE[idex-1][jdex-1][0]+SPACE[idex][jdex-1][0]+SPACE[idex+1][jdex-1][0] elif 0<jdex<Y-1: surronding=SPACE[idex+1][jdex][0]+SPACE[idex+1][jdex+1][0]+SPACE[idex][jdex+1][0]+SPACE[idex-1][jdex][0]+SPACE[idex-1][jdex+1][0]+SPACE[idex-1][jdex-1][0]+SPACE[idex][jdex-1][0]+SPACE[idex+1][jdex-1][0] else: surronding=SPACE[idex+1][jdex][0]+SPACE[idex+1][0][0]+SPACE[idex][0][0]+SPACE[idex-1][jdex][0]+SPACE[idex-1][0][0]+SPACE[idex-1][jdex-1][0]+SPACE[idex][jdex-1][0]+SPACE[idex+1][jdex-1][0] elif 0<idex<X-1: if jdex==0: surronding=SPACE[idex+1][jdex][0]+SPACE[idex+1][jdex+1][0]+SPACE[idex][jdex+1][0]+SPACE[idex-1][jdex][0]+SPACE[idex-1][jdex+1][0]+SPACE[idex-1][jdex-1][0]+SPACE[idex][jdex-1][0]+SPACE[idex+1][jdex-1][0] elif 0<jdex<Y-1: surronding=SPACE[idex+1][jdex][0]+SPACE[idex+1][jdex+1][0]+SPACE[idex][jdex+1][0]+SPACE[idex-1][jdex][0]+SPACE[idex-1][jdex+1][0]+SPACE[idex-1][jdex-1][0]+SPACE[idex][jdex-1][0]+SPACE[idex+1][jdex-1][0] else: surronding=SPACE[idex+1][jdex][0]+SPACE[idex+1][0][0]+SPACE[idex][0][0]+SPACE[idex-1][jdex][0]+SPACE[idex-1][0][0]+SPACE[idex-1][jdex-1][0]+SPACE[idex][jdex-1][0]+SPACE[idex+1][jdex-1][0] else: if jdex==0: surronding=SPACE[0][jdex][0]+SPACE[0][jdex+1][0]+SPACE[idex][jdex+1][0]+SPACE[idex-1][jdex][0]+SPACE[idex-1][jdex+1][0]+SPACE[idex-1][jdex-1][0]+SPACE[idex][jdex-1][0]+SPACE[0][jdex-1][0] elif 0<jdex<Y-1: surronding=SPACE[0][jdex][0]+SPACE[0][jdex+1][0]+SPACE[idex][jdex+1][0]+SPACE[idex-1][jdex][0]+SPACE[idex-1][jdex+1][0]+SPACE[idex-1][jdex-1][0]+SPACE[idex][jdex-1][0]+SPACE[0][jdex-1][0] else: surronding=SPACE[0][jdex][0]+SPACE[0][0][0]+SPACE[idex][0][0]+SPACE[idex-1][jdex][0]+SPACE[idex-1][0][0]+SPACE[idex-1][jdex-1][0]+SPACE[idex][jdex-1][0]+SPACE[0][jdex-1][0] if j==[0]: if surronding==3: NEW[idex][jdex][0]=1 jdex+=1 else: NEW[idex][jdex][0]=0 jdex+=1 else: if surronding==2 or surronding==3: NEW[idex][jdex][0]=1 jdex+=1 else: NEW[idex][jdex][0]=0 jdex+=1 idex+=1 print(surronding) SPACE=NEW[:] printset(SPACE) turn+=1 #input("Press any key to continue.") print('------The End-------')
iam.py
Description: Binary data
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor