Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 게임에는 up, down, left, right 방향키 | ||
# 각 키를 누르면 위, 아래, 왼쪽, 오른쪽으로 한 칸씩 이동 | ||
# [0,0]에서 | ||
# , up-> [0, 1] | ||
# , down-> [0, -1] | ||
# , left-> [-1, 0] | ||
# , right-> [1, 0] | ||
|
||
def solution(keyinput, board): | ||
row = board[0] | ||
col = board[1] | ||
result = [0,0] | ||
for i in keyinput: | ||
if i == "left" and result[0]-1 >= -(row // 2): | ||
result[0]-=1 | ||
elif i == "right" and result[0]+1 <= (row // 2): | ||
result[0] += 1 | ||
elif i == "up" and result[1] +1 <= (col //2): | ||
result[1] += 1 | ||
elif i == "down" and result[1] -1 >= -(col //2): | ||
result[1] -= 1 | ||
return result |