aanodin

Untitled

Apr 21st, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.18 KB | None | 0 0
  1. wk, wt, bk = input().split()
  2.  
  3. verts = {'a':1, 'b':2, 'c':3, 'd':4, 'e':5, 'f':6, 'g':7, 'h':8}
  4.  
  5. wk_h = int(wk[1])
  6. wk_v = verts[wk[0]]
  7. wt_h = int(wt[1])
  8. wt_v = verts[wt[0]]
  9. bk_h = int(bk[1])
  10. bk_v = verts[bk[0]]
  11.  
  12.  
  13. def king_attacks(k_h, k_v, target_h, target_v):
  14.     return abs(k_h - target_h) <= 1 and abs(k_v - target_v) <= 1
  15.  
  16.  
  17. def tower_attacks(t_h, t_v, wk_h, wk_v, target_h, target_v):
  18.     # check horizontal
  19.     if t_h == target_h:
  20.         if wk_h != t_h or ((wk_v < t_v and target_v > t_v) or (wk_v > t_v and target_v < t_v)):
  21.             return True
  22.         else:
  23.             return False
  24.  
  25.     if t_v == target_v:
  26.         if wk_v != t_v or ((wk_h < t_h and target_h > t_h) or (wk_h > t_h and target_h < t_h)):
  27.             return True
  28.         else:
  29.             return False
  30.  
  31.     return False
  32.  
  33.  
  34. attacked = tower_attacks(wt_h, wt_v, wk_h, wk_v, bk_h, bk_v)
  35.  
  36.  
  37. def bk_can_move(bk_h, bk_v, wk_h, wk_v, t_h, t_v, target_h, target_v):
  38.     if target_h < 1 or target_v < 1:
  39.         return False
  40.  
  41.     if abs(target_h - bk_h) > 1 or abs(target_v - bk_v) > 1:
  42.         return False
  43.  
  44.     if king_attacks(wk_h, wk_v, target_h, target_v):
  45.         return False
  46.  
  47.     if tower_attacks(t_h, t_v, wk_h, wk_v, target_h, target_v):
  48.         return False
  49.  
  50.     return True
  51.  
  52.  
  53. #print(bk_can_move(bk_h, bk_v, wk_h, wk_v, wt_h, wt_v, 4, 3))
  54.  
  55. # черный король может сделать ход
  56. targets = [(bk_h - 1, bk_v - 1),
  57.            (bk_h - 1, bk_v),
  58.            (bk_h - 1, bk_v + 1),
  59.            (bk_h + 1, bk_v - 1),
  60.            (bk_h + 1, bk_v),
  61.            (bk_h + 1, bk_v + 1),
  62.            (bk_h, bk_v - 1),
  63.            #(bk_h, bk_v),
  64.            (bk_h, bk_v + 1)
  65.            ]
  66.  
  67. can_move = False
  68. for target_h, target_v in targets:
  69.     if bk_can_move(bk_h, bk_v, wk_h, wk_v, wt_h, wt_v, target_h, target_v):
  70.         can_move = True
  71.         break
  72.  
  73. if king_attacks(wk_h, wk_v, bk_h, bk_v):
  74.     print('Strange')
  75. else:
  76.     if can_move and not attacked:
  77.         print('Normal')
  78.  
  79.     if can_move and attacked:
  80.         print('Check')
  81.  
  82.     if not can_move and not attacked:
  83.         print('Stalemate')
  84.  
  85.     if not can_move and attacked:
  86.         print('Checkmate')
Add Comment
Please, Sign In to add comment