2D Array and Matrix Application: Game of Life

Slides:



Advertisements
Similar presentations
Number puzzles in the paper Did you know there’s a whole range of number puzzles you can try in most newspapers? Click on the puzzles below to complete.
Advertisements

CS 5 Today HW 9 (lab + 2 probs) due Sunday, 11/8 at midnight Dizzying arrays of possibilities… John Conway Carl Gauss This week’s credits: Exam 2 on Mon.,Tue.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
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.
Activity 2-1: The Game of Life
EECS 110: Lec 12: Mutable Data Aleksandar Kuzmanovic Northwestern University
Model Iteration Iteration means to repeat a process and is sometimes referred to as looping. In ModelBuilder, you can use iteration to cause the entire.
Lecture Set 9 Arrays, Collections and Repetition Part C - Random Numbers Rectangular and Jagged arrays.
Homework 9 Due ( M & T sections ) ( W & Th sections ) at midnight Sun., 11/3 Mon., 11/4 Problems
Computing Science 1P Large Group Tutorial 20 Simon Gay Department of Computing Science University of Glasgow 2006/07.
A Variation on Conway’s Game of Life Winston Lee EPS 109.
1 Arrays of Arrays An array can represent a collection of any type of object - including other arrays! The world is filled with examples Monthly magazine:
Ionut Trestian Northwestern University
EECS 110: Lec 12: Mutable Data Aleksandar Kuzmanovic Northwestern University
MULTIPLICATION 5 Multiplicand X 3 Multiplier 15 Product LET’S LEARN
By Melissa Dalis Professor Susan Rodger Duke University June 2011
Thinking about programming
Pixels, Colors and Shapes
EECS 110: Lec 12: Mutable Data
Chaotic Behavior - Cellular automata
Graphs Chapter 15 introduces graphs which are probably the most general and commonly-used data structure. This lecture introduces heaps, which are used.
Introduction Abstract
Matrices Rules & Operations.
Computational Models.
Introduction to Computers
Radioactive Decay Radioactive elements are unstable. They decay, change, into different elements over time. Here are some facts to remember: The half-life.
EGR 115 Introduction to Computing for Engineers
– Officiating Management Software
Illustrations of Simple Cellular Automata
Week 15 – Monday CS221.
Computational methods in physics
Week 9 - Monday CS 121.
Cellular Automata + Reaction-Diffusion Systems
More Recursion.
Chapter I Introduction to MS PowerPoint Program
Using cartoons to draw similar figures
Analysis and design of algorithm
CMSC 341 Lecture 10 B-Trees Based on slides from Dr. Katherine Gibson.
M4.A.3 Compute accurately and fluently and make reasonable estimates.
עקרנות תכנות מונחה עצמים
Radioactive Decay Radioactive elements are unstable. They decay, change, into different elements over time. Here are some facts to remember: The half-life.
HMC’s Galileo Auditorium Some of Cope’s generated MP3s:
Topic 26 Two Dimensional Arrays
Cellular Automata.
Spatio-temporal information in society: cellular automata
Ionut Trestian Northwestern University
More 2 D Array.
Multiway Trees Searching and B-Trees Advanced Tree Structures
Using cartoons to draw similar figures
2D Array and Matrix.
Dictionaries 1/17/2019 7:55 AM Hash Tables   4
Multidimensional Arrays
Conway’s Game in matlab
Northwestern University
Part 1. Preparing for the exercises
ECE 352 Digital System Fundamentals
Modeling Pattern Formation in Skin Diseases by a Cellular Automaton
Data Structures & Algorithms
L6.1.1 Living, Nonliving, or Dead
Cartoon Similarity Using cartoons to draw similar figures
Introduction to Computer Science
EET 2259 Unit 9 Arrays Read Bishop, Sections 6.1 to 6.3.
Chapter 1 Introducing Small Basic
Absolute Value Equations
Radioactive Decay Radioactive elements are unstable. They decay, change, into different elements over time. Here are some facts to remember: The half-life.
AP Java Learning Objectives
EECS 110: Lec 12: Mutable Data
Activity 2-1: The Game of Life
Add some WordArt to your cover slide
10x + y What do you notice? x = 2 and y = 1? x = 4 and y = 5?
Presentation transcript:

2D Array and Matrix Application: Game of Life

Conway’s Game of Life Resources A short video on Game of Life https://www.youtube.com/watch?v=CgOcEZinQ2I Other applications of the Game Two plain text versions from conwaylife.com: http://www.conwaylife.com/wiki/Plaintext Game of Life Clock: https://www.youtube.com/watch?v=3NDAZ5g4EuU The original challenge: https://codegolf.stackexchange.com/questions/88783/build-a-digital-clock-in-conways-game-of-life

HW 8, Lab -- “Life” Grid World red cells are alive Evolutionary rules John Conway Grid World red cells are alive Evolutionary rules Everything depends on a cell’s eight neighbors 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) white cells are empty

Problem 1 -- Life Grid World red cells are alive Evolutionary rules Everything depends on a cell’s eight neighbors Exactly 3 neighbors give birth to a new, live cell! The next several slides simulate the game. Assume this is a starting state Which cells will give birth to a new cell?" IN row,col form: 2,2 and 3,4 Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead) white cells are empty

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

Problem 1 -- Life Grid World red cells are alive Evolutionary rules Everything depends on a cell’s eight neighbors 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) Keep going! white cells are empty life out there...

Problem 1 -- Creating Life next_life_generation( A ) returns new generation or "array" old generation or "array" 1 2 3 4 5 1 2 3 4 5 1 1 2 2 Adds (1,1), (2,3), and (3,1) Deletes (4,4) Answer next slide 3 3 4 4 5 5

Problem 1 -- Creating Life next_life_generation( A ) returns new generation or "array" old generation or "array" 1 2 3 4 5 1 2 3 4 5 1 1 2 2 3 3 4 4 5 5

Problem 1 -- Details For each generation… ? 0 represents an empty cell next_life_generation( A ) returns new generation or "array" old generation or "array" 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 before updating any of them ? http://www.math.com/students/wonders/life/life.html life out there...

Problem 1 – to ∞ and beyond! "rocks" Are there stable life configurations? "plants" Are there oscillating life configurations? period 3 period 2 "animals" Are there self-propagating life configurations?

Let us work out a couple of problems together. 1. Find the neighbors for some special cells in Conway’s Game of Life, return them as a list a) Upper left corner: The cell index is [0][0]. It doesn’t have any upper or left neighbors, only the ones on right or below. 0,0 0,1 1,0 1,1 Python code: neighbors = [m[1][0]] + [m[0][1]] + [m[1][1]] b) Your work: Finding neighbors for upper right corner, lower left corner, and lower right corner

2. Place integers 1..9 in a 3x3 matrix, no repetition is allowed, similar to Sudoku. Some cells may have been initially filled correctly. The unfilled cells are marked by -1. [[1, -1, -1], [-1, -1, 4], [5, 6, -1]] [[1, 2, 3], [7, 8, 4], [5, 6, 9]] results in [[-1, -1, -1], [-1, -1, -1], [-1, -1, -1]] [[1, 2, 3], [4, 5, 6], [7, 8, 9]] results in

Python list tools needed remove() and pop(): n = [i for i in range(1, 10)] for k in range(len(n)): v = randint(1,10) if v in n: n.remove(v) m = [] m = m + [n.pop()] # m = m + [n.pop(0)] Try list_remove_pop.py