My code consists of 2 chess knight coordinates (x1,y1) for knight1 and (x2,y2) for knight2. I want to know if knight1 can eat knight2 in his next move.
I made multiple if statement (I'm assuming thats not the most efficient way but I'm still a novice) One of my statements returns true for my second if statement.
My intputs go in first.
x1 = int(input('Input x value of knight1: \n'))
y1 = int(input('Input y value of knight1: \n'))
x2 = int(input('Input x2 value of knight2: \n'))
y2 = int(input('Input y2 value of knight2: \n'))
Then here are my if statements. I've set them up for these coordinates:
(x1-1,y1+2) (x1-1,y1-2)
(x1-2,y1+1) (x1-2,y1-1)
(x1+1,y1+2) (x1+1,y1-2)
(x1+2,y1+1) (x1+2,y1-1)
if (x1-1 == x2 and y1+2) or (x1-1 == x2 and y1-2):
print('Yes1')
elif (x1-2 == x2) and (y1+1 or y1-1):
print('Yes2')
elif (x1+1 == x2) and (y1+2 or y1-2):
print('Yes3')
elif (x1+2 == x2) and (y1+1 or y1-1):
print('Yes4')
else:
print('No')
For example when I input (3,3) as my knight1 position.. If I input (1,5) It should return 'No' but instead it returns 'Yes2' I understand that the x1-2 does in fact = x2 but I have an 'and' operator meaning the next comparator also should be taken into consideration?
Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire