MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / winning_move

Function winning_move

projects/Connect Four/main.py:38–81  ·  view source on GitHub ↗
(board, piece)

Source from the content-addressed store, hash-verified

36
37
38def winning_move(board, piece):
39 # Check horizontal locations for win
40 for c in range(COLUMN_COUNT - 3):
41 for r in range(ROW_COUNT):
42 if (
43 board[r][c] == piece
44 and board[r][c + 1] == piece
45 and board[r][c + 2] == piece
46 and board[r][c + 3] == piece
47 ):
48 return True
49
50 # Check vertical locations for win
51 for c in range(COLUMN_COUNT):
52 for r in range(ROW_COUNT - 3):
53 if (
54 board[r][c] == piece
55 and board[r + 1][c] == piece
56 and board[r + 2][c] == piece
57 and board[r + 3][c] == piece
58 ):
59 return True
60
61 # Check positively sloped diaganols
62 for c in range(COLUMN_COUNT - 3):
63 for r in range(ROW_COUNT - 3):
64 if (
65 board[r][c] == piece
66 and board[r + 1][c + 1] == piece
67 and board[r + 2][c + 2] == piece
68 and board[r + 3][c + 3] == piece
69 ):
70 return True
71
72 # Check negatively sloped diaganols
73 for c in range(COLUMN_COUNT - 3):
74 for r in range(3, ROW_COUNT):
75 if (
76 board[r][c] == piece
77 and board[r - 1][c + 1] == piece
78 and board[r - 2][c + 2] == piece
79 and board[r - 3][c + 3] == piece
80 ):
81 return True
82
83
84def draw_board(board):

Callers 1

main.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected