-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_is_whatching.py
More file actions
42 lines (38 loc) · 1.92 KB
/
check_is_whatching.py
File metadata and controls
42 lines (38 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from pieces_logic import check_vertical_and_horizontal, check_diagonal, knight, get_enemy_color
def is_watching(coordinate, color, board, youre_color): # coordinate = {x,y}
global check_vertical_and_horizontal, check_diagonal
piece_color = get_enemy_color(color)
knight_posible_ways = knight(
coordinate["x"], coordinate["y"], color, board)
for posible_way in knight_posible_ways:
if "square-" + str(posible_way["x"]) + str(posible_way["y"]) in board[piece_color]:
if board[piece_color]["square-" + str(posible_way["x"]) + str(posible_way["y"])] == "n":
return True
horizontal_ways = check_vertical_and_horizontal(
coordinate["x"], coordinate["y"], color, board)
for horizontal_way in horizontal_ways:
if "square-" + str(horizontal_way["x"]) + str(horizontal_way["y"]) in board[piece_color]:
piece = board[piece_color]["square-" +
str(horizontal_way["x"]) + str(horizontal_way["y"])]
if piece == "r" or piece == "q":
return True
diagonal_ways = check_diagonal(
coordinate["x"], coordinate["y"], color, board)
for diagonal_way in diagonal_ways:
if "square-" + str(diagonal_way["x"]) + str(diagonal_way["y"]) in board[piece_color]:
piece = board[piece_color]["square-" +
str(diagonal_way["x"]) + str(diagonal_way["y"])]
if piece == "b" or piece == "q":
return True
if piece == "p":
if youre_color == "white":
a = -1
else:
a = 1
if piece_color == "white":
if coordinate["y"] + a == diagonal_way["y"]:
return True
else:
if coordinate["y"] - a == diagonal_way["y"]:
return True
return False