CS 5010 Program Design Paradigms “Bootcamp” Lesson 3.2

Slides:



Advertisements
Similar presentations
When do I need an invariant? CS 5010 Program Design Paradigms “Bootcamp” Lesson 7.4 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Advertisements

Binary Search CS 5010 Program Design Paradigms “Bootcamp” Lesson 8.3 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:
Contracts, Purpose Statements, Examples and Tests CS 5010 Program Design Paradigms “Bootcamp” Lesson 1.6 TexPoint fonts used in EMF. Read the TexPoint.
Two Draggable Cats CS 5010 Program Design Paradigms “Bootcamp” Lesson 3.4 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:
Foldr and Foldl CS 5010 Program Design Paradigms “Bootcamp” Lesson 7.5 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:
Draggable Cat CS 5010 Program Design Paradigms “Bootcamp” Lesson 3.3 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:
Working with images and scenes CS 5010 Program Design Paradigms “Bootcamp” Lesson 2.5 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Basics of Inheritance CS 5010 Program Design Paradigms "Bootcamp" Lesson 12.1 © Mitchell Wand, This work is licensed under a Creative Commons.
The Function Design Recipe CS 5010 Program Design Paradigms “Bootcamp” Lesson 1.1 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Midterm Review CS 5010 Program Design Paradigms “Bootcamp” Lesson 9.4 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:
Classes, Objects, and Methods CS 5010 Program Design Paradigms "Bootcamp" Lesson 10.1 © Mitchell Wand, This work is licensed under a Creative.
Lists CS 5010 Program Design Paradigms “Bootcamp” Lesson 4.1 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAA 1 ©
Ormap, andmap, and filter CS 5010 Program Design Paradigms “Bootcamp” Lesson 5.3 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Rewriting your function using map and foldr CS 5010 Program Design Paradigms “Bootcamp” Lesson 5.5 TexPoint fonts used in EMF. Read the TexPoint manual.
Structural Decomposition CS 5010 Program Design Paradigms “Bootcamp” Lesson 2.1 © Mitchell Wand, This work is licensed under a Creative Commons.
Introducing General Recursion CS 5010 Program Design Paradigms “Bootcamp” Lesson 8.2 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Foldr CS 5010 Program Design Paradigms “Bootcamp” Lesson 5.4 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAA © Mitchell.
The Function Design Recipe CS 5010 Program Design Paradigms “Bootcamp” Lesson 1.1 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Classes, Objects, and Methods CS 5010 Program Design Paradigms "Bootcamp" Lesson 10.1 © Mitchell Wand, This work is licensed under a Creative.
Introduction to Universe Programs CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before.
Rewriting your function using map and foldr CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual.
Two Draggable Cats CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before you delete this.
Generalizing Over Functions CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Lists of Structures CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before you delete this.
How to Design Worlds CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before you delete this.
A Case Study: Space Invaders CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under a Creative.
Solving Your Problem by Generalization CS 5010 Program Design Paradigms “Bootcamp” Lesson 7.1 © Mitchell Wand, This work is licensed under a.
Halting Measures and Termination Arguments CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual.
Non-Empty Lists CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:
Stateful Objects and Stable Identities CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under.
More linear search with invariants CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before.
Contracts, Purpose Statements, Examples and Tests
CS 5010 Program Design Paradigms “Bootcamp” Lesson 2.2
Generalizing Similar Functions
Examining Two Pieces of Data
More About Recursive Data Types
CS 5010 Program Design Paradigms “Bootcamp” Lesson 3.1
CS 5010 Program Design Paradigms “Bootcamp” Lesson 4.3
CS 5010 Program Design Paradigms "Bootcamp" Lesson 9.4
Introduction to Invariants
Reviewing your Program
More Recursive Data Types
CS 5010 Program Design Paradigms “Bootcamp” Lesson 8.7
CS 5010 Program Design Paradigms “Bootcamp” Lesson 4.1
From Templates to Folds
The Different Kinds of Data
Callbacks and Interacting Objects
CS 5010 Program Design Paradigms “Bootcamp” Lesson 3.4
Patterns of Interaction 2: Publish-Subscribe
Case Study: Undefined Variables
Patterns of Interaction 2: Publish-Subscribe
CS 5010 Program Design Paradigms “Bootcamp” Lesson 7.5
Solving Your Problem by Generalization
A Case Study: Space Invaders
Contracts, Purpose Statements, Examples and Tests
CS 5010 Program Design Paradigms “Bootcamp” Lesson 6.5
ormap, andmap, and filter
Generalizing Similar Functions
The Iterative Design Recipe
Rewriting your function using map and foldr
Working with images and scenes
Introduction to Universe Programs
Examining Two Pieces of Data
A Case Study: Space Invaders
CS 5010 Program Design Paradigms “Bootcamp” Lesson 4.1
When do I need an invariant?
CS 5010 Program Design Paradigms “Bootcamp” Lesson 8.3
CS 5010 Program Design Paradigms “Bootcamp” Lesson 3.4
Design Strategies 3: Divide into cases
Presentation transcript:

CS 5010 Program Design Paradigms “Bootcamp” Lesson 3.2 How to Design Worlds CS 5010 Program Design Paradigms “Bootcamp” Lesson 3.2 Welcome to Week 2, Lesson 1: "How to Design Universe Programs". In this lesson, you will learn the steps in designing universe programs. You will learn how to decide what data goes into the state of a world, and what does not. We will also introduce the concept of a "wish list" to help you organize your program. © Mitchell Wand, 2012-2014 This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAA

Introduction In this lesson, we will show to how to decide whether information should be represented as part of the world state, or whether it should be kept as a constant in the program By the end of this lesson, you should be able to analyze information to determine whether it should be constant or part of the world state.

Review: the 2htdp/universe module Provides a way of creating and running an interactive machine. Machine will have some state. Machine can respond to inputs. Response to input is described as a function. Machine can show its state as a scene. We will use this to create interactive animations.

What's in the state? The state consists of the information that changes in response to a stimulus. Other things are constants.

Traffic Light Example Number of ticks until next change: Current Color this changes on every tick. So: this goes in the state Current Color changes when countdown timer runs out How often each color lasts before changing doesn’t change So: this will be a constant, not part of the state

Information Analysis for falling-cat dimensions of canvas x pos of cat y pos of cat current speed of cat image/size of cat acceleration of gravity g which of these belong in the world? which should be constants? which need not be represented?

Information Analysis for falling-cat dimensions of canvas x pos of cat y pos of cat current speed of cat image/size of cat acceleration of gravity g These vary from frame to frame in the animation, so they are part of the animation's state (the world)

Information Analysis for falling-cat dimensions of canvas x pos of cat y pos of cat current speed of cat image/size of cat acceleration of gravity g These do NOT vary from frame to frame in the animation, so they are NOT part of the animation's state (the world). We will represent them as constants in our program This is not used in our program, so we don't need to represent it at all

The information analysis depends on the application The choice of information to represent depends on what our application does. Here are four variations of falling-cat: falling-cat-0: like falling-cat, but doesn't respond to space key falling-cat: our pausable falling cat draggable-cat: like falling-cat, but the cat can be dragged with the mouse model gravity: like falling-cat or draggable-cat, but the cat accelerates with simulated gravity. Let's see how the information analysis differs as we change the application.

either CATSPEED or 0; represented by paused? Info analysis either CATSPEED or 0; represented by paused? falling-cat-1 falling-cat-2 (pausable) drag w/ mouse model gravity dimensions of canvas constant x pos of cat world world if draggable y pos of cat current speed of cat image/size of cat acceleration not represented Fields needed: y-pos y-pos, paused? x-pos, y-pos, paused? x-pos, y-pos, current-speed, paused?

Gravity and Speed When there is no gravity, the cat's speed is either 0 or CATSPEED, so we can represent this with one bit (paused?). When there is gravity, the cat accelerates, so we need to keep track of its current speed. When the cat resumes motion, it should resume its previous speed. So we need to keep track of both its paused? state and its previous velocity. The problem should specify what happens when the cat resumes falling. Here we've assumed that the cat resumes falling at the same speed it was moving when it paused. If we specified that the cat starts falling again with speed 0, how would that change the representation?

Recipe for Designing a World Here are the steps in designing a world. These are the same steps we followed in falling-cat, except that we've spelled out more detail in Step 1. How to Design Universe Programs Information Analysis What events should the world respond to? What information changes in response to an event? What information doesn't change in response to an event? 2. From your information analysis, write out the constant definitions and data definitions. 3. From your list of events, write a wishlist of functions to be designed 4. Design the functions on your wishlist (use the design recipe!)

Summary Information that can change after an event goes into the world state Info that doesn't change is represented by constants Manage your project with a wishlist Wishlist must include contracts and purpose statements for each function

Next steps If you have questions about this lesson, post them on the Discussion Board Go on to the next lesson.