개인적인 공부/Python

day 6-5 python (무작위 장애물)

karatejin 2023. 3. 2. 15:43

첫번째 시도
두번째 시도
세번째 시도

 

나의 코드

def turn_right():
    turn_left()
    turn_left()
    turn_left()

while not at_goal():
    
    if wall_in_front() and wall_on_right():
        turn_left()
    elif wall_on_right() == True:
        move()
    elif right_is_clear() or wall_in_front() == True:
        turn_right()
        move()
        turn_right()
        move()
    else:
        move()

코드의 줄수는 적어도 실행 속도가 느림

 

 

다른 코드

def turn_right():
    turn_left()
    turn_left()
    turn_left()
    
def met_wall():
    turn_left()
    while wall_on_right():
        move()
    turn_right()
    move()
    turn_right()
    while front_is_clear():
        move()
    turn_left()
        

while not at_goal():
    
    if wall_in_front():
        met_wall()        
    else:
        move()

코드의 줄 수 는 많아도 실행속도가 빠르다.