Advertisement
galactus03

Untitled

Mar 1st, 2015
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. """Creating the game of life"""
  2.  
  3. #generating matrix and coordinates
  4. cordinates = [(x,y) for x in range(0,11) for y in range (0,11)]
  5. matrix={x:0 for x in cordinates}
  6. directions = [(a,b) for a in range(-1,2) for b in range(-1,2) if (a,b)!=(0,0)]
  7. alive = 1
  8. dead = 0
  9. #checking up the count for neighbour alive and dead cells for each positon
  10. def check_count(design,x,y):
  11. count_alive = 0
  12. for m,n in directions: #going in all directions and checking for live and dead cells
  13. if design.get[(x+m,y+n),2] == 1:
  14. count_alive +=1
  15. elif design.get[(x+m,y+n),2] == 0:
  16. count_dead +=1
  17. return design[(x,y)],count_alive # returning the state of that cell,number of live and dead cells around it
  18.  
  19. def change(design):
  20. for x,y in design:
  21. values = check_count(design,x,y) #going to each position and preparing for next generation
  22. if values[0]==1:
  23. if values[1] < 2 :
  24. design[(x,y)] = 0
  25. elif values[1] == 2 or 3:
  26. design[(x,y)] = 1
  27. elif values[1] > 3 :
  28. design[(x,y)] = 0
  29. elif values[0] == 0 :
  30. if value[1] ==3:
  31. design[(x,y)] = 1
  32. return design
  33.  
  34. #Getting over with formalities
  35. print "Welcome to the Game of life (shitty version)"
  36. print "It's a universe based on 10*10 2 dimension matrix ..!"
  37. print "There are four rules to decide the fittest ..!"
  38. print "A inital pattern has been set ..! "
  39. print "Enjoy ..!"
  40.  
  41. #creating design
  42. matrix[(2,4)] =1
  43. matrix[(3,2)]=1
  44. matrix[(4,4)]=1
  45. matrix[(2,2)]=1
  46. matrix[(4,3)]=1
  47. matrix[(3,3)] = 1
  48. for keys in matrix:
  49. print matrix[keys],
  50. def main():
  51. count = 0
  52. generation = True
  53. while generation == True :
  54. shape = change(matrix)
  55. for keys in shape:
  56. print shape[keys],
  57. count +=1
  58. print "Generation " +repr(count) + " complete"
  59. matrix = shape
  60.  
  61. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement