Here's a method I have in a larger project (Python 3.8):
def generateTree(board, depth): #turns position into all of it's further branches
branches = []
for i in range(64):
for j in range(64):
if detLegality(board, i, j) == 'Legal':#finding a legal mov
newPos = board
newPos[j] = newPos[i]
newPos[i] = ' '
branches.append(newPos)
return branches
The board
parameter is not supposed to change inside the function, and I couldn't figure out why it was. After some debugging, I figured out it was changing during the two lines:
newPos[j] = newPos[i]
newPos[i] = ' '
How could a variable(board
) change in a line that doesn't call it? I'm not an experienced coder, so what's going on here? Thanks.