I've been trying to figure out this problem for multiple hours and still no luck. I'm in the process of writing Connect4 in Python for a school assignment and I need a function that checks if the board is full.
Here is my init function
def __init__( self, width, height ):
self.width = width
self.height = height
self.data = [] # this will be the board
for row in range( self.height ):
boardRow = []
for col in range( self.width ):
boardRow += [' ']
self.data += [boardRow]
My repr function
def __repr__(self):
#print out rows & cols
s = '' # the string to return
for row in range( self.height ):
s += '|' # add the spacer character
for col in range( self.width ):
s += self.data[row][col] + '|'
s += '\n'
s += '--'*self.width + '-\n'
for col in range( self.width ):
s += ' ' + str(col % 10)
s += '\n'
return s
And what I have for my isFull function
def isFull(self):
# check if board is full
for row in range(0,(self.height-(self.height-1))):
for col in range(0,self.width):
if (' ') not in self.data[row][col]:
return True
I want to check and see if there this ' ' (a space) within the data list. At least I think that's my problem, I'm not experienced in python so I may be misreading my issue. If anyone has any ideas I'm glad to listen.
range(0,(self.height-(self.height-1)))? It is the same asrange(0,1)