Advertisement
aanodin

Untitled

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