day 6-5 python (무작위 장애물)
2023. 3. 2. 15:43ㆍ개인적인 공부/Python
나의 코드
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()
코드의 줄 수 는 많아도 실행속도가 빠르다.
'개인적인 공부 > Python' 카테고리의 다른 글
day 7-2 hangman (1) | 2023.03.10 |
---|---|
day 7-1 hangman (0) | 2023.03.10 |
day 6-4 python (while 반복문 장애물) (0) | 2023.03.01 |
day 6-3 python while 반복문 (0) | 2023.03.01 |
day 6-2 python (반복문) (0) | 2023.03.01 |