I'm new to python and am trying to modify a single value in a list of lists. I come from java experience. I am writing code for a chess application to familiarize myself with python. board is a list of lists that contains all the pieces that exist on the board.
def updateMoves(self):
for i in range(self.getY()+1,col,1):
if board[self.getX()][i] != None:
self.canMove[self.getX()][i]=False
break;
else:
self.canMove[self.getX()][i]=True
def printMoves(self):
s=""
for i in range(row):
for k in range(col):
if self.canMove[i][k]==True:
s=s+"T,"
else:
s=s+"x,"
print(s)
s=""
GetY and X return a value stored on the piece of it's current position on the board(in this case the piece is in 2,2). The values in my list are started out as all false this code results in the canMove list(local to the class) looking like this: (x is false)
x,x,x,T,T,T,T,T,
x,x,x,T,T,T,T,T,
x,x,x,T,T,T,T,T,
x,x,x,T,T,T,T,T,
x,x,x,T,T,T,T,T,
x,x,x,T,T,T,T,T,
x,x,x,T,T,T,T,T,
x,x,x,T,T,T,T,T,
I decided to put breakpoints in, and on each loop of the array it changes the entire column to True. Any idea why this might be? I'm assuming its a syntax issue, but can't find anything in my google searches.