Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Game of Life A simulation of "life". From simple rules, complex behavior arises Rules –A cell that is alive and has fewer than two live neighbors dies.

Similar presentations


Presentation on theme: "The Game of Life A simulation of "life". From simple rules, complex behavior arises Rules –A cell that is alive and has fewer than two live neighbors dies."— Presentation transcript:

1 The Game of Life A simulation of "life". From simple rules, complex behavior arises Rules –A cell that is alive and has fewer than two live neighbors dies (because of loneliness) –A cell that is alive and has more than 3 live neighbors dies (because of over-crowding) –A cell that is dead and has exactly 3 live neighbors comes to life –All other cells maintain their state

2 The Game of Life: History Created by John Horton Conway, a British Mathematician Inspired by a problem presented by John Von Neumann: –Build a hypothetical machine that can build copies of itself First presented in 1970, Scientific American

3 “Life” Evolutionary rules Grid World Everything depends on a cell’s eight neighbors red cells are alive white cells are empty Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead) John Conway

4 Life Evolutionary rules Grid World Everything depends on a cell’s eight neighbors red cells are alive white cells are empty Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead)

5 Life Evolutionary rules Grid World Everything depends on a cell’s eight neighbors red cells are alive white cells are empty Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead)

6 Life Evolutionary rules Grid World Everything depends on a cell’s eight neighbors red cells are alive white cells are empty Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead) life out there... Keep going!

7 Creating Life 0123450 12345 0 1 2 3 4 5 0 1 2 3 4 5 updateNextLife(oldB, newB) old generation or "board" new generation or "board"

8 Creating Life 0123450 12345 0 1 2 3 4 5 0 1 2 3 4 5 old generation or "board" new generation or "board" updateNextLife(oldB, newB)

9 Details For each generation… 0 represents an empty cell 1 represents a living cell outermost edge should always be left empty (even if there are 3 neighbors) compute all cells based on their previous neighbors http://www.math.com/students/wonders/life/life.html old generation or "board" new generation or "board" life out there... updateNextLife(oldB, newB)

10 Main Loop def life( width, height ): """ will become John Conway's Game of Life... """ B = createBoard(width, height) csplot.showAndClickInIdle(B) while True: # run forever csplot.show(B) # show current B time.sleep(0.25) # pause a bit oldB = B B = createBoard( width, height ) updateNextLife( oldB, B ) # gets a new board

11 Main Loop def life( width, height ): """ will become John Conway's Game of Life... """ B = createBoard(width, height) csplot.showAndClickInIdle(B) while True: # run forever csplot.show(B) # show current B time.sleep(0.25) # pause a bit oldB = B B = createBoard( width, height ) updateNextLife( oldB, B ) # gets a new board Why not just have update RETURN a new list? (i.e., why bother with mutation at all?) Update MUTATES the list B

12 to  and beyond! Are there stable life configurations? Are there oscillating life configurations? Are there self-propagating life configurations? "rocks" "plants" "animals" period 3 period 2

13 to  and beyond! Are there life configurations that expand forever? What is the largest amount of the life universe that can be filled with cells? How sophisticated can the structures in the life universe be? http://www.ibiblio.org/lifepatterns/ Are all feasible configurations reachable?

14 Gaussian Elimination 2p + 3n + -1q = -8.00 -3p + -1n + 2q = 42.00 1p + -9n + 4q = 56.00 Goal: Find p,n,q Carl Gauss is so money!

15 Gaussian Elimination 2p + 3n + -1q = -8.00 -3p + -1n + 2q = 42.00 1p + -9n + 4q = 56.00 Goal: get 1s along the diagonal get 0s elsewhere on the left Find p,n,q 1p + 0n + 0q = 1.00 0p + 1n + 0q = 5.00 0p + 0n + 1q = 25.00

16 Gaussian Elimination 2p + 3n + -1q = -8.00 -3p + -1n + 2q = 42.00 1p + -9n + 4q = 56.00 Goal: get 1s along the diagonal get 0s elsewhere on the left Find p,n,q 1p + 0n + 0q = 1.00 0p + 1n + 0q = 5.00 0p + 0n + 1q = 25.00 Just the array is necessary ! We can get rid of the variables... Using only row operations (our methods) ! where to start?

17 Solve 1.00 1.50 -0.50 -4.00 -3.00 -1.00 2.00 42.00 1.00 -9.00 4.00 56.00 multiply Row 0 by 0.5

18 Solve 1.00 1.50 -0.50 -4.00 -3.00 -1.00 2.00 42.00 1.00 -9.00 4.00 56.00 multiply Row 0 by 0.5 1.00 1.50 -0.50 -4.00 0.00 3.50 0.50 30.00 0.00 -10.50 4.50 44.00 add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2

19 Solve 1.00 1.50 -0.50 -4.00 -3.00 -1.00 2.00 42.00 1.00 -9.00 4.00 56.00 multiply Row 0 by 0.5 1.00 1.50 -0.50 -4.00 0.00 3.50 0.50 30.00 0.00 -10.50 4.50 44.00 1.00 0.00 -0.71 -16.85 0.00 1.00 0.14 30.00 0.00 0.00 6.00 150.00 multiply Row 1 by 1/3.5 add a multiple of Row 1 to Row 0 add a multiple of Row 1 to Row 2 add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2

20 Solve 1.00 1.50 -0.50 -4.00 -3.00 -1.00 2.00 42.00 1.00 -9.00 4.00 56.00 multiply Row 0 by 0.5 1.00 1.50 -0.50 -4.00 0.00 3.50 0.50 30.00 0.00 -10.50 4.50 44.00 add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2 1.00 0.00 -0.71 -16.85 0.00 1.00 0.14 30.00 0.00 0.00 6.00 150.00 1.00 0.00 0.00 1.00 0.00 1.00 0.00 5.00 0.00 0.00 1.00 25.00 same for other columns as far as possible... multiply Row 1 by 1/3.5 add a multiple of Row 1 to Row 0 add a multiple of Row 1 to Row 2

21 def add2ofRow1IntoRow2( A ): 0.00 1.00 0.00 1.00 3.00 0.50 0.50 3.00 10.00 20.00 30.00 40.00 before after A A 0.00 1.00 0.00 1.00 3.00 0.50 0.50 3.00 16.00 21.00 31.00 46.00 two of row 1 are to be added to row 2 row 0 row 1 row 2 row 0 row 1 row 2 Write a method that adds two times the values in row # 1 into the values in row # 2. Only row 2's values change. You may assume that A has at least three rows! How could you make the source and destination rows inputs to this function? How would it change the code? The values in row 1 should not change

22 def addRowSIntoRowD( rs, rd, A ): 0.00 1.00 0.00 1.00 3.00 0.50 0.50 3.00 10.00 20.00 30.00 40.00 0.00 1.00 0.00 1.00 3.00 0.50 0.50 3.00 16.00 21.00 31.00 46.00 row 0 row 1 row 2 row 0 row 1 row 2 Write a method that adds row # s into the values in row # d. s d s d

23 Using 2d arrays 2.00 3.00 -1.00 -8.00 -3.00 -1.00 2.00 42.00 1.00 -9.00 4.00 56.00 Before After 2.00 3.00 -3.00 -8.00 -3.00 -1.00 6.00 42.00 1.00 -9.00 12.00 56.00 arr A method for multiplying columns:

24 Solving ?! Gaussian Elimination 2p + 3n + -1q = -8.00 -3p + -1n + 2q = 42.00 1p + -9n + 4q = 56.00 1.00p + 1.50n + -0.50q = -4.00 -3.00p + -1.00n + 2.00q = 42.00 1.00p + -9.00n + 4.00q = 56.00 Goal: get 1s along the diagonal get 0s elsewhere on the left multiply the zeroth row (R0) by 0.5 Find p,n,q 1.00p + 1.50n + -0.50q = -4.00 0.00p + 3.50n + 0.50q = 30.00 -0.00p + -10.50n + 4.50q = 44.00 add 3 times R0 to R1 add -1 times R0 to R2

25 Solved ! 1.00p + 1.50n + -0.50q = -4.00 0.00p + 3.50n + 0.50q = 30.00 -0.00p + -10.50n + 4.50q = 44.00 multiply R1 by 1 / 3.5 1.00p + 1.50n + -0.50q = -4.00 0.00p + 1.00n + 0.14q = 8.57 -0.00p + -10.50n + 4.50q = 44.00 add -1.5 times R1 to R0 add 10.5 times R1 to R2 1.00p + 0.00n + -0.71q = -16.85 0.00p + 1.00n + 0.14q = 30.00 -0.00p + 0.00n + 6.00q = 150.00 add 3 times R0 to R1 add -1 times R0 to R2 continue... 1.00p + 0.00n + 0.00q = 1.00 0.00p + 1.00n + 0.00q = 5.00 -0.00p + 0.00n + 1.00q = 25.00 only the array is necessary !

26 Solved ! 1.00p + 1.50n + -0.50q = -4.00 0.00p + 3.50n + 0.50q = 30.00 -0.00p + -10.50n + 4.50q = 44.00 multiply R1 by 1 / 3.5 1.00p + 1.50n + -0.50q = -4.00 0.00p + 1.00n + 0.14q = 8.57 -0.00p + -10.50n + 4.50q = 44.00 add -1.5 times R1 to R0 add 10.5 times R1 to R2 1.00p + 0.00n + -0.71q = -16.85 0.00p + 1.00n + 0.14q = 30.00 -0.00p + 0.00n + 6.00q = 150.00 add 3 times R0 to R1 add -1 times R0 to R2 continue... 1.00p + 0.00n + 0.00q = 1.00 0.00p + 1.00n + 0.00q = 5.00 -0.00p + 0.00n + 1.00q = 25.00 only the array is necessary !


Download ppt "The Game of Life A simulation of "life". From simple rules, complex behavior arises Rules –A cell that is alive and has fewer than two live neighbors dies."

Similar presentations


Ads by Google