nnikif

Untitled

Mar 11th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. def convertChesstoDigit(placeCh):
  2.     digCh=[]
  3.     digCh.append(1+ord(placeCh[0])-ord('a'))
  4.     digCh.append(int(placeCh[1]))
  5.     return digCh
  6.  
  7. def bishopCovers(n1,n2):
  8.     coveredByB=[]
  9.     for i in range(-8,9):
  10.         b1=n1+i
  11.         b2=n2+i
  12.         c1=n1+i
  13.         c2=n2-i
  14.         if 1<=b1 and b1<=8 and 1<=b2 and b2<=8:
  15.             coveredByB.append([b1,b2])
  16.         if 1<=c1 and c2<=8 and 1<=c2 and c2<=8:
  17.             coveredByB.append([c1,c2])
  18.     return coveredByB
  19.  
  20.  
  21. def bishopAndPawn(bishop, pawn):
  22.     bish1,bish2=convertChesstoDigit(bishop)
  23.     pawn1,pawn2=convertChesstoDigit(pawn)
  24.     if [pawn1,pawn2] in bishopCovers(bish1,bish2):
  25.         return True
  26.     else:
  27.         return False
Advertisement
Add Comment
Please, Sign In to add comment