Presentation is loading. Please wait.

Presentation is loading. Please wait.

Stepwise Refinement -- A procedure calls another procedure.

Similar presentations


Presentation on theme: "Stepwise Refinement -- A procedure calls another procedure."— Presentation transcript:

1 Stepwise Refinement -- A procedure calls another procedure

2  A curupira is playing soccer in the rainforest. The curupira has a soccer ball and will kick the soccer ball toward a pond in the forest. Each kick causes the soccer ball to move forward a random distance.  If the curupira gets the soccer ball in the water, the curupira does a dance, otherwise he disappears, shocked that he didn’t succeed.

3 Problem solving step 1  Download and open the world: CurupiraSoccerSetup.a3p

4 Problem Solving step 2  Design an algorithm Do in order curupira runs to soccer ball curupira kicks the soccer ball a random distance If soccer ball is in the water, curupira dances else curupira disappears

5  Implementation translate algorithm into code, one line at a time Problem Solving step 3 Do in order curupira runs to the soccer ball curupira kicks the soccer ball a random distance …

6 Do in order curupira runs to the soccer ball curupira kicks the soccer ball a random distance … Decomposition runToObject Do together curupira performs running motion curupira moves forward to the ball Recall Decomposition -- take a complex procedure and break into smaller, simpler actions

7 runToObject Do together curupira performs a running motion curupira moves forward distance to the Problem There is no running motion procedure for the curupira

8 runToObject Do together curupira performs running motion curupira moves forward to the ball  Stepwise refinement: create another procedure & call it from this procedure Stepwise refinement myFirstMethod Do in order curupira runs to the soccer ball curupira kicks the soccer ball a random distance … runningMotion

9  runningMotion Algorithm Do in order Do together curupira right leg turns forward curupira left leg turns backward Do together curupira right leg turns backward curupira left leg turns forward Do together curupira right leg turns forward curupira left leg turns backward

10 Video: 14. Create a procedure This video illustrates the steps documented in slides

11  Select Curupira from the class menu in the code editor Open Curupira class document

12  Select Add Procedure… and name it runningMotion Declare a new procedure

13 Comment

14 By default, actions are for this (entire) curupira Translating algorithm to code Do in order Do together curupira right leg turns forward curupira left leg turns backward Do together curupira right leg turns backward curupira left leg turns forward Do together curupira right leg turns forward curupira left leg turns backward

15  This video illustrates slide 16 Video: 15. Selecting subpart joints

16  Click on the instance menu  Select an appropriate joint for the subpart  In this example, select the hip because the leg subpart turns at the hip Select a joint in the skeleton

17  Now add the code  Remember the Do Together! Complete procedure

18 Working our way back up… myFirstMethod Do in order curupira runs to the soccer ball curupira kicks the soccer ball a random distance … runToObject Do together curupira performs running motion curupira moves forward distance to the runningMotion Do together curupira right leg turns forward curupira left leg turns backward … We have completed runningMotion procedure Create runToObject procedure and add call to runningMotion

19 1. Click on Curupira tab 2. Click on Add Procedure… 3. Name it runToObject Implement runToObject Class panel

20  Add comment  Call runningMotion

21  Return to myFirstMethod in the Scene class Test runToObject

22 Test – call from myFirstMethod myFirstMethod Do in order curupira runs to the soccer ball curupira kicks the soccer ball a random distance … runToObject Do together curupira performs running motion curupira moves forward distance to the runningMotion Do together curupira right leg turns forward curupira left leg turns backward … Testing: Call runToObject from myFirstMethod

23 Call runToObject in myFirstMethod … we need to call it somewhere in our program 1.Select curupira in the instance menu 2.Drag the runToObject tile into myFirstMethod in the editor 3.Click on Run After we have defined the new procedure, runToObject…


Download ppt "Stepwise Refinement -- A procedure calls another procedure."

Similar presentations


Ads by Google