Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """Creating the game of life"""
- #generating matrix and coordinates
- cordinates = [(x,y) for x in range(0,11) for y in range (0,11)]
- matrix={x:0 for x in cordinates}
- directions = [(a,b) for a in range(-1,2) for b in range(-1,2) if (a,b)!=(0,0)]
- alive = 1
- dead = 0
- #checking up the count for neighbour alive and dead cells for each positon
- def check_count(design,x,y):
- count_alive = 0
- for m,n in directions: #going in all directions and checking for live and dead cells
- if design.get[(x+m,y+n),2] == 1:
- count_alive +=1
- elif design.get[(x+m,y+n),2] == 0:
- count_dead +=1
- return design[(x,y)],count_alive # returning the state of that cell,number of live and dead cells around it
- def change(design):
- for x,y in design:
- values = check_count(design,x,y) #going to each position and preparing for next generation
- if values[0]==1:
- if values[1] < 2 :
- design[(x,y)] = 0
- elif values[1] == 2 or 3:
- design[(x,y)] = 1
- elif values[1] > 3 :
- design[(x,y)] = 0
- elif values[0] == 0 :
- if value[1] ==3:
- design[(x,y)] = 1
- return design
- #Getting over with formalities
- print "Welcome to the Game of life (shitty version)"
- print "It's a universe based on 10*10 2 dimension matrix ..!"
- print "There are four rules to decide the fittest ..!"
- print "A inital pattern has been set ..! "
- print "Enjoy ..!"
- #creating design
- matrix[(2,4)] =1
- matrix[(3,2)]=1
- matrix[(4,4)]=1
- matrix[(2,2)]=1
- matrix[(4,3)]=1
- matrix[(3,3)] = 1
- for keys in matrix:
- print matrix[keys],
- def main():
- count = 0
- generation = True
- while generation == True :
- shape = change(matrix)
- for keys in shape:
- print shape[keys],
- count +=1
- print "Generation " +repr(count) + " complete"
- matrix = shape
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement