Jul-22-2021, 03:24 AM
# DO NOT EDIT THE FOLLOWING LINES
# COURSE CPSC 231 SPRING 2021
# INSTRUCTOR: Jonathan Hudson
# RNkY9dhladt8yUgc1WHi
# DO NOT EDIT THE ABOVE LINES
#INFORMATION FOR YOUR TA
# Constants for piece types
EMPTY = 0
X = 1
O = 2
# Insert your implementation of createBoard here (code and comments (in-line and function))
#
def createBoard(rows = 3, cols = 3):
board = []
for x in range(0, rows):
board.append([])
for y in range(0, cols):
board[x].append(0)
return board
def rowsIn(board):
numOfRows = len(board)
return numOfRows
def colsIn(board):
numOfColumns = len(board[0])
return numOfColumns
# Insert your implementation of canPlay here (code and comments (in-line and function))
def canPlay(board,rows ,cols):
if board[rows][cols] == 0:
return True
else:
return False
def play (board, rows, cols, piece):
board[rows][cols] = piece
# Replace this with your implementation of full here (code and comments (in-line and function
def full(board):
for rows in range(rowsIn(board)):
for cols in range(colsIn(board)):
if board[rows][cols] == EMPTY:
return False
return True
# Insert your implementations of winInRow, winInCol, winInDiag here (code and comments (in-line and function))
def winInRow(board, row ,piece):
for rows in range(rowsIn(board)):
for cols in range(colsIn(board)):
if board[rows][cols] == piece:
if board[rows][cols+1] == piece:
if board[rows][cols+2] == piece:
return True
return False
# Replace this with your implementation of won here (code and comments (in-line and function))
#
def won(board, piece):
return False
#
# Replace this with your implementation of hint here (code and comments (in-line and function))
#
def hint(board, piece):
return -1, -1
def gameover(board):
"""
This function determines if the game is complete due to a win or tie by either player
:param board: The 2D list board to check
:return: True if game is complete, False otherwise
"""
if full(board) or won(board, X) or won(board, O):
return True
return Falsether error i get is The board was:
[[1, 1, 1], [0, 0, 0], [0, 0, 0]]
FAILED: For row = 1 piece = 1
FAILED: The value returned was True when True was expected.
FAILED: winInRow should say True to winInRow but for 0 and not 1.
