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: 3827022 • 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 II
# Drops a piece in the board into the desired column number.
# If player is 1, drop an 'X'. If player is 2, drop an 'O'. (letter Oh).
# Returns the number of the row that the piece landed in (where the bottommost row is row #1).
# If the game piece can be dropped, return the row number where the piece landed, otherwise return -1.
# Note that col_num is given as a value in the range 1 through board._num_cols, NOT 0 through board._num_cols-1.
def drop_piece(board, col_num, player):
if col_num < 1 or col_num > board._num_cols:
return -1
  
# when a piece is dropped from top, it will land at the bottom most row with a free cell in
# the given column, so checking start from bottom most row
for i in range(0, board._num_rows):
if board._slots[i][col_num-1] == '.':
if player == 1:
board._slots[i][col_num-1] = 'X'
else:
board._slots[i][col_num-1] = 'O'
return i+1
  
# if column is completely filled already
return -1

# Code link: https://pastebin.com/HJPU7t0t

Please rate positively.

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