Continue with Life, Magic and Catch -up

Slides:



Advertisements
Similar presentations
Representing a Game Board In a game, we represent the action taking place using an array – In a very simple game, we use individual variables to represent.
Advertisements

1 The Game of Life Supplement 2. 2 Background The Game of Life was devised by the British mathematician John Horton Conway in More sophisticated.
Project 1 Tic Tac Toe Assigned Mon, Sep 8, 2003 Due Mon, Sep 15, 2003.
CS 100Lecture 171 CS100A Lecture 17 n Previous Lecture –Programming concepts n Two-dimensional arrays –Java Constructs n Constructors for two-dimensional.
Computer Science 1 How do you store a bunch of similar stuff?
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
Computer Science 2 Arrays of Records. First Record Program Input an unknown number of Team Names, School names, and Total scores. (While loop) –Output:
1 1 2 What is a Cellular Automaton? A one-dimensional cellular automaton (CA) consists of two things: a row of "cells" and a set of "rules". Each of.
Arrays Chapter 7.
Microsoft Excel.
Lecture 5 of Computer Science II
Introduction Abstract
Two-Dimensional Arrays
Simplifying 1 + 2a + b + 1 a + b a + b + 1 2a b + a + b
Week 9 - Monday CS 121.
Chap 7. Building Java Graphical User Interfaces
עקרנות תכנות מונחה עצמים
Review Finish program Graphics Programming
Computer Science Dynamics.
Computer Science 2 Hashing
Board: Objects, Arrays and Pedagogy
Nested Loop Review and Two-Dimensional Arrays
The Wonderful World of the Magic Square
How do you store a bunch of similar stuff?
Multiplying and Dividing Integers
Topic 26 Two Dimensional Arrays
Computer Science II First With files.
Computer Science II First With files.
Two-Dimensional Arrays
Truth tables: Ways to organize results of Boolean expressions.
Computer Science 2 Arrays of Records.
Computer Science 1 Get out your notebook
Computer Science 2 Review the Bubble Sort
Continue on the Array of Records program
Simplifying 1 + 2a + b + 1 a + b a + b + 1 2a b + a + b
Computer Science 2 Arrays of Records.
Dry run Fix Random Numbers
CS100J Lecture 18 Previous Lecture Programming concepts This Lecture
Truth tables: Ways to organize results of Boolean expressions.
More 2 D Array.
Computer Science Dynamics.
Data Types and Data Structures
Two-Dimensional Arrays
Computer Science Sorting.
Computer Science 1 1/19/2011 On the record (paper) write the following
Computer Science 2 Arrays of Records.
How do you store a bunch of similar stuff?
CS Software Studio Assignment 1
Computer Science 2 Tally Arrays 2/4/2016.
CS 2 Records 2/22/2018.
Truth tables: Ways to organize results of Boolean expressions.
Tic Tac Toe application
Computer Science 1 Online time for Graphics Program Random review
Computer Science II Second With files.
An example of how to represent a problem
© T Madas.
Beginning C Lecture 5 Lecturer: Dr. Zhao Qinpei
CS100J Lecture 18 Previous Lecture Programming concepts This Lecture
How do you store a bunch of similar stuff?
Computer Science I: Get out your notes.
Continue on the Valentines program
Time to finish first stack program
Coordinate Shirley Sides
AP Java Learning Objectives
Computer Science 1 while
Computer Science 1 Get out your notebook
Computer Science 1 Get out your notebook
Dry Run Fix it Write a program
Tic-Tac-Toe Game Engine
Computer Science II First With files.
Presentation transcript:

Continue with Life, Magic and Catch -up Computer Science 2 3/8/2018 Dry run Declarations Fix it Continue with Life, Magic and Catch -up

Dry Run!! program Sample2; type rectype = record of a:integer; b:real; end; arraytype = array[1..5] of rectype; var data: arraytype; count:integer; begin for count := 1 to 5 do data[count].a:= 2* count; data[count].b:= count -2; for count:= 1 to 5 do data[count].b:= data[count].b +data[count].a; for count:= 5 downto 1 do writeln(data[count].a:5, data[count].b:5:2); for count:= 1 to 4 do begin with data[count] do a := a + b; b := a*b; end; for count:= 1 to 5 do writeln(a,b:5:2) end.

Write the declarations for.. Storing 25 names, addresses, and ages. Storing 50 x-coordinates, y-coordinates, colors (numerical value), and file names (strings) for graphics. Creating a board for tic-tac-toe

This file is on the website as wreckt.pas Fix the following program wreckt; type record = record begin name:string; phone:number; end PhoneBook = array[1..10] of phones; var count:integer; PhoneBook:Arry of records; for count:= 1 to 10 do writeln('Please enter the name'); readln(Phoneboook[count]); writeln('Please enter the phone number'); readln(Phonebook[number]); end; writeln(Phonebook[count]); end. This file is on the website as wreckt.pas

Program: Life The universe is a two-dimensional grid of square cells, each of which is in one of two possible states, alive or dead, or "populated" or "unpopulated". Every cell interacts with its eight neighbors, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur: Any live cell with fewer than two live neighbors dies, as if caused by under population. Any live cell with two or three live neighbors lives on to the next generation. Any live cell with more than three live neighbors dies, as if by overpopulation. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

Patterns - Any live cell with fewer than two live neighbors dies, as if caused by under population. - Any live cell with two or three live neighbors lives on to the next generation. - Any live cell with more than three live neighbors dies, as if by overpopulation. - Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

Your application of Life Hint: include a boundary around your world. You determine the size of the universe Fill your universe: Examples Each cell has a 1 in N chance of being alive for the first generation. You select the value for N or have the user enter the value for N. Look up potential life patterns. Run the game for several generations. Show the universe after each generation Push: Break the program into procedures. neighbors(), showUniverse(), populate() Push: Determine a way to use records in your solution. Push: Have your universe ‘wrap’

Magic Square A magic square[1] is a n by n square grid (where n is the number of cells on each side) filled with distinct positive integers in the range {1,2,...,n2} such that each cell contains a different integer and the sum of the integers in each row, column and diagonal is equal

Magic Square Program Write a program that will take as input the values for each cell of a 3x3 potential magic square and determine if the square is magic. Push: Write a program to generate 3x3 magic squares. Using an algorithm rather than just hard coding a found solution. Push: Modify this to handle n x n magic squares.