-
Notifications
You must be signed in to change notification settings - Fork 1
/
piece.py
40 lines (31 loc) · 2.31 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
# -------------------------------------------------------------------------------------------------------------------- #
# piece.py: περιέχει την κλάση Piece #
# -------------------------------------------------------------------------------------------------------------------- #
class Piece:
"""
Αρχικοποιεί κάθε κομμάτι του σκακιού ως ένα αντικείμενο, προσδίδοντάς του κάποιες βασικές ιδιότητες
Ορίσματα:
---------
name (str):
όνομα κομματιού (π.χ. rbl= rook black left κ.ο.κ)
pos (str):
θέση κομματιού (π.χ. a8= στήλη A, γραμμή 8 κ.ο.κ)
state (bool):
κατάσταση κομματιού (True για κομμάτια, False για κενά κελιά)
row (int):
γραμμή του πίνακα που βρίσκεται το κομμάτι (χρησιμοποιείται στην κλάση gui.GUI)
col (int):
στήλη του πίνακα που βρίσκεται το κομμάτι (χρησιμοποιείται στην κλάση gui.GUI)
"""
def __init__(self, name: str, pos: str, state=True, row=-1, col=-1):
self.name = name # όνομα κομματιού (π.χ. rbl= rook black left κ.ο.κ)
self.pos = pos # θέση κομματιού (π.χ. a8= στήλη A, γραμμή 8 κ.ο.κ)
self.state = state # κατάσταση κομματιού (True για κομμάτια, False για κενά κελιά)
# συντεταγμένες που θα βοηθήσουν στη γραφική αναπαράσταση της σκακιέρας (βλ. κλάση GUI)
self.row = row # γραμμή του πίνακα που βρίσκεται το κομμάτι
self.col = col # στήλη του πίνακα που βρίσκεται το κομμάτι
def __str__(self):
"""
Μέθοδος για εκτυπώσεις στην κονσόλα (βοήθησε στο debugging)
"""
return f"{self.name}({self.pos}) [{self.row}][{self.col}]"