Could someone help me write code for the game of life in python 2.6. I am a beginner to programming, and I know how to use lists and have functions from a function library that include: setupgame()- which creates a grid,state=isAlive(cell),
num=countNeighboursAlive(cell)in the neighbourhood, newState=decideState(state,num) stating whether the cell should be alive or dead, and setState(cell,state)- allowing the cell to change to a new state and displayBoard()- to display the grid. Thanks.
James0l9l
0
Light Poster
Recommended Answers
Jump to PostLooks like you have the game ready, only write the main loop. Do not be afraid to experiment.
You can also see
http://www.daniweb.com/code/snippet217028.html
Jump to PostI mean the part after if __name__.... part in this program:
def plus(a,b): return a+b def minus(a,b): return a-b def getint(prompt): try: a = raw_input(prompt) if a: return int(a) except ValueError: print "Incorrect input, give again!" return getint(prompt) else: return a if __name__=='__main__': a = b = …
Jump to PostI gave example of main program processing two integers like when inputting the dimensions of grid in game of life. To show main program in lines 21-34 and exception hanling for wrong input (you would only accept dimension inside some lower and upper bound, not all integers, so you would …
Jump to PostThis makes number grid 0..49 50 times:
board = [] for x in range (50): board.append(range(50)) print board
Jump to Postimport random lifechance = .1 ## 10 % chance for life in square board = [] for x in range (50): # '*' == life, '' == dead board.append(['*' if random.random()<lifechance else '' for notcare in range(50)]) # make strings for lines replacing '' values (which are …
All 17 Replies
TrustyTony
888
pyMod
Team Colleague
Featured Poster
James0l9l
0
Light Poster
TrustyTony
888
pyMod
Team Colleague
Featured Poster
James0l9l
0
Light Poster
James0l9l
0
Light Poster
TrustyTony
888
pyMod
Team Colleague
Featured Poster
James0l9l
0
Light Poster
TrustyTony
888
pyMod
Team Colleague
Featured Poster
TrustyTony
888
pyMod
Team Colleague
Featured Poster
James0l9l
0
Light Poster
James0l9l
0
Light Poster
James0l9l
0
Light Poster
TrustyTony
888
pyMod
Team Colleague
Featured Poster
James0l9l
0
Light Poster
TrustyTony
888
pyMod
Team Colleague
Featured Poster
James0l9l
0
Light Poster
TrustyTony
888
pyMod
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.