Blockly Games: Bird - level 9

5,427 views
Skip to first unread message

Jamie

unread,
Feb 28, 2023, 11:37:14 AM2/28/23
to Blockly
Hello guys, why are my solutions wrong?
Thanks.
bird01.png
bird00.png

Neil Fraser

unread,
Mar 2, 2023, 8:11:52 AM3/2/23
to blo...@googlegroups.com
Am Di., 28. Feb. 2023 um 17:37 Uhr schrieb Jamie <jamie....@gmail.com>:
Hello guys, why are my solutions wrong?

This case is easiest to understand:

bird00.png
The bird flies at 180° until x = 20.
Then she flies at 270° until she has the worm (during this flight x remains at 20, so the first condition doesn't apply).
Then she flies at 90° until y = 60 (during this flight x remains at 20, so the first condition doesn't apply, and she has the worm, so the second condition doesn't apply).
So far so good.

Now the bird has the worm, x = 20, y = 60.  Thus the first three conditions don't apply, and so the fourth condition matches and she flies at 0°.  The moment she does so though, x becomes 21.  Now the first condition (x > 20) takes effect, causing the bird to fly back at 180°.  That's why the bird spasms back and forth, she's alternating between the first and fourth conditions.

Changing the first condition to be more specific will prevent it from applying later on:
Screenshot 2023-03-02 at 14.03.26.png

This gets the bird further along, but she then gets stuck with the "y < 60" condition intended for flying away from the worm, since that also applies when she flies towards the nest.  The solution is the same, just make the condition you don't want to apply more specific so it doesn't apply later on:
Screenshot 2023-03-02 at 14.07.12.png
 
Hope this helps.  The frantic twitching you are seeing is called an "emergent behaviour".  Nowhere in your program does it say to stop flying and twitch.  But the sum of the conflicting conditions create this unexpected pattern.

--
Neil Fraser, Switzerland
https://neil.fraser.name

Jamie Catter

unread,
Mar 4, 2023, 3:16:34 AM3/4/23
to blo...@googlegroups.com
Thank you.
Jamie

--
You received this message because you are subscribed to a topic in the Google Groups "Blockly" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blockly/QlQgQ4BhDAU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/CAEx9HWGrnXp58S5GBpB0i3vzHg2m1Vd3SS4JEuMHTrG0fexEYw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages