MCPcopy Create free account
hub / github.com/geekcomputers/Python / is_winner

Function is_winner

Tic-Tac-Toe Games/tic-tac-toe5.py:73–91  ·  view source on GitHub ↗

Return True if the given letter has won the game. >>> is_winner([' ', 'X','X','X',' ',' ',' ',' ',' ',' '], 'X') True >>> is_winner([' ']*10, 'O') False

(board: List[str], le: str)

Source from the content-addressed store, hash-verified

71
72
73def is_winner(board: List[str], le: str) -> bool:
74 """
75 Return True if the given letter has won the game.
76
77 >>> is_winner([' ', 'X','X','X',' ',' ',' ',' ',' ',' '], 'X')
78 True
79 >>> is_winner([' ']*10, 'O')
80 False
81 """
82 return (
83 (board[7] == le and board[8] == le and board[9] == le)
84 or (board[4] == le and board[5] == le and board[6] == le)
85 or (board[1] == le and board[2] == le and board[3] == le)
86 or (board[7] == le and board[4] == le and board[1] == le)
87 or (board[8] == le and board[5] == le and board[2] == le)
88 or (board[9] == le and board[6] == le and board[3] == le)
89 or (board[7] == le and board[5] == le and board[3] == le)
90 or (board[9] == le and board[5] == le and board[1] == le)
91 )
92
93
94def get_board_copy(board: List[str]) -> List[str]:

Callers 2

get_computer_moveFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected