Knight and Bishop

We all know about the chess game. Chess game is played on 8x8 board. Now, Alice and Bob come to play…

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

@hjr265 @khatribiru Sorry but can you please provide some more sample sets? I am getting WA in test 2,or any hint/s where is the bug?

T=int(input())

for i in range(0,T):
    num=i+1
    moveinput=input()
    room1=moveinput[1]
    alphabet='abcdefgh'
    
    for j in range(len(alphabet)):
        if room1 == alphabet[j]:
            roomno1=int(j)
    numroom1=int(moveinput[2])
    if (numroom1+roomno1)%2==0:
        roomcolor1='white'
    if (numroom1+roomno1)%2!=0:
        roomcolor1='black'
    
    room2=moveinput[5]
    alphabet='abcdefgh'
    for j in range(len(alphabet)):
        if room2 == alphabet[j]:
            roomno2=int(j)
    numroom2=int(moveinput[6])
    if (numroom2+roomno2)%2==0:
        roomcolor2='white'
    if (numroom2+roomno2)%2!=0:
        roomcolor2='black'    
    
    if moveinput[0]=='B':                                                        #differentcolorbishop
        if moveinput[4]=='B':
            if roomcolor1!=roomcolor2:
                print("Case "+str(num)+": Draw")
            
            if roomcolor1==roomcolor2:                                           #samecolorbishop
                if abs(roomno1-roomno2)==abs(int(moveinput[2])-int(moveinput[6])):
                    print("Case "+str(num)+": Alice")
                    
                if abs(roomno1-roomno2)!=abs(int(moveinput[2])-int(moveinput[6])):
                    print("Case "+str(num)+": Draw")
                    
    if moveinput[0]=='K':                                                        #2knight
        if moveinput[4]=='K':
            if (roomno2 == roomno1 + 1 or roomno2 == roomno1 - 1) and (int(moveinput[6]) == int(moveinput[2]) - 2 or int(moveinput[6]) == int(moveinput[2]) + 2):
                print("Case "+str(num)+": Alice")
            elif (roomno2 == roomno1 - 2 or roomno2 == roomno1 + 2) and (int(moveinput[6]) == int(moveinput[2]) - 1 or int(moveinput[6]) == int(moveinput[2]) + 1):
                print("Case "+str(num)+": Alice")
            else:
                print("Case "+str(num)+": Draw")
    
    if moveinput[0]=='B':                                                        #knightbishop
        if moveinput[4]=='K':
            if abs(roomno1-roomno2)==abs(int(moveinput[2])-int(moveinput[6])):
                    print("Case "+str(num)+": Alice")
                    
            if abs(roomno2-roomno1)!=abs(int(moveinput[6])-int(moveinput[2])):
                    if (roomno1 == roomno2 + 1 or roomno1 == roomno2 - 1) and (int(moveinput[2]) == int(moveinput[6]) - 2 or int(moveinput[2]) == int(moveinput[6]) + 2):
                        print("Case "+str(num)+": Bob")
                    elif (roomno1 == roomno2 - 2 or roomno1 == roomno2 + 2) and (int(moveinput[2]) == int(moveinput[6]) - 1 or int(moveinput[2]) == int(moveinput[6]) + 1):
                        print("Case "+str(num)+": Bob")
                    else:
                        print("Case "+str(num)+": Draw")
                        
    if moveinput[0]=='K':                                                        #knightbishop
        if moveinput[4]=='B':
            if (roomno2 == roomno1 + 1 or roomno2 == roomno1 - 1) and (int(moveinput[6]) == int(moveinput[2]) - 2 or int(moveinput[6]) == int(moveinput[2]) + 2):
                print("Case "+str(num)+": Alice")
            elif (roomno2 == roomno1 - 2 or roomno2 == roomno1 + 2) and (int(moveinput[6]) == int(moveinput[2]) - 1 or int(moveinput[6]) == int(moveinput[2]) + 1):
                print("Case "+str(num)+": Alice")
            else:        
                if abs(roomno2-roomno1)==abs(int(moveinput[6])-int(moveinput[2])):
                    print("Case "+str(num)+": Bob")
                    
                if abs(roomno1-roomno2)!=abs(int(moveinput[2])-int(moveinput[6])):
                    print("Case "+str(num)+": Draw")