is anyone able to decipher this code and help explain how the code allows the knight to move across the board it would be appreciated. i don't really have any idea as to why these specific numbers so if you could also explain that, it would be appreciated.
# Notes - variables:
# chosen is the current position of the piece
# moves is a list of where the chosen piece can move
# taken_pieces is a list of where the chosen piece can capture
# board is a list of every space on the board and says what piece exists there
# turn is a number either 1 or 2 representing whose turn it is
turn = 1
wcastle = 0
bcastle = 0
chosen = None
moves = []
taken_pieces = []
wtake_piece = []
btake_piece = []
board = [None for i in range(64)]
def attacked_spaces(player,board):
attacked = []
# Knight for both players
if board[i][0] == 'N' and board[i][1] == str(player):
x,y = i%8,i//8
if x >= 2 and y <= 6:
attacked.append((x-2)+(y+1)*8)
if x >= 1 and y <= 5:
attacked.append((x-1)+(y+2)*8)
if x <= 6 and y <= 5:
attacked.append((x+1)+(y+2)*8)
if x <= 5 and y <= 6:
attacked.append((x+2)+(y+1)*8)
if x <= 5 and y >= 1:
attacked.append((x+2)+(y-1)*8)
if x <= 6 and y >= 2:
attacked.append((x+1)+(y-2)*8)
if x >= 1 and y >= 2:
attacked.append((x-1)+(y-2)*8)
if x >= 2 and y >= 1:
attacked.append((x-2)+(y-1)*8)
if board[i][0] == 'K' and board[i][1] == str(player):
x,y = i%8,i//8
if x >= 1 and y <= 6:
attacked.append((x-1)+(y+1)*8)
if y <= 6:
attacked.append(x+(y+1)*8)
if x <= 6 and y <= 6:
attacked.append((x+1)+(y+1)*8)
if x <= 6:
attacked.append((x+1)+y*8)
if x <= 6 and y >= 1:
attacked.append((x+1)+(y-1)*8)
if y >= 1:
attacked.append(x+(y-1)*8)
if x >= 1 and y >= 1:
attacked.append((x-1)+(y-1)*8)
if x >= 1:
attacked.append((x-1)+y*8)
return attacked