-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queen.py
117 lines (106 loc) · 2.42 KB
/
Queen.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#location has to be the index of the list board
def Queen(piece, location, board, active_indx):
this = [] #All possible places that can be moved to
UP = [] #Movement UP
DN = [] #Movement DOWN
LT = [] #Movement LEFT
RT = [] #Movement RIGHT
S_E = [] #Movement DOWN + RIGHT
N_E = [] #Movement UP + RIGHT
S_W = [] #Movement DOWN + LEFT
N_W = [] #Movement UP + LEFT
if piece > 0:
IDs1 = range(1,7)
IDs2 = range(-6,0)
elif piece < 0:
IDs1 = range(-6,0)
IDs2 = range(1,7)
i = 1 #UP movement
while True:
UP_loc = location - i * 9
if board[UP_loc] in IDs1 or UP_loc not in active_indx:
break
elif board[UP_loc] in IDs2:
UP.append(UP_loc)
break
UP.append(UP_loc)
i += 1
j = 1 #DN movement
while True:
DN_loc = location + j * 9
if board[DN_loc] in IDs1 or DN_loc not in active_indx:
break
elif board[DN_loc] in IDs2:
DN.append(DN_loc)
break
DN.append(DN_loc)
j += 1
k = 1 #Right movement
while True:
RT_loc = location + k * 1
if board[RT_loc] in IDs1 or RT_loc not in active_indx:
break
elif board[RT_loc] in IDs2:
RT.append(RT_loc)
break
RT.append(RT_loc)
k += 1
l= 1 #Left movement
while True:
LT_loc = location - l * 1
if board[LT_loc] in IDs1 or LT_loc not in active_indx:
break
elif board[LT_loc] in IDs2:
LT.append(LT_loc)
break
LT.append(LT_loc)
l += 1
m = 1 #RIGHT + DOWN movement
while True:
SE_loc = location + m * 10
if board[SE_loc] in IDs1 or SE_loc not in active_indx:
break
elif board[SE_loc] in IDs2:
S_E.append(SE_loc)
break
S_E.append(SE_loc)
m += 1
n = 1 #UP + LEFT movement
while True:
NW_loc = location - n * 10
if board[NW_loc] in IDs1 or NW_loc not in active_indx:
break
elif board[NW_loc] in IDs2:
N_W.append(NW_loc)
break
N_W.append(NW_loc)
n += 1
o = 1 #UP + RIGHT movement
while True:
NE_loc = location - o * 8
if board[NE_loc] in IDs1 or NE_loc not in active_indx:
break
elif board[NE_loc] in IDs2:
N_E.append(NE_loc)
break
N_E.append(NE_loc)
o += 1
p = 1 #DOWN + LEFT movement
while True:
SW_loc = location + p * 8
if board[SW_loc] in IDs1 or SW_loc not in active_indx:
break
elif board[SW_loc] in IDs2:
S_W.append(SW_loc)
break
S_W.append(SW_loc)
p += 1
this.extend(UP)
this.extend(DN)
this.extend(RT)
this.extend(LT)
this.extend(S_E)
this.extend(N_E)
this.extend(S_W)
this.extend(N_W)
return this