Python Forum
The game should now run and terminate once the board is full, but still can’t identif
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The game should now run and terminate once the board is full, but still can’t identif
#1
 
# 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
ther 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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Enabling interrupt on Adafruits button/led board Moris526 0 361 Apr-30-2021, 03:29 PM
Last Post: Moris526
  High-Precision Board Voltage Reading from Python into PD Liam484 1 435 Mar-29-2021, 02:57 PM
Last Post: Marbelous
  Interrupt for Adafruits Neotrellis button/led board Moris526 0 439 Dec-28-2020, 05:42 AM
Last Post: Moris526
  Is there a way to not terminate a running thread in python Contra_Boy 3 720 May-05-2020, 09:38 PM
Last Post: SheeppOSU
  Terminate a process when hotkey is pressed 66Gramms 0 818 Dec-24-2019, 06:41 PM
Last Post: 66Gramms
  How to terminate the caller fuction through callee? 100k 2 776 Nov-27-2019, 06:49 PM
Last Post: jefsummers
  How to terminate a list of inputs with a set value? SOS Manning 2 687 Sep-19-2019, 01:54 AM
Last Post: scidam
  [Help] A function that generates an n x n sized board? vanicci 5 2,286 Aug-14-2018, 02:26 PM
Last Post: vanicci
  how to terminate all the processes in C py2exe 0 1,137 Aug-02-2018, 04:31 AM
Last Post: py2exe
  lambda-Amazon EC2:Remove instance termination protection if enabled and terminate ins dragan979 0 1,999 Jun-13-2018, 09:48 AM
Last Post: dragan979

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020