Skip to content

Commit 27e7da3

Browse files
committed
modularity and design ♟️
1 parent ddd63b9 commit 27e7da3

File tree

15 files changed

+361
-48
lines changed

15 files changed

+361
-48
lines changed

app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from flask import Flask
2-
from routes import bp
2+
from src.routes import bp # import the blueprint from your package
33

44
def create_app():
55
app = Flask(__name__)
66
app.register_blueprint(bp)
77
return app
88

9+
# For local dev
910
if __name__ == "__main__":
1011
create_app().run(debug=True)

config.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# src/__init__.py
148 Bytes
Binary file not shown.
2.1 KB
Binary file not shown.
523 Bytes
Binary file not shown.
1.47 KB
Binary file not shown.
1.37 KB
Binary file not shown.
Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
import chess.pgn, io
2-
from engine_manager import EngineManager
3-
from config import ENGINE_DEPTH
2+
import chess
3+
from src.engine_manager import EngineManager
4+
from src.config import ENGINE_DEPTH
45

56
def analyze_pgn(pgn_text):
6-
"""
7-
Parses PGN, runs Stockfish before/after each move,
8-
and returns a list of dicts with san, eval, tag, from, to.
9-
"""
107
game = chess.pgn.read_game(io.StringIO(pgn_text))
118
if game is None:
129
raise ValueError("Could not parse PGN")
1310

1411
board = game.board()
15-
engine_mgr = EngineManager()
16-
analysis = []
12+
mgr = EngineManager()
13+
result = []
1714

1815
for move in game.mainline_moves():
19-
info_before = engine_mgr.analyze(board, ENGINE_DEPTH)
16+
info_before = mgr.analyze(board, ENGINE_DEPTH)
2017
score_before = info_before['score'].white().score(mate_score=10000)
2118

2219
san = board.san(move)
@@ -25,30 +22,28 @@ def analyze_pgn(pgn_text):
2522

2623
board.push(move)
2724

28-
info_after = engine_mgr.analyze(board, ENGINE_DEPTH)
25+
info_after = mgr.analyze(board, ENGINE_DEPTH)
2926
score_after = info_after['score'].white().score(mate_score=10000)
3027

31-
# classify
28+
diff = (score_after or 0) - (score_before or 0)
3229
if score_before is None or score_after is None:
3330
tag = "Unknown"
31+
elif abs(diff) < 20:
32+
tag = "Best Move"
33+
elif abs(diff) < 100:
34+
tag = "Inaccuracy"
35+
elif abs(diff) < 300:
36+
tag = "Mistake"
3437
else:
35-
diff = score_after - score_before
36-
if abs(diff) < 20:
37-
tag = "Best Move"
38-
elif abs(diff) < 100:
39-
tag = "Inaccuracy"
40-
elif abs(diff) < 300:
41-
tag = "Mistake"
42-
else:
43-
tag = "Blunder"
44-
45-
analysis.append({
38+
tag = "Blunder"
39+
40+
result.append({
4641
"san": san,
4742
"eval": score_after,
4843
"tag": tag,
4944
"from": uci_from,
5045
"to": uci_to
5146
})
5247

53-
engine_mgr.close()
54-
return analysis
48+
mgr.close()
49+
return result

src/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
3+
# src/config.py
4+
BASE_DIR = os.path.dirname(__file__) # .../your‑project/src
5+
ENGINE_PATH = os.path.abspath(
6+
os.path.join(BASE_DIR, os.pardir, "stockfish.exe")
7+
)
8+
ENGINE_DEPTH = 15

0 commit comments

Comments
 (0)