Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Where do I fit the recursion into this?
Old
graficdes9er
Guest
 
Status:
Posts: n/a
Default Where do I fit the recursion into this? - 03-15-2010, 08:07 PM

Here is my world. And I do not know where to place recursion. This is for an assignment, I know how recursion works, but not sure how it is going to work here. We have to click on the key and make the hare move. He is. That works.. and he moves forward.. Where would I place recursion, since that is the major thing about the assignment?
Attached Files
File Type: a2w test1_rabbit.a2w (3.56 MB, 43 views)
   
Reply With Quote
Old
graficdes9er
Guest
 
Status:
Posts: n/a
Default 03-15-2010, 09:44 PM

Anybody? I have to turn this in tonight.... ugh.
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 03-15-2010, 11:22 PM

Some assignments have you place certain program elements where they really shouldn't be (if you wanted it to be efficient, that is) for the sake of teaching you about that element. if all you have is a rabbit moving forward, you can just have a method where the rabbit moves forward, then have that method call itself after that. Bingo, you have recursion, and it's going to move that rabbit forward forever.

Now, if you want the rabbit to move a limited distance forward, you'll need to put a stopper in there somewhere. I'll leave that up to you.


(')>
   
Reply With Quote
Old
graficdes9er
Guest
 
Status:
Posts: n/a
Default 03-16-2010, 12:36 AM

Ok could you look at my file. I have it move forward, but I have the event saying when you click on the key.. it starts the process

This is how it goes

EVENT - when world starts - bunny say

When clicked on key
if x>5
windupKey roll "direction" 2 revs"
hare.slide (how much)

in hare slide I used if else.. roles and then included the hare slide again..

That is recursion right?
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 03-16-2010, 01:05 AM

Well... I always thought of recursion as something that calls itself in order to perform an action multiple times. Like this:

[PoolFill]
Pool fill with 15 gallons of water;
If pool is filled
>(Do nothing)
Else
PoolFill();

See, the method will keep calling itself over and over automatically until the pool is filled.

Now, recursion can also be something like:

[HareHop]
bunnyHops decrement by 1
Bunny move forward 1 meter
If bunnyHops > 0
>HareHop();
Else
>(Do nothing)

This is nearly the same setup, but using a number variable called bunnyHops as the condition which stops the recursion. By setting that variable to a certain number before you call the method HareHop for the first time, you can guarantee it will be called that many times and the bunny will move forward that many times.

I know for a fact that THAT'S recursion. But to make sure, let me look it up real quick...

And it looks like I'm right. To be recursive, a method or function must call itself as the very last command it executes (unless of course you put a conditional stop, as i did, in there).


(')>
   
Reply With Quote
Old
graficdes9er
Guest
 
Status:
Posts: n/a
Default 03-16-2010, 01:26 AM

Ok, so here is what I have - in my hare method I have it IF/ELSE...
IF "hare is within 1.5 meters of bunny" bunny say ...

ELSE - """ANOTHER if/else))
IF/World event - "which is the when mouse clicked on"
Do together - key roll -
Hare move forward random = min "" max "" dur ""

else - do nothing

under those is the hare method again placed.

in my events I have it say when you click on key - do together - key roll - hare.my user created method ELSE do nothing.
   
Reply With Quote
Old
rankhornjp
Guest
 
Status:
Posts: n/a
Default 03-16-2010, 09:29 AM

If I understand you correctly:

You want to click the key and then have the rabbit do "skateboardslide" until it gets to the ramp and then stop.

Is that correct?


If so, look at this file and see if it helps you out. Look at method iceSkater.closing
Attached Files
File Type: a2w skaterLogic.a2w (3.23 MB, 40 views)

Last edited by rankhornjp; 03-16-2010 at 09:40 AM.
   
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.