Untitled
unknown
python
a year ago
1.0 kB
9
Indexable
def has_won(board, column): directions = [(0, 1), (1, 0), (1, 1), (1, -1)] def in_bound(row, col): return 0 <= row < len(board) and 0 <= col < len(board[0]) def check_win(direction, r, c, symbol): count = 1 dr, dc = direction r_pos, c_pos = r + dr, c + dc while in_bound(r_pos, c_pos) and board[r_pos][c_pos] == symbol: count += 1 r_pos, c_pos = r_pos + dr, c_pos + dc r_neg, c_neg = r - dr, c - dc while in_bound(r_neg, c_neg) and board[r_neg][c_neg] == symbol: count += 1 r_neg, c_neg = r_neg - dr, c_neg - dc return count >= 4 row_top = 0 while row_top < len(board) and board[row_top][column] == '.': row_top += 1 row_top -= 1 if row_top < 0: return False for direction in directions: if check_win(direction, row_top, column, board[row_top][column]): return True return False
Editor is loading...