-
Notifications
You must be signed in to change notification settings - Fork 0
/
descriptor.py
106 lines (84 loc) · 2.83 KB
/
descriptor.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
from action_parser import BoardAction
from chessman import Bishop, King, Knight, Pawn, Queen, Rook
# from manager import TurnResult
class Descriptor:
@classmethod
def describe(cls, turn):
score = turn.score
if score:
print(f'End of game with a result of {score}')
return
rook = turn.rook
if rook:
print(f'{rook}')
return
piece = turn.chessman
capture = turn.captured_chessman
promotion = turn.promotion
if promotion:
print(f'The {piece} has been promoted to {promotion}')
return
distance = cls.get_distance(turn.actions[0])
if capture:
buf = f'The {piece} has moved {distance} and captured a {capture}.'
else:
buf = f'The {piece} has moved {distance}.'
if turn.check:
buf += ' Check !'
if turn.checkmate:
buf += ' Checkmate !!'
print(buf)
"""
if capture :
ajoute capture + piece concernée
if promotion:
ajoute promote into + piece
if actions > 1 => Rook
ajoute rook + côté + color
if actions = 1:
ajoute has moved
if score:
ajoute game ended with score of
if echec:
ajoute met en echec le roi
if echec et mat
ajoute met en echec et mat
"""
@classmethod
def get_distance(cls, action: BoardAction):
x, y = action.start_pos
x1, y1 = action.end_pos
piece = action.chessman
distance = 0
if isinstance(piece, (Pawn, Bishop)):
distance = abs(x1 - x)
elif isinstance(piece, (Rook, King, Queen)):
distance = max(abs(x1 - x), abs(y1 - y))
elif isinstance(piece, Knight):
distance_x = abs(x1 - x)
distance_y = abs(y1 - y)
return f'{distance_y} square horizontally and {distance_x} squares vertically'
return f'{distance} squares'
@classmethod
def describe_as_log(cls, turn)->str:
score = turn.score
if score:
return f'End of game with a result of {score}'
rook = turn.rook
if rook:
return f'{rook}'
piece = turn.chessman
capture = turn.captured_chessman
promotion = turn.promotion
if promotion:
return f'The {piece} has been promoted to {promotion}'
distance = cls.get_distance(turn.actions[0])
if capture:
buf = f'The {piece} has moved {distance} and captured a {capture}.'
else:
buf = f'The {piece} has moved {distance}.'
if turn.check:
buf += ' Check !'
if turn.checkmate:
buf += ' Checkmate !!'
return buf