Skip to content

Commit

Permalink
0831-3
Browse files Browse the repository at this point in the history
  • Loading branch information
oje2024 committed Aug 31, 2024
1 parent 1508099 commit 066cea9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions JEOH/51to60/53.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
def solution(board, aloe, bloc): #해결못해서 답지참고함
ROW, COL = len(board), len(board[0])
DR, DC = [-1, 0, 1, 0], [0, 1, 0, -1]
def is_valid_pos(r, c):
return 0 <= r < ROW and 0 <= c < COL
def recursive_func(alpha_pos, beta_pos, visited, step):
r, c = alpha_pos if step % 2 == 0 else beta_pos
can_move = False
is_opponent_winner = True
win_steps, lose_steps = [], []
for i in range(4):
nr, nc = r + DR[i], c + DC[i]
if is_valid_pos(nr, nc) and (nr, nc) not in visited and board[nr][nc]:
can_move = True
if alpha_pos == beta_pos:
return True, step + 1
win, steps_left = (
recursive_func([nr, nc], beta_pos, visited | {(r, c)}, step + 1)
if step % 2 == 0
else recursive_func(
alpha_pos, [nr, nc], visited | {(r, c)}, step + 1
)
)
is_opponent_winner &= win
(win_steps if win else lose_steps).append(steps_left)
if not can_move:
return False, step
if is_opponent_winner:
return False, max(win_steps)
return True, min(lose_steps)
Empty file added JEOH/81to90/86.py
Empty file.
Empty file added JEOH/81to90/87.py
Empty file.
Empty file added JEOH/81to90/88.py
Empty file.
Empty file added JEOH/81to90/89.py
Empty file.
Empty file added JEOH/81to90/90.py
Empty file.

0 comments on commit 066cea9

Please sign in to comment.