How to Design Worlds CS 5010 Program Design Paradigms “Bootcamp” Lesson 3.2 1 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this.

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.:
Interfaces CS 5010 Program Design Paradigms "Bootcamp" Lesson 10.2 © Mitchell Wand, This work is licensed under a Creative Commons Attribution-NonCommercial.
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.
Searching in a Graph CS 5010 Program Design Paradigms “Bootcamp” Lesson 8.4 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this.
Mutually-Recursive Data Definitions CS 5010 Program Design Paradigms “Bootcamp” Lesson 6.4 © Mitchell Wand, This work is licensed under a Creative.
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.
Invariants and Performance CS 5010 Program Design Paradigms “Bootcamp” Lesson 7.6 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
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.
Examining Two Pieces of Data CS 5010 Program Design Paradigms “Bootcamp” Lesson © Mitchell Wand, This work is licensed under a Creative.
Classes, Objects, and Methods CS 5010 Program Design Paradigms "Bootcamp" Lesson 10.1 © Mitchell Wand, This work is licensed under a Creative.
The Point of This Course CS 5010 Program Design Paradigms “Bootcamp” Lesson 0.1 © Mitchell Wand, This work is licensed under a Creative Commons.
Generalizing Similar Functions CS 5010 Program Design Paradigms “Bootcamp” Lesson 5.1 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Introduction to Universe Programs CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before.
Design Strategies 2: Using a template CS 5010 Program Design Paradigms “Bootcamp” Lesson 2.1 © Mitchell Wand, This work is licensed under a Creative.
Rewriting your function using map and foldr CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual.
Case Study: Free Variables CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
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.
A Case Study: Space Invaders CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under a Creative.
Patterns of Interaction 2: Publish-Subscribe CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed.
Solving Your Problem by Generalization CS 5010 Program Design Paradigms “Bootcamp” Lesson 7.1 © Mitchell Wand, This work is licensed under a.
Organization of This Course CS 5010 Program Design Paradigms “Bootcamp” Lesson 0.2 © Mitchell Wand, This work is licensed under a Creative Commons.
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.
Using the List Template CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Using the List Template CS 5010 Program Design Paradigms “Bootcamp” Lesson 4.2 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this.
More linear search with invariants CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before.
Converting from Immutable to Mutable Objects CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed.
Contracts, Purpose Statements, Examples and Tests
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
Introduction to Invariants
More Recursive Data Types
CS 5010 Program Design Paradigms “Bootcamp” Lesson 8.7
CS 5010 Program Design Paradigms “Bootcamp” Lesson 3.4
CS 5010 Program Design Paradigms “Bootcamp” Lesson 3.2
CS 5010 Program Design Paradigms “Bootcamp” Lesson 7.5
A Case Study: Space Invaders
Contracts, Purpose Statements, Examples and Tests
ormap, andmap, and filter
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 3.4
Presentation transcript:

How to Design Worlds CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAA © Mitchell Wand, This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. Creative Commons Attribution-NonCommercial 4.0 International License

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. 2

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. 3

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

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

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 6 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 7 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 8 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. 9

Info analysis falling-cat-1falling-cat-2 (pausable) drag w/ mousemodel gravity dimensions of canvasconstant x pos of catconstant worldworld if draggable y pos of catworld current speed of catconstantworld image/size of catconstant accelerationnot represented constant Fields needed:y-posy-pos, paused?x-pos, y-pos, paused? x-pos, y-pos, current-speed, paused? 10 either CATSPEED or 0; represented by 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. 11 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. 12 How to Design Universe Programs 1.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 13

Next steps If you have questions about this lesson, post them on the Discussion Board Do the Guided Practice for this Lesson Go on to the next lesson. 14