-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpiece.py
More file actions
100 lines (85 loc) · 2.57 KB
/
Copy pathpiece.py
File metadata and controls
100 lines (85 loc) · 2.57 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
class Piece:
def __init__(self, color,name):
self.color = color
self.name = name
def is_move_valid(self, origine,destination):
print("This piece has no move, please report")
def is_ennemy(self,destination):
if Game.at(destination) != self.color:
return True
else:
return False
def is_ally(self,destination):
if Game.at(destination) == self.color:
return True
else:
return False
class King(Piece):
def is_move_valid(self, origine, destination):
oc, ol = origine
dc, dl = destination
if origine == destination:
return False
for i in range(-1, 1):
for j in range(-1, 1):
if (oc+i, ol+j)==(dc, dl):
return True
return False
class Queen(Piece):
def is_move_valid(self, origine, destination):
oc, ol = origine
dc, dl = destination
if origine == destination:
return False
if oc-dc == ol-dl: # is Diagonal
return True
if oc == dc or ol == dl: # Same Line or col
return True
else:
return False
class Rook(Piece):
def is_move_valid(self, origine, destination):
oc, ol = origine
dc, dl = destination
if origine == destination:
return False
if oc == dc or ol == dl: # Same line or col
return True
else:
return False
class Bishop(Piece):
def is_move_valid(self, origine, destination):
oc, ol = origine
dc, dl = destination
if origine == destination:
return False
if(oc-dc)==(ol-dl): # Same diag
return True
else:
return False
class Knight(Piece):
def is_move_valid(self, origine, destination):
oc, ol = origine
dc, dl = destination
if origine == destination:
return False
if oc-dc == 2 or oc-dc == -2:
if ol-dl == 1 or ol-dl == -1:
return True
elif ol-dl == 2 or ol-dl == -2:
if oc-dc == 1 or oc-dc == -1:
return True
else:
return False
class Pawn(Piece):
def is_move_valid(self, origine, destination):
if origine == destination:
return False
oc, ol = origine
dc, dl = destination
if dc-oc == 1:
return True
elif dc-oc == 1 and (dl-ol== 1 or dl - ol == -1) and is_ennemy(destination):
return True
else:
return False