It's good to find a banana and proceed, but if a robot stop when there is nothing, it can't find it yourself.
Let's give curiosity. Move the robot even when nothing is happening to make the program look like it is curious.
Operant behavior
Try moving forward or turning to the right when nothing is happening.
Such spontaneous behavior is called "operant behavior" in psychological terms.
It's the behavior that people do when they're bored, or the whimsical behavior that makes them crazy.
If you move the robot somehow and if it finds a banana and move forward firmly, you can make a robot as if it is curious!
Program
Let's rewrite the part of the previous program that finds bananas and goes on without finding anything.
Now let's use the function.
A function is a function that can combine several blocks into one.
If you can do that, you can make only one movement into one, so the program will be refreshed.
There is a "destination" do something "" in the "function", so we bring it.
This is a function, and we can put blocks in it.
And "Do something" is the name of the function.Let's change this.
This time, we want to put a program about operant behavior here, so we will call it "operant".
Then, a small block called "operant" is created in the "function".
When this block is executed, the block put in the operator function is executed!
Let's put a program of operant behavior in the operant function, and put this little operator block when it can't find a banana or a pumpkin ghost.
This will execute the inside of the operator function when nothing is found.
Let's put some whimsical movements here.
Whimsical movement
Computer is not good at random.
It is designed to work as instructed, so it am not good at not having instructions.
We want to move forward somehow or turn to the right somehow, what should we do?
There is a block called "Random Number" in "Calculation".
This round block is a block that changes to a different number each time, sometimes it becomes 1 and sometimes it becomes 50.
This is useful for making random movements!
For example, if it goes straight only when it is 1 and turn right otherwise, it can go straight very sometimes.
If it is 50 or less, it is straight, and if it is larger than 50, it is rotated clockwise. There is a 50% chance that it will go straight or turn to the right.
There is like this.
If this number is less than "accidentally" 50, the robot will rotate forward, otherwise it will rotate clockwise.
But the loop moves very fast.
This alone will make the movement really strange, so let's put in a block to wait and decide the movement once and let it move a little as it is.
The whole program looks like this.
By doing this, even when there is nothing, it will make random movements such as spinning and going straight.It's like it's looking for something!
Find a banana
If a robot find a banana, it will go straight, so let's put a little banana and experiment.
A robot should move a little more slowly so that it can find it.
Let's make the movement during operant action a block that can change the strength of the motor.
Set it to a slightly smaller value such as 40 or 50 and rotate it straight.
When we try to move it, it works just as well, but unlike before, finding bananas has become a little easier.
A robot is a whim,it can find only way when there is a banana.
How to make it easier to find
This is fine if it's random, but it can be smarter if it's a move for the "find bananas" mission.
It will develop from here, so please try various things.
For example, if a robot knows that a banana is definitely nearby, it may find it better not to go too far.
Or, it would be nice to move away while drawing a circle.
There are many ideas.It should be easier to find just by changing the speed of the motor. Please try various things