본문 바로가기
개발일지/Python

2022.01.20 Day-6-1 유데미 파이썬 부트캠프 (로봇게임코딩1)

by 개발에정착하고싶다 2022. 1. 20.
320x100

오늘의 과제는 대체로 쉽고
더 게임식의 가시적인 느낌이여서 쉬운 느낌이였다.

https://reeborg.ca/reeborg.html?lang=en&mode=python&menu=worlds%2Fmenus%2Freeborg_intro_en.json&name=Hurdle%202&url=worlds%2Ftutorial_en%2Fhurdle2.json

여기가 해당 게임 코딩 진행 사이트다.

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

def jump():
    move()
    turn_left()
    move()
    turn_right()
    move()
    turn_right()
    move()
    turn_left()

for i in range(6):
    jump()
    if at_goal():
        break


이걸 내가 작성했다는게 참 신기하긴 하다.
코딩을 할때 점점 느끼는 것은 사소한 것이라도 쌓여가는 순서의 사고방식을 무시하면
멈춘다는 것이다.
가급적 생각이 가능한 한에서 사소한거라도 차근차근 생각을 해야한다.

선생님께서 알려주신 방법은 마지막 접근법이 달랐으며 매우 좋았다.
for 문의 경의에는 범위, 리스트 등의 값을 다 쓰고 나면 더 이상 출력을 못하는 구조 이거나
아니면 내가 만든 것처럼 break로 깰 수 는 있지만 코드가 다소 길어지낟.

하지만 while 은 "사실일 때 까지 돌려주면 된다."
때문에 코드가 매우 간결하게 끝날 수 있었다.

선생님은
while not at_goal():
    jump()
라고 해주셨다.

와... 골이 사실이 아니라면 점프를 출력하고
사실일 경우엔 거기서 끝난다니....


와... 이걸 보고 있으면서도 진짜 믿기지가 않게 신기하다

https://reeborg.ca/reeborg.html?lang=en&mode=python&menu=worlds%2Fmenus%2Freeborg_intro_en.json&name=Hurdle%203&url=worlds%2Ftutorial_en%2Fhurdle3.json

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

def jump():
    turn_left()
    move()
    turn_right()
    move()
    turn_right()
    move()
    turn_left()

while not at_goal():
    if front_is_clear():
        move()
    elif wall_in_front():
        jump()


==========================
허들 4는 1시간동안 붙들고 해봤는데 안되더라;

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

def jump():
    while wall_on_right():
        move()
        if not wall_on_right():
            turn_right()
    
while not at_goal():
    if front_is_clear() and wall_on_right():
        move()    
    elif wall_in_front() and wall_on_right():
        turn_left()
    elif wall_in_front() and not wall_on_right():
        turn_right()

이게 내 코드인데 아무튼 안된다.

최소한에 조건 값자체가 "바닥이 보다 오퍼시티 값이 빠졌을때" 만이라도 생성한다면
충분히 어렵진 않은 조건일테지만
제한 조건 하에서의 코딩이라 그런가 암튼 어렵네


이건 선생님이 알려주신 코드다.

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

def jump():
    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():
        jump()
    else:
        move()

와... 그저 놀라울 따름이다.
새삼 게임 프로그래머가 얼마나 대단한 인력인지 깨닫게 된다.

300x250