Question: Write a program for Karel to move all coins from the left room to the exact same positions in the room on the right! There
Write a program for Karel to move all coins from the left room to the exact same positions in the room on the right! There are many possible solutions. One code needs to work for all mazes shown below.
Sweeping the room efficiently is key. Let's use, for example, a spiral path. The spiral can be defined via a helper list:
H
What this means, is "make steps forward, turn right, make steps forward, turn right, To follow the spiral path, parse this list using a for loop using an index variable n The body of the for loop is very simple: After making n steps, turn right.
Then create an empty list L to remember the positions of the coins along the way. After each step, append True to L if a coin is there, and False otherwise. You don't need a condition to do this, just take the value of the Boolean sensor coin. Do not forget to collect the coins.
Then move to the other room, and use a similar method to place the coins there, following the spiral path defined by the list H
Sample type of code:
while not home
if coin
get
right
go
if not coin
left
left
go
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
