-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathknight.py
58 lines (55 loc) · 1.7 KB
/
knight.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
import piece
class Knight(piece.Piece):
def __init__(self,position,team,game):
self.type = 'knight'
piece.Piece.__init__(self,position = position,team = team,game = game)
def allpos(self):
P=[]
try:
P.append(self.position._get_up()._get_up()._get_right())
except AssertionError :
pass
try:
P.append(self.position._get_up()._get_up()._get_left())
except AssertionError :
pass
try:
P.append(self.position._get_right()._get_right()._get_up())
except AssertionError :
pass
try:
P.append(self.position._get_right()._get_right()._get_down())
except AssertionError :
pass
try:
P.append(self.position._get_left()._get_left()._get_up())
except AssertionError :
pass
try:
P.append(self.position._get_left()._get_left()._get_down())
except AssertionError :
pass
try:
P.append(self.position._get_down()._get_down()._get_right())
except AssertionError :
pass
try:
P.append(self.position._get_down()._get_down()._get_left())
except AssertionError :
pass
return P
def possible_moves(self):
P = self.allpos()
L = []
for p in P:
if p._get_piece() == None:
L.append(p.position)
return L
def possible_attacks(self):
P = self.allpos()
L = []
for p in P:
if p._get_piece() != None:
if p._get_piece().team!=self.team:
L.append(p.position)
return L