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
  Trying to make a board with turtle, nothing happens when running script Quascia 3 608 Nov-01-2023, 03:11 PM
Last Post: deanhystad
Photo HOW FIX MY BOARD GAME LAZABI 3 1,435 Apr-01-2022, 04:23 PM
Last Post: BashBedlam
  Enabling interrupt on Adafruits button/led board Moris526 0 1,987 Apr-30-2021, 03:29 PM
Last Post: Moris526
  High-Precision Board Voltage Reading from Python into PD Liam484 1 2,047 Mar-29-2021, 02:57 PM
Last Post: Marbelous
  Interrupt for Adafruits Neotrellis button/led board Moris526 0 1,769 Dec-28-2020, 05:42 AM
Last Post: Moris526
  Is there a way to not terminate a running thread in python Contra_Boy 3 1,933 May-05-2020, 09:38 PM
Last Post: SheeppOSU
  Terminate a process when hotkey is pressed 66Gramms 0 2,210 Dec-24-2019, 06:41 PM
Last Post: 66Gramms
  How to terminate the caller fuction through callee? 100k 2 2,101 Nov-27-2019, 06:49 PM
Last Post: jefsummers
  How to terminate a list of inputs with a set value? SOS Manning 2 2,142 Sep-19-2019, 01:54 AM
Last Post: scidam
  [Help] A function that generates an n x n sized board? vanicci 5 4,692 Aug-14-2018, 02:26 PM
Last Post: vanicci

Forum Jump:

User Panel Messages

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