Practical session 8 Assignment 3. Game of life A zero-player game. Simulates Evolution, of an infinite two-dimensional matrix’s cells. Each cell can be.

Slides:



Advertisements
Similar presentations
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Advertisements

Computer Science 320 Clumping in Parallel Java. Sequential vs Parallel Program Initial setup Execute the computation Clean up Initial setup Create a parallel.
MATH 224 – Discrete Mathematics
Contest format 5 hours, around 8-12 problems One computer running (likely)Linux, plus printer 3 people on one machine No cell phones, calculators, USB.
Recursion vs. Iteration The original Lisp language was truly a functional language: –Everything was expressed as functions –No local variables –No iteration.
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture two Dr. Hamdy M. Mousa.
Python Programming: An Introduction to Computer Science
Sorted list matching & Experimental run-Time COP 3502.
Section 2.3 Gauss-Jordan Method for General Systems of Equations
COMPUTER SIMULATIONS Important for research… But also really fun.
CSI 101 Elements of Computing Spring 2009 Lecture # 8 Looping and Recursion Wednesday, February 25 th, 2009.
1 Chapter 18 Recursion Dale/Weems/Headington. 2 Chapter 18 Topics l Meaning of Recursion l Base Case and General Case in Recursive Function Definitions.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 16: Recursion.
Multi-Core ßeta Computer Christopher Celio & Matt Long Spring 2007.
Project 1CS-4513, D-Term Programming Project #1 Concurrent Game of Life Due Friday, March 20.
The Power of Calling a Method from Itself Svetlin Nakov Telerik Corporation
Fibonacci Problem Solving and Thinking in Engineering Programming H. James de St. Germain.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
Chapter 1 Algorithm Analysis
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
CPSC 171 Introduction to Computer Science 3 Levels of Understanding Algorithms More Algorithm Discovery and Design.
A Level Computing#BristolMet Session Objectives U2#S6 MUST identify different data types used in programming aka variable types SHOULD describe each data.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 2.
Recursion, Complexity, and Searching and Sorting By Andrew Zeng.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 17: Recursion.
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 10 Scott Marino.
Recursion. What is recursion? Solving a problem in terms of itself or repeating objects in a “self-similar” way A recursive function is a function that.
Copyright © 2007, Oracle. All rights reserved. Managing Concurrent Requests.
Composition and Evolution of Operating Systems Introduction to Operating Systems: Module 2.
Recursion, Complexity, and Sorting By Andrew Zeng.
Recursion. Recursive Methods HAVE: 1.A base case or termination condition that causes the method to end 2.A non-base case whose actions move the algorithm.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 19 : Recursion King Fahd University of Petroleum & Minerals College of Computer.
ICS 145B -- L. Bic1 Project: Main Memory Management Textbook: pages ICS 145B L. Bic.
Algorithms and Algorithm Analysis The “fun” stuff.
The Structure of Processes (Chap 6 in the book “The Design of the UNIX Operating System”)
Programming Principles Chapter 1. Objectives Discuss the program design process. Introduce the Game of Life. Discuss object oriented design. – Information.
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.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
Design Issues. How to parallelize  Task decomposition  Data decomposition  Dataflow decomposition Jaruloj Chongstitvatana 2 Parallel Programming: Parallelization.
FORS 8450 Advanced Forest Planning Lecture 5 Relatively Straightforward Stochastic Approach.
Introduction to Computation and Problem Solving Class 33: Activ Learning: Sorting Prof. Steven R. Lerman and Dr. V. Judson Harward.
Project18’s Communication Drawing Design By: Camilo A. Silva BIOinformatics Summer 2008.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
CSC 1010 Programming for All Lecture 4 Loops Some material based on material from Marty Stepp, Instructor, University of Washington.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 16: Recursion.
Decision Making and Branching (cont.)
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 6 l Array Basics l Arrays in Classes and Methods l Programming.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Simple algorithms on an array - compute sum and min.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
Assembly Language Co-Routines
Digital Electronics and Computer Interfacing Tim Mewes 2. LabVIEW Basics part II.
Given a node v of a doubly linked list, we can easily insert a new node z immediately after v. Specifically, let w the be node following v. We execute.
Function Recursion to understand recursion you must understand recursion.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
Practical Session 9 Computer Architecture and Assembly Language.
Topic: Introduction to Computing Science and Programming + Algorithm
Assignments A sample main program for Project 2 phase 2 is contained in: It reads.
Fundamentals of Programming
RTS: Kernel Design 11/30/2018.
RTS: Kernel Design 1/2/2019.
Introduction to Repetition Structures
Computer Architecture and Assembly Language
Intro to Computer Science Loops
The structure of programming
Fundaments of Game Design
Computer Architecture and Assembly Language
Presentation transcript:

Practical session 8 Assignment 3

Game of life A zero-player game. Simulates Evolution, of an infinite two-dimensional matrix’s cells. Each cell can be alive or dead. A cell’s state in each iteration (generation) is set with accordance to its former state and its neighbors’ states.

Our version We’ll simulate a simplified, one-dimensional (finite) array. Each cell is given an initial state on program startup At each “generation”, a cell will determine its next state according to its former state and its neighbors’ states, using a given transition function

Implementation Using the co-routine mechanism, we’ll write a small simulator for the game. Running co-routines: – n cell instances – A printer – A scheduler

A Cell Can be alive(1) or dead(0) Executes a simple infinite loop: 1.Calculate next state using current state (of “me” and my left and right neighbors). 2.Update new state After each of these two stages, the cell co- routine must resume the scheduler. In other words, it loops (for ever) over: (1)  resume  (2)  resume

A Cell Just to be perfectly clear: – cell i ‘s left neighbor is cell i-1. – cell i ‘s right neighbor is cell i+1. – The Array “wraps around”  calculations are %WorldSize

A Cell How do we determine a cell’s next step? – One of the program’s parameters is a transition function: A sequence of hexadecimal digits (a nibble of bits) such as “B1E3”. Each digit represents a transition. B  1011 Left neighbor’s state Right neighbor’s state “My” state new state

Transition example Given this transition function: B = = E = = Say a cell is dead, its left neighbor is dead and its right neighbor is alive, then “3” can be applied, and thus the next state is alive (1). When no transition can be applied, no transition is done: Say a cell is alive, its left neighbor is alive and its right neighbor is dead  no transition fits the case (we’d need either “C” or “D”), and thus no change is made.

The printer Simply prints the entire “world” (the array), whenever it gets “time”.

The scheduler You are to implement a simple round-robin scheduler. void scheduler(int cycles) – Iterate cycles times over all cells – After each K resumes of cell co-routines, resume the printer. – At the end of all cycles, resume the printer once more, and then terminate the process.

Program’s flow Invoked using: >ass3 where: – - A series of “0” and “1”. describes the initial state, as well as the amount of cells – - Amount of scheduler cycles through each cell – - Printing frequency – - A series of hexadecimal digits

Program’s flow When invoked, and using the co-routines mechanism from class, your application will: – Set up: a state array, WorldSize, K – Initiate all co-routines: Each cell needs to get a parameter i with its index. The scheduler needs to get cycles (t) as a parameter. Initiate the printer – Initiate an array CORS of pointers to: cell 1, cell 2, …, cell WorldSize, scheduler, printer. – Transfer control to scheduler

Technicalities You are to submit a single.zip file, using the same directory structure as in previous assignments. src folder will include: – ass3.s (with most of the code) – printer.s (printer function code) – scheduler.s (scheduler function code)

Example Let’s run an example using your simple scheduler: >ass B46DF Cellleftcurrnext First 8 “time slices” produce readings and state computations: New 2 4 B

Example ;after 7 “resumes”. No updates ;after 14; 6 updates made ;(21): no second updates yet ;(28): 4 second cycle updates ;(35): 2 nd cycle updated ;(40): last print (done cycling)