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