I am trying to do a chess game but i have problems and i couldn't find these problems. It is long and hard to read but i am a student and i don't know too much thing in python.
i have a file like that:
move p3 c4
move p4 d3
import sys
f=open(sys.argv[1],'r')
commands=[[line.split()] for line in f.readlines()]
length=len(commands)
counter=0
line8=['R1','N1','B1','QU','KI','B2','N2','R2']
line7=['P1','P2','P3','P4','P5','P6','P7','P8']
line6=[' ',' ',' ',' ',' ',' ',' ',' ']
line5=[' ',' ',' ',' ',' ',' ',' ',' ']
line4=[' ',' ',' ',' ',' ',' ',' ',' ']
line3=[' ',' ',' ',' ',' ',' ',' ',' ']
line2=['p1','p2','p3','p4','p5','p6','p7','p8']
line1=['r1','n1','b1','qu','ki','b2','n2','r2']
for i in range(0,length-1):
if commands[i][0][0]=='move':
#PAWNS
if commands[i][0][1] in['p1','p2','p3','p4','p5','p6','p7','p8']:
letterlist = ['','a','b','c','d','e','f','g','h']
pawnandnumber=list(commands[i][0][1])
moveandnumber = list((commands[i][0][2]))
#LINE BY LINE PAWN MOVES
if commands[i][0][1] in line2:
where_is_pawn=line2.index(commands[i][0][1])
if pawnandnumber[1]==str(letterlist.index(moveandnumber[0])) and (moveandnumber[1]=='3' or '4'):
print('>',end=' ')
print(commands[i][0])
print('OK')
if moveandnumber[1]=='3':
if line3[where_is_pawn] in ['R1','N1','B1','QU','KI','B2','N2','R2','P1','P2','P3','P4','P5','P6','P7','P8',' ']:
line3.pop(where_is_pawn)
line2.pop(where_is_pawn)
line2.insert(where_is_pawn,' ')
line3.insert(where_is_pawn, line2[where_is_pawn])
if moveandnumber[1]=='4':
if line4[where_is_pawn] in ['R1','N1','B1','QU','KI','B2','N2','R2','P1','P2','P3','P4','P5','P6','P7','P8',' ']:
line4.pop(where_is_pawn)
line2.pop(where_is_pawn)
line2.insert(where_is_pawn, ' ')
line4.insert(where_is_pawn, commands[i][0][1])
if commands[i][0][1] in line3:
if pawnandnumber[1]==str(letterlist.index(moveandnumber[0])):
where_is_pawn = line3.index(commands[i][0][1])
if line4[where_is_pawn] in ['R1','N1','B1','QU','KI','B2','N2','R2','P1','P2','P3','P4','P5','P6','P7','P8',' ']:
line4.pop(where_is_pawn)
line3.pop(where_is_pawn)
line3.insert(where_is_pawn, ' ')
line4.insert(where_is_pawn, commands[i][0][1])
if commands[i][0][1] in line4:
if pawnandnumber[1]==str(letterlist.index(moveandnumber[0])):
where_is_pawn = line4.index(commands[i][0][1])
if line5[where_is_pawn] in ['R1','N1','B1','QU','KI','B2','N2','R2','P1','P2','P3','P4','P5','P6','P7','P8',' ']:
line5.pop(where_is_pawn)
line4.pop(where_is_pawn)
line4.insert(where_is_pawn,' ')
line5.insert(where_is_pawn, commands[i][0][1])
if commands[i][0][1] in line5:
if pawnandnumber[1]==str(letterlist.index(moveandnumber[0])):
where_is_pawn = line5.index(commands[i][0][1])
if line6[where_is_pawn] in ['R1','N1','B1','QU','KI','B2','N2','R2','P1','P2','P3','P4','P5','P6','P7','P8',' ']:
line6.pop(where_is_pawn)
line5.pop(where_is_pawn)
line5.insert(where_is_pawn, ' ')
line6.insert(where_is_pawn, commands[i][0][1])
if commands[i][0][1] in line6:
if pawnandnumber[1]==str(letterlist.index(moveandnumber[0])):
where_is_pawn = line6.index(commands[i][0][1])
if line7[where_is_pawn] in ['R1','N1','B1','QU','KI','B2','N2','R2','P1','P2','P3','P4','P5','P6','P7','P8',' ']:
line7.pop(where_is_pawn)
line6.pop(where_is_pawn)
line6.insert(where_is_pawn, ' ')
line7.insert(where_is_pawn, commands[i][0][1])
if commands[i][0][1] in line7:
if pawnandnumber[1]==str(letterlist.index(moveandnumber[0])):
where_is_pawn = line7.index(commands[i][0][1])
if line8[where_is_pawn] in ['R1','N1','B1','QU','KI','B2','N2','R2','P1','P2','P3','P4','P5','P6','P7','P8',' ']:
line8.pop(where_is_pawn)
line7.pop(where_is_pawn)
line7.insert(where_is_pawn, ' ')
line8.insert(where_is_pawn, commands[i][0][1])
print(line8)
print(line7)
print(line6)
print(line5)
print(line4)
print(line3)
print(line2)
print(line1)
i have an output like that:
> ['move', 'p3', 'c3']
OK
['R1', 'N1', 'p3', 'QU', 'KI', 'B2', 'N2', 'R2']
['P1', 'P2', ' ', 'P4', 'P5', 'P6', 'P7', 'P8']
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
['p1', 'p2', ' ', 'p4', 'p5', 'p6', 'p7', 'p8']
['r1', 'n1', 'b1', 'qu', 'ki', 'b2', 'n2', 'r2']
p3 should be in 2 upper line and p4 should be 1 upper line what can i do? Or if you think my method is wrong is there an easy way to do it? I am designing a chess game the rows are a,b,c... the lines are 1,2,3... i have an input that contains some commands like 'move' i need to read line by line and print them. Thanks in advance.