Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. def proverka(cell):
  2.     if 1 <= cell[0] <= 8 and 1 <= cell[1] <= 8:
  3.         return True
  4.     return False
  5.  
  6.  
  7. def obrabotka1(cell):
  8.     letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
  9.     x, y = list(cell)
  10.     for i in range(8):
  11.         if x == letters[i]:
  12.             return i + 1, int(y)
  13.  
  14.  
  15. def obrabotka2(cell):
  16.     letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
  17.     return letters[cell[0] - 1] + str(cell[1])
  18.  
  19.  
  20. def possibleTurns(cell):
  21.     cell = obrabotka1(cell)
  22.     turns = []
  23.     if proverka((cell[0] - 1, cell[1] - 2)):
  24.         turns.append(obrabotka2((cell[0] - 1, cell[1] - 2)))
  25.     if proverka((cell[0] + 1, cell[1] + 2)):
  26.         turns.append(obrabotka2((cell[0] + 1, cell[1] + 2)))
  27.     if proverka((cell[0] - 1, cell[1] + 2)):
  28.         turns.append(obrabotka2((cell[0] - 1, cell[1] + 2)))
  29.     if proverka((cell[0] + 1, cell[1] - 2)):
  30.         turns.append(obrabotka2((cell[0] + 1, cell[1] - 2)))
  31.     if proverka((cell[0] - 2, cell[1] - 1)):
  32.         turns.append(obrabotka2((cell[0] - 2, cell[1] - 1)))
  33.     if proverka((cell[0] + 2, cell[1] + 1)):
  34.         turns.append(obrabotka2((cell[0] + 2, cell[1] + 1)))
  35.     if proverka((cell[0] - 2, cell[1] + 1)):
  36.         turns.append(obrabotka2((cell[0] - 2, cell[1] + 1)))
  37.     if proverka((cell[0] + 2, cell[1] - 1)):
  38.         turns.append(obrabotka2((cell[0] + 2, cell[1] - 1)))
  39.     return sorted(turns)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement