-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rook.py
110 lines (99 loc) · 2.08 KB
/
Rook.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
#location has to be the index of the list board
def Rook(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
if piece > 0:
i = 1
while True:
UP_loc = location - i * 9
if board[UP_loc] > 0 or UP_loc not in active_indx:
break
elif board[UP_loc] < 0:
UP.append(UP_loc)
break
UP.append(UP_loc)
i += 1
j = 1
while True:
DN_loc = location + j * 9
if board[DN_loc] > 0 or DN_loc not in active_indx:
break
elif board[DN_loc] < 0:
DN.append(DN_loc)
break
DN.append(DN_loc)
j += 1
k = 1
while True:
RT_loc = location + k * 1
if board[RT_loc] > 0 or RT_loc not in active_indx:
break
elif board[RT_loc] < 0:
RT.append(RT_loc)
break
RT.append(RT_loc)
k += 1
l= 1
while True:
LT_loc = location - l * 1
if board[LT_loc] > 0 or LT_loc not in active_indx:
break
elif board[LT_loc] < 0:
LT.append(LT_loc)
break
LT.append(LT_loc)
l += 1
this.extend(UP)
this.extend(DN)
this.extend(RT)
this.extend(LT)
return this
elif piece < 0:
i = 1
while True:
UP_loc = location - i * 9
if board[UP_loc] < 0 or UP_loc not in active_indx:
break
elif board[UP_loc] > 0:
UP.append(UP_loc)
break
UP.append(UP_loc)
i += 1
j = 1
while True:
DN_loc = location + j * 9
if board[DN_loc] < 0 or DN_loc not in active_indx:
break
elif board[DN_loc] > 0:
DN.append(DN_loc)
break
DN.append(DN_loc)
j += 1
k = 1
while True:
RT_loc = location + k * 1
if board[RT_loc] < 0 or RT_loc not in active_indx:
break
elif board[RT_loc] > 0:
RT.append(RT_loc)
break
RT.append(RT_loc)
k += 1
l= 1
while True:
LT_loc = location - l * 1
if board[LT_loc] < 0 or LT_loc not in active_indx:
break
elif board[LT_loc] > 0:
LT.append(LT_loc)
break
LT.append(LT_loc)
l += 1
this.extend(UP)
this.extend(DN)
this.extend(RT)
this.extend(LT)
return this