[이것이 코딩테스트다] 실전문제 게임 개발

최대한·2021년 1월 3일
0
post-custom-banner
h,w=map(int, input().split())
x,y,d=map(int,input().split())
m=[]
d_list=[0,1,2,3]
x_list=[-1,0,1,0]
y_list=[0,1,0,-1]
count=1
for i in range(h):
    m.append(input().split())
d_count=0
while True:
    m[x][y]='1'
    next_d = d_list[d-1]
    next_x = x + x_list[next_d]
    next_y = y + y_list[next_d]
    if d_count == 4:
        if d % 2 == 0:
            next_x = x + -x_list[d]
            if m[next_x][y] == '0':
                x = next_x
                continue
            else:
                break
        else:
            next_y = y + -y_list[d]
            if m[x][next_y] == '0':
                y = next_y
                continue
            else:
                break
    d = next_d
    if d % 2 == 0 and m[next_x][y] == '0':
        x = next_x
        d_count=0
        count+=1
    elif d % 2 == 1 and m[x][next_y] == '0':
        y = next_y
        d_count=0
        count+=1
    else:
        d_count+=1
    continue
print(count)
profile
Awesome Dev!
post-custom-banner

0개의 댓글