Alice Community  

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

Reply
 
Thread Tools Display Modes
Cuckoo Clock Recursion
Old
jwehrly
Junior Member
 
Status: Offline
Posts: 1
Join Date: Sep 2013
Question Cuckoo Clock Recursion - 09-12-2013, 08:23 AM

Hello, my project is to create a cuckoo clock using recursion. Now I understand how recursion works and I have created the methods for this project but I cannot figure out how to create the IF/ELSE statement to end the loop when the user interacts with the running program. My exact assignment was written like this:

Chapter 8
Page 260, #7

On the Hour
Place a cuckoo clock (Objects) in a new world. Be sure to set the scene which means that you should select a room (look in Environments) as the backdrop for your scene as you certainly would not hang a cuckoo clock in the open air.

The idea of this animation is to have the cuckoo clock keep time (not in real time, of course). The minute hand should go around on the face of the clock (perhaps one complete revolution should take about 30 seconds in real time) and the pendulum should swing back and forth continually. When the minute hand has made one revolution (from 12 back to 12 [one revolution] on the face of the clock), then the hour hand should advance to the next hour [1/12 of a revolution], the doors should open, and the cuckoo bird (on the clock arm) should come out and chirp once. Then the bird should retreat inside the clock and the doors should close until the next hour has gone by. “All is well” as long as the clock is running—which should continue until the user stops the animation. Use a recursive method to implement the animation. Recall that ‘recursive’ means that the method calls itself. This world does not require any changes to Events but it does require a method to move the clock [cuckooClock.keepTime()] hands and another to control the cuckoo [cuckooCLock.cockoo()].

Any help is greatly appreciated.

V/r
Jwehrly
Attached Files
File Type: a2w Chapter7.a2w (873.1 KB, 61 views)
   
Reply With Quote
I also need help
Old
mmcham
Junior Member
 
Status: Offline
Posts: 4
Join Date: Jul 2014
Default I also need help - 08-17-2014, 10:07 AM

I am going to bump this back to the top because I am also stuck on this problem. I tried the original poster's solution code but it seems to actually be a loop and not a recursion. However using a loop seems to be the only way I have been able to get the pendulum to swing continuously. Maybe it is missing a variable or parameter somewhere because I do not seem to be able to drag anything into an IF/ELSE statement to recurse. It only shows IF true, do nothing (where I can drag something).

Thanks for any help or direction!
   
Reply With Quote
Look Elsewhere
Old
MrMoke
Senior Member
 
MrMoke's Avatar
 
Status: Offline
Posts: 501
Join Date: Sep 2007
Location: Austin, Texas
Default Look Elsewhere - 08-17-2014, 11:39 AM

The true can be replaced.
Click on World and then Function tab to view additional Boolean Logic, and Math, options that are available to you for making decisions. Just drag the appropriate test in over the true, drop it, and modify to your liking.

As mentioned in the text, you need to consider what condition requires a recursive call, what must be done before making the call, and what to do when that condition becomes false.

Since this project isn't a real-time simulation, the pendulum swing doesn't have to be a 1-second cycle, and the minute hand runs at twice the speed of a seconds hand.

The whole project takes only a small amount of coding, but a large amount of thought.

Last edited by MrMoke; 08-17-2014 at 02:31 PM.
   
Reply With Quote
Old
mmcham
Junior Member
 
Status: Offline
Posts: 4
Join Date: Jul 2014
Default 08-17-2014, 04:02 PM

Quote:
Originally Posted by MrMoke View Post
The true can be replaced.
Click on World and then Function tab to view additional Boolean Logic, and Math, options that are available to you for making decisions. Just drag the appropriate test in over the true, drop it, and modify to your liking.

As mentioned in the text, you need to consider what condition requires a recursive call, what must be done before making the call, and what to do when that condition becomes false.

Since this project isn't a real-time simulation, the pendulum swing doesn't have to be a 1-second cycle, and the minute hand runs at twice the speed of a seconds hand.

The whole project takes only a small amount of coding, but a large amount of thought.
Thanks. I've coded the pendulum swing, clock face movement, and cuckoo already and have them working. My hang up is the what function to make true and recursive.
   
Reply With Quote
Old
mmcham
Junior Member
 
Status: Offline
Posts: 4
Join Date: Jul 2014
Default 08-17-2014, 04:06 PM

Here's what I am working with. I am missing something really simple and it's driving me nuts. I have tried several functions from the world as true and can't figure it out.
Attached Files
File Type: a2w try4.a2w (720.1 KB, 11 views)

Last edited by mmcham; 08-17-2014 at 04:21 PM.
   
Reply With Quote
Think like a clock?
Old
MrMoke
Senior Member
 
MrMoke's Avatar
 
Status: Offline
Posts: 501
Join Date: Sep 2007
Location: Austin, Texas
Default Think like a clock? - 08-17-2014, 07:29 PM

Which of the routines that you have written would be the most likely to be used as a recursive method?
Clocks chime when a specific event is reached. What's happening while it's waiting? What is the event?

Click and open the vid to view the clues
Attached Files
File Type: zip Cuckoo.zip (781.3 KB, 21 views)

Last edited by MrMoke; 08-18-2014 at 08:13 AM.
   
Reply With Quote
Reply

Thread Tools
Display Modes

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 ©2019, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.