This repository has been archived by the owner on Jan 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpieces.py
59 lines (52 loc) · 1.52 KB
/
pieces.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
class Piece():
"""A class wich represents a piece of chess
Attributes:
type: the numerical representation of the type of piece (King, Queen, etc.)
rank: the rank of the piece, dependent on its type and used in the Rank heuristic by Verlaan
"""
toType = {
1: "Q",
2: "R",
3: "B",
4: "N",
5: "P",
6: "K"
}
def __init__(self, t):
"""Initialises a Piece object
Args:
t: the numerical representation of the type of piece
"""
match t:
case "Q":
# Queen
self.type = 1
self.rank = 9
case "R":
# Rook
self.type = 2
self.rank = 5
case "B":
# Bischop
self.type = 3
self.rank = 5
case "N":
# kNight
self.type = 4
self.rank = 3
case "P":
# Pawn
self.type = 5
self.rank = 1
case "K":
# King
self.type = 6
self.rank = 99
def __repr__(self) -> str:
"""The string representation of a Piece object
Returns:
A string containing information about the type and rank of the piece
"""
return f"{Piece.toType[self.type]}"
def __lt__(self, other):
return self.type < other.type