1.1. Harvest ¶
- harvest1.wld 월드 파일을 연다.
 
- 현재 지도에 있는 모든 씨앗을 수확하는 로직을 짠다.
 
 
~cpp 
def move_and_pick():
    move()
    if next_to_a_beeper():
      pick_beeper()
def upAndTurnLeft():
    turn_left()
    move()
    pick_beeper()
    turn_left()   
 
def upAndTurnRight():
    turn_left()
    turn_left()
    turn_left()
    move()
    turn_left()
    turn_left()
    turn_left()
def harvestTwoRow():
    repeat(move_and_pick,6)
    upAndTurnLeft()
    repeat(move_and_pick,6)
    upAndTurnRight()
repeat(harvestTwoRow,3)
turn_off()
1.2. 선택적 Harvest ¶
- harvest2.wld 월드 파일을 연다.
 
- 현재 2개인 씨앗도 섞여 있다. 모든 밭에 1개인 씨앗만 있게 만든다.
 
~cpp 
next_to_a_carrot=next_to_a_beeper
plant_carrot = put_beeper
pick_carrot = pick_beeper
def pick_TwoCarrot():
    if next_to_a_carrot():
        pick_carrot()
        if not next_to_a_carrot():
            plant_carrot()
def one_carrot_only():
    if not next_to_a_carrot():
        plant_carrot()
def move_and_pick():
    if front_is_clear():
       move()
       pick_TwoCarrot()
    else:
        upAndTurnLeft()
def move_and_put():
    move()
    one_carrot_only()
def upAndTurnLeft():
    turn_left()
    move()
    pick_beeper()
    turn_left()    
def upAndTurnRight():
    turn_left()
    turn_left()
    turn_left()
    move()
    turn_left()
    turn_left()
    turn_left()
downAndTurnRight = upAndTurnLeft
downAndTurnLeft = upAndTurnRight 
def harvestTwoRow():
    repeat(move_and_pick,6)
    repeat(move_and_pick,6)
repeat(harvestTwoRow,1)
upAndTurnRight()
repeat(move_and_pick,6)
repeat(move_and_pick,5)
upAndTurnRight()
repeat(move_and_pick,6)
repeat(move_and_pick,5)
one_carrot_only()
turn_left()
turn_left()
repeat(move_and_put,5)
downAndTurnLeft()
one_carrot_only()
repeat(move_and_put,5)
downAndTurnRight()
one_carrot_only()
repeat(move_and_put,5)
downAndTurnLeft()
one_carrot_only()
repeat(move_and_put,5)
downAndTurnRight()
one_carrot_only()
repeat(move_and_put,5)
downAndTurnLeft()
repeat(move_and_put,5)
turn_off()
1.3. 임의의 개수 씨를 처리하는 Harvest ¶
- harvest3.wld 월드 파일을 연다.
 
- 현재 2개 이상인 씨앗이 밭에 있다. 모두 1개인 씨앗만 있게 만든다.
 
- 이 경우에서의 처리를 while 문을 사용하여 처리한다.
 
~cpp 
next_to_a_carrot=next_to_a_beeper
plant_carrot = put_beeper
pick_carrot = pick_beeper
def upAndTurnLeft():
    turn_left()
    move()
    pick_beeper()
    turn_left()    
def upAndTurnRight():
    turn_left()
    turn_left()
    turn_left()
    move()
    turn_left()
    turn_left()
    turn_left()
downAndTurnRight = upAndTurnLeft
downAndTurnLeft = upAndTurnRight 
def pick_TwoCarrot():
    if next_to_a_carrot():
       while next_to_a_carrot():
           pick_carrot()
       if not next_to_a_carrot():
           plant_carrot()
def one_carrot_only():
    if not next_to_a_carrot():
        plant_carrot()
def move_and_pick():
    if front_is_clear():
       move()
       pick_TwoCarrot()
    else:
        upAndTurnLeft()
def move_and_put():
    if front_is_clear():
       move()
       one_carrot_only()
    else:
        downAndTurnLeft()
def harvestTwoRow():
    repeat(move_and_pick,6)
    repeat(move_and_pick,6)
repeat(harvestTwoRow,1)
upAndTurnRight()
repeat(move_and_pick,6)
repeat(move_and_pick,5)
upAndTurnRight()
repeat(move_and_pick,6)
repeat(move_and_pick,5)
one_carrot_only()
turn_left()
turn_left()
repeat(move_and_put,6)
one_carrot_only()
repeat(move_and_put,5)
downAndTurnRight()
one_carrot_only()
repeat(move_and_put,6)
one_carrot_only()
repeat(move_and_put,5)
downAndTurnRight()
one_carrot_only()
repeat(move_and_put,6)
one_carrot_only()
repeat(move_and_put,5)
turn_off()
1.4. Amazing Part 1 ¶
-  amazing1.wld 월드 파일을 연다.
 
- 현재 월드를 한바귀 도는 로직을 만든다.
 
{{{~cpp 
put_beeper()
while not next_to_a_beeper():
    if front_is_clear():
        move()
    else:
        turn_left()
turn_off()
== Amazing Part 2 ==
 *  amazing2.wld 월드 파일을 연다.
 * 현재 월드를 한바귀 도는 로직을 만든다.
{{{~cpp 
def turn_right():
    repeat(turn_left, 3)
put_beeper()
move()
while not next_to_a_beeper():
    if right_is_clear():
        turn_right()
        move()
    elif front_is_clear():
        move()
    else:
        turn_left()
turn_off()
}}}
== Amazing Part 3,4 ==
 *  amazing3.wld 월드 파일을 연다.
 * 현재 월드를 한바귀 도는 로직을 만든다.
{{{~cpp 
def turn_right():
    repeat(turn_left,3)
put_beeper()
if front_is_clear():
    move()
else:
    turn_left()
    if front_is_clear():
        move()
    else:
        turn_left()
        move()
while not next_to_a_beeper():
    if front_is_clear():
        if right_is_clear():
            turn_right()
            move()
        else:
            move()
    else:
        turn_left()
turn_off()
}}}
== Amazing Part 5 ==
 *  amazing5.wld 월드 파일을 연다.
 * 현재 월드를 한바귀 도는 로직을 만든다.
{{{~cpp 
def turn_right():
    repeat(turn_left,3)
if front_is_clear():
    move()
else:
    turn_left()
    if front_is_clear():
        move()
    else:
        turn_left()
        move()
while not next_to_a_beeper():
    if right_is_clear():
        turn_right()
        move()
    elif front_is_clear():
        move()
    else:
        turn_left()
turn_off()
}}}
== 이제 만든 amazing을 써먹어 보자 ==
 * hurdle3.wld 월드 파일을 열어서 돌려보자.(처음의 put_beeper()는 빼야함)
 * maze1.wld 월드 파일을 열어서 돌려보자.
 * amazing을 해보면서 느낀점을 각자 이야기 해봅시다~!
== rain1 ==
 * rain1.wld 월드 파일을 연다.
 * 처음 시작한 창문 말고 나머지 창문들을 beeper를 앞에 두는 식으로 해서 닫는다. 로봇은 처음 시작하는 창문으로 온다음에 그 창문을 바라보아야 한다. 시작시에 로봇은 beeper를 충분히 가지고 있다.
{{{~cpp 
def turn_right():
    repeat(turn_left,3)
move()
put_beeper()
turn_left()
move()
def close_window():
    if not front_is_clear():
        turn_right()
    elif left_is_clear():
        put_beeper()
        move()
    else:
        move()
def turn_around():
    while not next_to_a_beeper():
        close_window()
    pick_beeper()
    turn_left()
turn_around()
turn_off()
}}}
== rain2 ==
 * rain2.wld 월드 파일을 연다. rain1과 좀 다르게 생겼다.
 * rain1의 코드를 여기서도 돌아가도록 만든다.
{{{~cpp 
def turn_right():
    repeat(turn_left,3)
def turn_back():
    repeat(turn_left,2)
move()
put_beeper()
turn_left()
move()
def close_window():
    if not front_is_clear():
        turn_right()
    elif left_is_clear():
        put_beeper()
        move()
        if left_is_clear():
            turn_back()
            move()
            pick_beeper()
            turn_right()
            move()
    else:
        move()
def turn_around():
    while not next_to_a_beeper():
        close_window()
    pick_beeper()
    turn_left()
turn_around()
turn_off()
}}}
== trash1 ==
 * trash1.wld 월드 파일을 연다. 
 * 여기 있는 beeper들을 모두 모아가지고 왼쪽 위 구석에 모두 모은다.다 모은후 시작할때의 위치에서 그 자세로 있는다.
{{{~cpp 
def turn_back():
    repeat(turn_left,2)
def turn_right():
    repeat(turn_left,3)
def go_to_garbage():
    turn_back()
    while front_is_clear():
        move()
    turn_right()
    move()
    put_beeper()
    turn_back()
    move()
    turn_left()
while front_is_clear():
    move()
    if next_to_a_beeper():
        pick_beeper()
        go_to_garbage()
turn_back()
while front_is_clear():
    move()
turn_back()
turn_off()
}}}
== trash2 ==
 * trash2.wld 파일을 연다. trash1에서 작성한 로직이 여기서도 돌아가야 한다.
----
[RUR-PLE]












