-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpiece.py
58 lines (41 loc) · 1.36 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
import os
class Piece:
def __init__(self, name, color, value, texture=None, texture_rect=None):
self.name = name
self.color = color
value_sign = 1 if color == 'white' else -1
self.value = value * value_sign
self.moves = []
self.moved = False
self.texture = texture
self.set_texture()
self.texture_rect = texture_rect
def set_texture(self, size=80):
self.texture = os.path.join(
f'assets/images/imgs-{size}px/{self.color}_{self.name}.png')
def add_move(self, move):
self.moves.append(move)
def clear_moves(self):
self.moves = []
class Pawn(Piece):
def __init__(self, color):
self.dir = -1 if color == 'white' else 1
self.en_passant = False
super().__init__('pawn', color, 1.0)
class Knight(Piece):
def __init__(self, color):
super().__init__('knight', color, 3.0)
class Bishop(Piece):
def __init__(self, color):
super().__init__('bishop', color, 3.001)
class Rook(Piece):
def __init__(self, color):
super().__init__('rook', color, 5.0)
class Queen(Piece):
def __init__(self, color):
super().__init__('queen', color, 9.0)
class King(Piece):
def __init__(self, color):
self.left_rook = None
self.right_rook = None
super().__init__('king', color, 10000.0)