Check if the current player has won. Args: player_pos: Dict of player positions (X and O) cur_player: Current player ("X" or "O") Returns: True if player wins, False otherwise >>> check_win({"X": [1,2,3], "O": []}, "X") True >>> check_win({"X": [1,
(player_pos: Dict[str, List[int]], cur_player: str)
| 46 | |
| 47 | |
| 48 | def check_win(player_pos: Dict[str, List[int]], cur_player: str) -> bool: |
| 49 | """ |
| 50 | Check if the current player has won. |
| 51 | |
| 52 | Args: |
| 53 | player_pos: Dict of player positions (X and O) |
| 54 | cur_player: Current player ("X" or "O") |
| 55 | |
| 56 | Returns: |
| 57 | True if player wins, False otherwise |
| 58 | |
| 59 | >>> check_win({"X": [1,2,3], "O": []}, "X") |
| 60 | True |
| 61 | >>> check_win({"X": [1,2], "O": []}, "X") |
| 62 | False |
| 63 | """ |
| 64 | soln = [ |
| 65 | [1, 2, 3], |
| 66 | [4, 5, 6], |
| 67 | [7, 8, 9], # Rows |
| 68 | [1, 4, 7], |
| 69 | [2, 5, 8], |
| 70 | [3, 6, 9], # Columns |
| 71 | [1, 5, 9], |
| 72 | [3, 5, 7], # Diagonals |
| 73 | ] |
| 74 | return any(all(pos in player_pos[cur_player] for pos in combo) for combo in soln) |
| 75 | |
| 76 | |
| 77 | def check_draw(player_pos: Dict[str, List[int]]) -> bool: |