Question: Hi, I need help with Python (3.4) Programming to make Connect 4 Game. class Board: def __init__(self, num_rows, num_cols): self._num_rows = num_rows self._num_cols = num_cols
Hi, I need help with Python (3.4) Programming to make "Connect 4" Game.
class Board: def __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('.')

For this, I have :
def board_full(board): for i in range(board._num_cols): if board._slots[board._num_rows - 1][i] == '.': return False return True
Secondly,

For this, I have:
def drop_piece(board, col_num, player): piece = '.' if player == 1: piece = 'X' elif player == 2: piece = 'O' else: return -1 if col_num or col_num > board._num_cols: return -1 if board._slots[board._num_rows - 1][col_num] != '.': return -1 for i in range(board._num_rows): if board._slots[i][col_num] == '.': board._slots[i][col_num] = piece return i + 1
I think I have errors in one of these codes, please help me with it.
This function scans the entire board passed in as an argument and returns True if the board is entirely filled with pieces, or False if there are still empty slots For example, the following board would result in a return value of True for board-full (board)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
