-
Notifications
You must be signed in to change notification settings - Fork 0
/
pawn.py
40 lines (34 loc) · 1.24 KB
/
pawn.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
pos_letters = ["a", "b", "c", "d", "e", "f", "g", "h"]
class Pawn:
def __init__(self, color, position):
self.color = str(color).lower()
self.position = position
self.moved = 0
self.en_passant = 0
def __repr__(self) -> str:
if self.color == "b":
return "p"
else:
return "P"
def move(self, current_pos):
moves = []
ch = current_pos[0]
nm = int(current_pos[1])
if self.moved == 0:
self.moved = 1
if self.color == "w":
moves.append(f"{pos_letters[pos_letters.index(ch)]}{nm+1}")
moves.append(f"{pos_letters[pos_letters.index(ch)]}{nm+2}")
elif self.color == "b":
moves.append(f"{pos_letters[pos_letters.index(ch)]}{nm-1}")
moves.append(f"{pos_letters[pos_letters.index(ch)]}{nm-2}")
else:
if self.color == "w":
moves.append(f"{pos_letters[pos_letters.index(ch)]}{nm+1}")
elif self.color == "b":
moves.append(f"{pos_letters[pos_letters.index(ch)]}{nm-1}")
return moves
def draw(self):
if self.color == "w":
return "white_pawn"
return "black_pawn"