-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnight.py
More file actions
79 lines (68 loc) · 1.76 KB
/
Knight.py
File metadata and controls
79 lines (68 loc) · 1.76 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
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
#location has to be the index of the list board
def Knight(piece, location, board, active_indx):
#Define the two 'special' indices where the knight can be
left_invalid = range(0, 72, 9)
right_invalid = range(7, 79, 9)
#Define possible indices where the knight can move
a = location + (2 * 9) + 1
b = location + (2 * 9) - 1
c = location - (2 * 9) + 1
d = location - (2 * 9) - 1
e = location + 11
f = location - 7
g = location + 7
h = location - 11
if piece > 0:
if location in left_invalid:
new_indxs = [a, b, d, c, e, f]
elif location in right_invalid:
new_indxs = [b, d, g, h]
else:
new_indxs = [a, b, c, d, e, f, g, h]
#Check if new location is an active index
i = 0
for item in new_indxs:
if item not in active_indx:
new_indxs[i] = 'null'
i += 1
#Define which piece ID is in the new_indxs
piece_ID = []
for indx in new_indxs:
if indx == 'null':
piece_ID.append('null')
else:
piece_ID.append(board[indx])
this = []
j = 0
for unit in piece_ID:
if unit <= 0 and unit != 'null':
this.append(new_indxs[j])
j += 1
return this
elif piece < 0:
if location in left_invalid:
new_indxs = [a, b, d, c, e, f]
elif location in right_invalid:
new_indxs = [b, d, g, h]
else:
new_indxs = [a, b, c, d, e, f, g, h]
#Check if new location is an active index
i = 0
for item in new_indxs:
if item not in active_indx:
new_indxs[i] = 'null'
i += 1
#Define which piece ID is in the new_indxs
piece_ID = []
for indx in new_indxs:
if indx == 'null':
piece_ID.append('null')
else:
piece_ID.append(board[indx])
this = []
j = 0
for unit in piece_ID:
if unit >= 0 and unit != 'null':
this.append(new_indxs[j])
j += 1
return this