PLEASE CODE IN PYTHON Part IV: vertical winner(board) This function scans the en
ID: 3830130 • Letter: P
Question
PLEASE CODE IN PYTHON
Part IV: vertical winner(board)
This function scans the entire game board passed as an argument and returns one of three values:
• 1 if player 1 has placed four consecutive X’s in a single column somewhere in the board
• 2 if player 2 has placed four consecutive O’s in a single column somewhere in the board
• 0 (zero) if neither player has placed four consecutive pieces in a single column somewhere in the board
Under no circumstances is the function permitted to make a change to board.
PROVIDED BELOW IS THE BOARD CLASS
Explanation / Answer
# PART IV
# Determines if a player has won the game by putting four pieces on top of each other in a single column.
# Returns 1 if player 1 has won the game by placing four X's contiguously in a single column.
# Returns 2 if player 2 has won the game by placing four O's contiguously in a single column.
# Returns 0 if no one has won yet by placing pieces in this manner.
# This function must not modify the contents of the game board.
def vertical_winner(board):
for j in range(0, board._num_cols):
count1 = 0
count2 = 0
for i in range(0, board._num_rows):
if board._slots[i][j] == 'X':
count1 += 1
count2 = 0
elif board._slots[i][j] == 'O':
count2 += 1
count1 = 0
if count1 == 4 and count2 == 0:
return 1
elif count2 == 4 and count1 == 0:
return 2
return 0
# code link: https://pastebin.com/x9URT3fp
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.