silentengine 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- silentengine/__init__.py +1 -0
- silentengine/batch.py +758 -0
- silentengine/board.py +606 -0
- silentengine/config.py +91 -0
- silentengine/constants.py +21 -0
- silentengine/data.py +259 -0
- silentengine/dialogs.py +152 -0
- silentengine/engine.py +293 -0
- silentengine/engine_setup.py +263 -0
- silentengine/main.py +35 -0
- silentengine/resources/openings.tsv +3866 -0
- silentengine/resources/stats.db.zst +0 -0
- silentengine/review.py +184 -0
- silentengine/theme.py +66 -0
- silentengine/widgets.py +457 -0
- silentengine/window.py +1824 -0
- silentengine-1.1.0.dist-info/METADATA +202 -0
- silentengine-1.1.0.dist-info/RECORD +21 -0
- silentengine-1.1.0.dist-info/WHEEL +4 -0
- silentengine-1.1.0.dist-info/entry_points.txt +2 -0
- silentengine-1.1.0.dist-info/licenses/LICENSE +674 -0
|
Binary file
|
silentengine/review.py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import math
|
|
3
|
+
|
|
4
|
+
import chess
|
|
5
|
+
import chess.engine
|
|
6
|
+
import chess.pgn
|
|
7
|
+
import chess.polyglot
|
|
8
|
+
import chess.svg
|
|
9
|
+
|
|
10
|
+
# Game review (full-game analysis, move classification, eval graph)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
PIECE_VALUES = {
|
|
14
|
+
chess.PAWN: 1,
|
|
15
|
+
chess.KNIGHT: 3,
|
|
16
|
+
chess.BISHOP: 3,
|
|
17
|
+
chess.ROOK: 5,
|
|
18
|
+
chess.QUEEN: 9,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
# (label, badge text, color); the first five fill the left column of the Review tab
|
|
22
|
+
CATEGORIES = [
|
|
23
|
+
("Brilliant", "!!", "#1baca6"),
|
|
24
|
+
("Great", "!", "#5c8bb0"),
|
|
25
|
+
("Best", "★", "#81b64c"),
|
|
26
|
+
("Excellent", "✓", "#96bc4b"),
|
|
27
|
+
("Good", "✓", "#7fa26a"),
|
|
28
|
+
("Book", "B", "#a88865"),
|
|
29
|
+
("Inaccuracy", "?!", "#e6c200"),
|
|
30
|
+
("Mistake", "?", "#e68a00"),
|
|
31
|
+
("Miss", "✗", "#ee6b6e"),
|
|
32
|
+
("Blunder", "??", "#d14343"),
|
|
33
|
+
]
|
|
34
|
+
CAT_COLOR = {label: color for label, _badge, color in CATEGORIES}
|
|
35
|
+
BADGE_TEXT = {label: badge for label, badge, _c in CATEGORIES}
|
|
36
|
+
# categories that get a symbol after the move in the move list / graph / PGN
|
|
37
|
+
SYMBOLS = {
|
|
38
|
+
"Brilliant": ("!!", CAT_COLOR["Brilliant"]),
|
|
39
|
+
"Great": ("!", CAT_COLOR["Great"]),
|
|
40
|
+
"Inaccuracy": ("?!", CAT_COLOR["Inaccuracy"]),
|
|
41
|
+
"Mistake": ("?", CAT_COLOR["Mistake"]),
|
|
42
|
+
"Blunder": ("??", CAT_COLOR["Blunder"]),
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
BAD_LABELS = ("Mistake", "Miss", "Blunder")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# Eval helpers
|
|
49
|
+
def win_fraction(cp: float) -> float:
|
|
50
|
+
"""White's winning chances in [0, 1] (Lichess formula)."""
|
|
51
|
+
return 1.0 / (1.0 + math.exp(-0.00368208 * cp))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def line_fraction(line: dict) -> float:
|
|
55
|
+
if line["mate"] is not None:
|
|
56
|
+
return 1.0 if line["mate"] > 0 else 0.0
|
|
57
|
+
return win_fraction(line["cp"])
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def line_text(line: dict) -> str:
|
|
61
|
+
if line["mate"] is not None:
|
|
62
|
+
return f"M{line['mate']}" if line["mate"] > 0 else f"-M{abs(line['mate'])}"
|
|
63
|
+
pawns = line["cp"] / 100
|
|
64
|
+
return f"{pawns:+.1f}" if abs(pawns) >= 10 else f"{pawns:+.2f}"
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def fmt_spent(sec: float) -> str:
|
|
68
|
+
if sec < 10:
|
|
69
|
+
return f"{sec:.1f}s"
|
|
70
|
+
if sec < 60:
|
|
71
|
+
return f"{sec:.0f}s"
|
|
72
|
+
return f"{int(sec // 60)}m{int(sec % 60):02d}"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def material_diff(board: chess.Board, color: bool) -> int:
|
|
76
|
+
total = 0
|
|
77
|
+
for piece in board.piece_map().values():
|
|
78
|
+
v = PIECE_VALUES.get(piece.piece_type, 0)
|
|
79
|
+
total += v if piece.color == color else -v
|
|
80
|
+
return total
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def is_sacrifice(
|
|
84
|
+
before: chess.Board, mover: bool, after: chess.Board, pv: list
|
|
85
|
+
) -> bool:
|
|
86
|
+
"""Follow the engine's reply line until it goes quiet; did the mover end up >= 2 points down?"""
|
|
87
|
+
start = material_diff(before, mover)
|
|
88
|
+
b = after.copy(stack=False)
|
|
89
|
+
for k, mv in enumerate(pv[:6]):
|
|
90
|
+
capture = b.is_capture(mv)
|
|
91
|
+
b.push(mv)
|
|
92
|
+
if k >= 1 and not capture:
|
|
93
|
+
break
|
|
94
|
+
return start - material_diff(b, mover) >= 2
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def classify_line(boards: list, moves: list, results: list, in_book: list) -> list:
|
|
98
|
+
"""boards[i] = position after i plies. Returns one dict per move (plies 1..N).
|
|
99
|
+
|
|
100
|
+
Heuristic approximation of the usual move ratings (the real Chess.com rules aren't public):
|
|
101
|
+
Blunder/Mistake/Inaccuracy: win-chance loss >= 15 / 10 / 5 points
|
|
102
|
+
Brilliant: near-best move that sacrifices material and doesn't leave you worse
|
|
103
|
+
Great: the only good move (every alternative loses >= 15 points), not a plain recapture
|
|
104
|
+
Best: the engine's top move; Excellent: loss < 2; Good: the rest; Book: known opening position
|
|
105
|
+
"""
|
|
106
|
+
out = []
|
|
107
|
+
for i in range(1, len(boards)):
|
|
108
|
+
prev_loss = out[-1]["loss"] if out else 0.0
|
|
109
|
+
b0, played = boards[i - 1], moves[i - 1]
|
|
110
|
+
mover = b0.turn
|
|
111
|
+
|
|
112
|
+
def pov(frac: float) -> float:
|
|
113
|
+
return frac * 100 if mover == chess.WHITE else 100 - frac * 100
|
|
114
|
+
|
|
115
|
+
before, after = pov(results[i - 1]["frac"]), pov(results[i]["frac"])
|
|
116
|
+
loss = max(0.0, before - after)
|
|
117
|
+
best = results[i - 1]["best"]
|
|
118
|
+
is_best = best is not None and played == best
|
|
119
|
+
second = results[i - 1].get("second")
|
|
120
|
+
gap = before - pov(second) if second is not None else None
|
|
121
|
+
prev = moves[i - 2] if i >= 2 else None
|
|
122
|
+
recapture = (
|
|
123
|
+
prev is not None
|
|
124
|
+
and b0.is_capture(played)
|
|
125
|
+
and played.to_square == prev.to_square
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
if in_book[i] and loss < 5:
|
|
129
|
+
label = "Book"
|
|
130
|
+
elif loss >= 15:
|
|
131
|
+
label = "Blunder"
|
|
132
|
+
elif loss >= 5 and prev_loss >= 10 and before >= 50:
|
|
133
|
+
label = "Miss"
|
|
134
|
+
elif loss >= 10:
|
|
135
|
+
label = "Mistake"
|
|
136
|
+
elif loss >= 5:
|
|
137
|
+
label = "Inaccuracy"
|
|
138
|
+
elif (
|
|
139
|
+
loss <= 1.5
|
|
140
|
+
and before <= 90
|
|
141
|
+
and after >= 45
|
|
142
|
+
and is_sacrifice(b0, mover, boards[i], results[i].get("pv") or [])
|
|
143
|
+
):
|
|
144
|
+
label = "Brilliant"
|
|
145
|
+
elif (
|
|
146
|
+
loss <= 1.5
|
|
147
|
+
and gap is not None
|
|
148
|
+
and gap >= 10
|
|
149
|
+
and 3 <= before <= 92
|
|
150
|
+
and not recapture
|
|
151
|
+
):
|
|
152
|
+
label = "Great"
|
|
153
|
+
elif is_best:
|
|
154
|
+
label = "Best"
|
|
155
|
+
elif loss < 2:
|
|
156
|
+
label = "Excellent"
|
|
157
|
+
else:
|
|
158
|
+
label = "Good"
|
|
159
|
+
out.append({"label": label, "loss": loss, "before": before, "after": after})
|
|
160
|
+
return out
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def move_accuracy(loss: float) -> float:
|
|
164
|
+
"""Lichess accuracy formula; `loss` is the mover's win-chance drop in points (0-100)."""
|
|
165
|
+
return max(0.0, min(100.0, 103.1668 * math.exp(-0.04354 * max(0.0, loss)) - 3.1669))
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def volatility_weight(fracs: list[float], k: int) -> float:
|
|
169
|
+
"""Weight of move k (0-based) = std-dev of win% in a window around it (Lichess-style, approximate)."""
|
|
170
|
+
w = max(2, min(8, len(fracs) // 10))
|
|
171
|
+
win = [f * 100 for f in fracs[max(0, k - w // 2) : k + w // 2 + 1]]
|
|
172
|
+
if len(win) < 2:
|
|
173
|
+
return 0.5
|
|
174
|
+
mean = sum(win) / len(win)
|
|
175
|
+
std = math.sqrt(sum((x - mean) ** 2 for x in win) / len(win))
|
|
176
|
+
return max(0.5, min(12.0, std))
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def game_accuracy(accs: list[float], weights: list[float]) -> float | None:
|
|
180
|
+
if not accs:
|
|
181
|
+
return None
|
|
182
|
+
wmean = sum(a * w for a, w in zip(accs, weights)) / sum(weights)
|
|
183
|
+
hmean = len(accs) / sum(1 / max(a, 1.0) for a in accs)
|
|
184
|
+
return (wmean + hmean) / 2
|
silentengine/theme.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from PySide6.QtGui import (
|
|
5
|
+
QColor,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
STYLE = """
|
|
9
|
+
QWidget { background:#141414; color:#e6e6e6; font-size:13px; }
|
|
10
|
+
QLineEdit, QPlainTextEdit, QTextBrowser { background:#1b1b1b; border:1px solid #3a3a3a; padding:4px; }
|
|
11
|
+
QLineEdit[bad="true"], QPlainTextEdit[bad="true"] { border:1px solid #d14343; }
|
|
12
|
+
QToolButton { background:transparent; border:none; padding:6px 10px; font-size:16px; }
|
|
13
|
+
QToolButton:hover { background:#262626; }
|
|
14
|
+
QMenu { background:#1f1f1f; border:1px solid #333; }
|
|
15
|
+
QMenu::item { padding:6px 24px; }
|
|
16
|
+
QMenu::item:selected { background:#2e4a7a; }
|
|
17
|
+
QProgressBar { background:#2a2a2a; border:none; max-height:3px; }
|
|
18
|
+
QProgressBar::chunk { background:#3b82f6; }
|
|
19
|
+
QLabel#dbPanel { color:#777; }
|
|
20
|
+
QLabel#opening { color:#9db7e8; padding:2px 4px; }
|
|
21
|
+
QTabWidget::pane { border:1px solid #3a3a3a; top:-1px; }
|
|
22
|
+
QTabBar::tab { background:#1b1b1b; color:#888; padding:5px 14px; border:1px solid #3a3a3a; border-bottom:none; }
|
|
23
|
+
QTabBar::tab:selected { color:#e6e6e6; background:#242424; }
|
|
24
|
+
QScrollArea { border:none; }
|
|
25
|
+
QLabel#gameInfo { color:#dddddd; padding:2px 4px; font-weight:600; }
|
|
26
|
+
QTableWidget { background:#1b1b1b; border:1px solid #3a3a3a; gridline-color:#1b1b1b; }
|
|
27
|
+
QTableWidget::item:selected { background:#2e4a7a; }
|
|
28
|
+
QHeaderView::section { background:#1b1b1b; color:#888; border:none; padding:4px; }
|
|
29
|
+
QLabel#header { font-weight:600; padding:4px; }
|
|
30
|
+
|
|
31
|
+
QToolTip { background:#1f1f1f; color:#e6e6e6; border:1px solid #3a3a3a; padding:4px; }
|
|
32
|
+
|
|
33
|
+
QScrollBar:vertical { background:#141414; width:10px; margin:0; }
|
|
34
|
+
QScrollBar::handle:vertical { background:#3a3a3a; border-radius:5px; min-height:24px; }
|
|
35
|
+
QScrollBar::handle:vertical:hover { background:#4a4a4a; }
|
|
36
|
+
QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical { height:0; }
|
|
37
|
+
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical { background:none; }
|
|
38
|
+
QScrollBar:horizontal { background:#141414; height:10px; margin:0; }
|
|
39
|
+
QScrollBar::handle:horizontal { background:#3a3a3a; border-radius:5px; min-width:24px; }
|
|
40
|
+
QScrollBar::handle:horizontal:hover { background:#4a4a4a; }
|
|
41
|
+
QScrollBar::add-line:horizontal, QScrollBar::sub-line:horizontal { width:0; }
|
|
42
|
+
QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal { background:none; }
|
|
43
|
+
|
|
44
|
+
QToolButton::menu-indicator { image:none; width:0px; }
|
|
45
|
+
QToolButton[role="primary"] { background:#2e4a7a; color:#fff; font-size:13px; font-weight:600; padding:6px 16px; border-radius:4px; }
|
|
46
|
+
QToolButton[role="primary"]:hover { background:#3a5a94; }
|
|
47
|
+
QToolButton[role="primary"]:disabled { background:#2a2a2a; color:#777; }
|
|
48
|
+
QToolButton[role="chip"] { font-size:12px; padding:5px 12px; border:1px solid #3a3a3a; border-radius:4px; background:#1b1b1b; }
|
|
49
|
+
QToolButton[role="chip"]:hover { background:#262626; }
|
|
50
|
+
QToolButton[role="chip"]:checked { background:#2e4a7a; border-color:#3b82f6; color:#fff; }
|
|
51
|
+
QToolButton[role="accent"] { font-size:12px; font-weight:700; color:#e6c200; border:1px solid #6b5a00; border-radius:4px; padding:5px 12px; }
|
|
52
|
+
QToolButton[role="accent"]:hover { background:#2a2500; }
|
|
53
|
+
QToolButton[role="nav"] { padding:6px 0; min-width:40px; border-radius:4px; }
|
|
54
|
+
QToolButton[role="nav"]:hover { background:#262626; }
|
|
55
|
+
QToolButton[role="nav"]:pressed { background:#2e4a7a; }
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
LIGHT_SQ = QColor("#eeeed2")
|
|
60
|
+
DARK_SQ = QColor("#769656")
|
|
61
|
+
LAST_MOVE = QColor(255, 235, 59, 110)
|
|
62
|
+
SELECT = QColor(20, 85, 200, 110)
|
|
63
|
+
ARROW = QColor(30, 110, 220, 190)
|
|
64
|
+
MARK = QColor(60, 170, 60, 200)
|
|
65
|
+
MARK_ALT = QColor(215, 60, 60, 200)
|
|
66
|
+
HINT = QColor(240, 160, 40, 210)
|