Jul-22-2021, 03:24 AM
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# 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 False |
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.