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
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. The Curupira (Portuguese pronunciation: [kuɾuˈpiɾɐ]) is a mythological creature of Brazilian folklore. This creature blends many features of West African and European sprites but was usually regarded as mischievious. His name comes from the Tupi language kuru'pir, meaning "covered in blisters". According to the legend, this creature has bright red/orange hair and resembles a man or a dwarf, but its feet are turned backwards. – excerpted and edited from 2

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 Problem Solving step 3 Implementation
translate algorithm into code, one line at a time Do in order curupira runs to the soccer ball curupira kicks the soccer ball a random distance

6 Decomposition Recall Decomposition -- take a complex procedure and break into smaller, simpler actions 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 to the ball

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

8 Stepwise refinement Stepwise refinement: create another procedure & call it from this procedure 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 to the ball runningMotion

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

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

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

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

13 Comment

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

15 Video: 15. Selecting subpart joints
This video illustrates slide 16 Videos/16.SelectingSubparts.mp4

16 Select a joint in the skeleton
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

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

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 <target> Create runToObject procedure and add call to runningMotion runningMotion Do together curupira right leg turns forward curupira left leg turns backward We have completed runningMotion procedure

19 Implement runToObject
Click on Curupira tab Click on Add Procedure… Name it runToObject 1 Class panel 2 This is an alternative way to add a new procedure to a class, using the class panel 3

20 Add comment Call runningMotion

21 Test runToObject Return to myFirstMethod in the Scene class

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

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


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

Similar presentations


Ads by Google