Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment overview For the final homework assignment you will implement a varia

ID: 3827031 • Letter: A

Question

Assignment overview For the final homework assignment you will implement a variant of the game Connect Four on game boards of arbitrary dimensions (The classic game is played on a 6-row. by-7-column board.) Some basic code has been provided to you which depends on seven functions, six of which you will write for this assignment. The first thing to do is to download homework4.py from Piazza Resources and fill in your information at the top of the file. Inside the file you will find the Board class, which represents the game board, and also a function display-board that has been written for you. Let's explore the Board class a little: class Board: de f init (self num rows, num cols) self num rows num rows self. num cols num cols self slots for i in range (0, num rows) self slots .append for j in range (0, num cols) self. slots (-1) append The game board itself is represented using a list of lists of characters. Each position in the board is called a "slot" and holds either a period, capital letter X, or capital letter O: a represents an empty slot in the board an 'X' represents a piece for player 1. and an o' represents a piece for player 2. The board has at least 4 rows and 4 columns. The piece in -slots to] [01 is in the lower-left comer of the board, whereas the piece in slots [-num-rows-11 [-num-cols-11 is in the upper-right corner of the board:

Explanation / Answer

# PART V
# Determines if a player has won the game by placing four pieces in a diagonal.
# Returns 1 if player 1 has won the game by placing four X's diagonally.
# Returns 2 if player 2 has won the game by placing four O's diagonally.
# 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 diagonal_winner(board):
for i in range(3, board._num_rows):
count1 = 0
count2 = 0
for j in range(0, i+1):
if i == j and board._slots[j][j] == 'X':
count1 += 1
count2 = 0
elif i == j and board._slots[j][j] == 'O':
count2 += 1
count1 = 0
if count1 == 4 and count2 == 0:
return 1
elif count2 == 4 and count1 == 0:
return 2
  
n = board._num_rows
for i in range(3, board._num_rows):
count1 = 0
count2 = 0
for j in range(0, i+1):
if (n-i-1) == j and board._slots[j][j] == 'X':
count1 += 1
count2 = 0
elif (n-1-1) == j and board._slots[j][j] == 'O':
count2 += 1
count1 = 0
if count1 == 4 and count2 == 0:
return 1
elif count2 == 4 and count1 == 0:
return 2
return 0

# pastebin link for code: https://pastebin.com/1PfnjKTD

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote