File size: 1,049 Bytes
37d841f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Endpoint de análisis: recibe un PGN y devuelve evaluación jugada a jugada."""
from flask import Blueprint, request, jsonify
from modules.analysis.stockfish_wrapper import analyze_pgn

analyze_bp = Blueprint('analyze', __name__)


@analyze_bp.route('/analyze', methods=['POST'])
def analyze():
    """
    Body JSON:
      { "pgn_en": "1. e4 e5 2. Nf3 ...", "depth": 18 (opcional) }

    Respuesta:
      { "depth": int, "total_moves": int, "moves": [...] }
    """
    data = request.get_json(silent=True) or {}
    pgn = (data.get('pgn_en') or '').strip()
    if not pgn:
        return jsonify({'error': "Se esperaba {'pgn_en': '...'}"}), 400

    depth = data.get('depth')
    if depth is not None:
        try:
            depth = int(depth)
            if not (1 <= depth <= 30):
                return jsonify({'error': 'depth debe estar entre 1 y 30'}), 400
        except (TypeError, ValueError):
            return jsonify({'error': 'depth debe ser entero'}), 400

    result = analyze_pgn(pgn, depth=depth)
    return jsonify(result)