Advertisement
aanodin

Untitled

Apr 21st, 2020
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.80 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. tower_is_near = (abs(bk_h - wt_h) == 1 and abs(bk_v - wt_v) == 1)
  43. # король может съесть ладью, если стоит рядом с ней, и ее не защищает (атакует) свой король
  44. can_eat_tower = tower_is_near and not king_attacks(wk_h, wk_v, wt_h, wt_v)
  45.  
  46.  
  47. def bk_can_move(bk_h, bk_v, wk_h, wk_v, t_h, t_v, target_h, target_v):
  48.     if target_h < 1 or target_v < 1:
  49.         return False
  50.  
  51.     if abs(target_h - bk_h) > 1 or abs(target_v - bk_v) > 1:
  52.         return False
  53.  
  54.     if king_attacks(wk_h, wk_v, target_h, target_v):
  55.         return False
  56.  
  57.     if tower_attacks(t_h, t_v, wk_h, wk_v, target_h, target_v):
  58.         return False
  59.  
  60.     #if tower_is_near and not can_eat_tower:
  61.     #    return False
  62.  
  63.     return True
  64.  
  65.  
  66. #print(bk_can_move(bk_h, bk_v, wk_h, wk_v, wt_h, wt_v, 4, 1))
  67.  
  68. # черный король может сделать ход
  69. targets = [(bk_h - 1, bk_v - 1),
  70.            (bk_h - 1, bk_v),
  71.            (bk_h - 1, bk_v + 1),
  72.            (bk_h + 1, bk_v - 1),
  73.            (bk_h + 1, bk_v),
  74.            (bk_h + 1, bk_v + 1),
  75.            (bk_h, bk_v - 1),
  76.            #(bk_h, bk_v),
  77.            (bk_h, bk_v + 1)
  78.            ]
  79.  
  80. can_move = False
  81. for target_h, target_v in targets:
  82.     if bk_can_move(bk_h, bk_v, wk_h, wk_v, wt_h, wt_v, target_h, target_v):
  83.         can_move = True
  84.         break
  85.  
  86. if can_move is False:
  87.     can_move = can_eat_tower
  88.  
  89. if king_attacks(wk_h, wk_v, bk_h, bk_v):
  90.     print('Strange')
  91. else:
  92.     if can_move and not attacked:
  93.         print('Normal')
  94.  
  95.     if can_move and attacked:
  96.         print('Check')
  97.  
  98.     if not can_move and not attacked:
  99.         print('Stalemate')
  100.  
  101.     if not can_move and attacked:
  102.         print('Checkmate')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement