generated from Code-Institute-Org/p3-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpiece.py
136 lines (111 loc) · 3.06 KB
/
piece.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import constants
"""
My coding of piece.py is based somewhat on how
X.S. styled piece.py as shown here
https://github.com/xsanon/chess/blob/main/src/piece.py
"""
class Piece():
"""
A class to represent a piece in chess
...
Attributes:
-----------
piece : str
Each piece is depicted by a letter which represents
the name of a piece as following :-
Pawn -> P
Rook -> R
Knight -> N
Bishop -> B
Queen -> Q
King -> K
sign (colour) : is depicted by a number
1 if the piece belongs to the Player i.e. white
-1 if the piece belongs to the Computer i.e. black
"""
def __init__(self, sign):
self.letter = ""
self.sign = sign
def print_string(self):
"""
No 'print_string' for the Base Class
"""
return None
class Rook(Piece):
def __init__(self, value, sign):
"""
Rook's value is 500
"""
super().__init__(sign)
self.letter = constants.ROOK_LETTER
self.value = constants.ROOK_VALUE * sign
def print_string(self):
"""
String to be outputted for Rooks
"""
return "Rook"
class Knight(Piece):
def __init__(self, value, sign):
"""
Knight's value is 270
"""
super().__init__(sign)
self.letter = constants.KNIGHT_LETTER
self.value = constants.KNIGHT_VALUE * sign
def print_string(self):
"""
String to be outputted for Knights
"""
return "Knight"
class Bishop(Piece):
def __init__(self, value, sign):
"""
Bishop's value is 300
"""
super().__init__(sign)
self.letter = constants.BISHOP_LETTER
self.value = constants.BISHOP_VALUE * sign
def print_string(self):
"""
String to be outputted for Bishops
"""
return "Bishop"
class Queen(Piece):
def __init__(self, value, sign):
"""
Queen's value is 900
"""
super().__init__(sign)
self.letter = constants.QUEEN_LETTER
self.value = constants.QUEEN_VALUE * sign
def print_string(self):
"""
String to be outputted for Queens
"""
return "Queen"
class King(Piece):
def __init__(self, value, sign):
"""
Note: The Player's King value is 5000
and the Computer's King value is -7500
"""
super().__init__(sign)
self.letter = constants.KING_LETTER
self.value = (constants.VALUE_OF_COMPUTER_KING
if sign == constants.COMPUTER
else constants.VALUE_OF_PLAYER_KING)
# King piece cannot be 'taken'
# So no 'print_string'
class Pawn(Piece):
def __init__(self, value, sign):
"""
Pawn's value is 100
"""
super().__init__(sign)
self.letter = constants.PAWN_LETTER
self.value = constants.PAWN_VALUE * sign
def print_string(self):
"""
String to be outputted for Pawns
"""
return "Pawn"