File size: 2,183 Bytes
80e55f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import datetime
import google.generativeai as genai
import os


genai.configure(api_key=os.environ.get('GOOGLE_API_KEY'))
model = genai.GenerativeModel('gemini-2.5-flash')

def get_counter_debuts(opponent_debuts, user_color, user_repertoire):
    if not opponent_debuts or not opponent_debuts.strip():
        return "❌ Iltimos, kamida bitta debyt kiriting!"
    
    color_context = "Siz oq rangli o'ynaysiz." if user_color == "Oq" else "Siz qora rangli o'ynaysiz."
    
    repertoire_context = ""
    if user_repertoire and user_repertoire.strip():
        repertoire_context = f"\n\nFOYDALANUVCHI REPERTUARI:\n{user_repertoire}\n\nIltimos, bu repertuarni hisobga olib tavsiyalar bering."

    prompt = f"""
    Siz professional shaxmat murabbiyisiz. {color_context}
    
    Raqib quyidagi debyutlarni o'ynaydi:
    {opponent_debuts}
    {repertoire_context}
    
    Har bir raqib debyuti uchun quyidagilarni bering:
    
    ## DEBYT NOMI
    
    **Qarshi Debyt:** [Eng yaxshi qarshi debyt]
    
    **Asosiy G'oya:**
    [2-3 jumlada tushuntirish]
    
    **Strategik Rejalar:**
    - [Reja 1]
    - [Reja 2]
    - [Reja 3]
    
    **Muhim Yurishlar:**
    [Boshlanish yurishlari ketma-ketligi]
    
    **Tuzoqlar va Ehtiyot Choralari:**
    [Diqqat qilish kerak bo'lgan narsalar]
    
    ---
    
    Javobni o'zbek tilida, toza markdown formatida bering.
    """
    
    try:
        response = model.generate_content(prompt)
        fixed_response = response.text.strip()
        
        result = f"""# πŸ† SHAXMAT TAHLILI NATIJALARI

**Sana:** {datetime.now().strftime("%Y-%m-%d %H:%M")}  
**Sizning Rangingiz:** {user_color}  
---

{fixed_response}

---

## πŸ’‘ QO'SHIMCHA MASLAHATLAR

1. **O'rganish:** Har bir debyutni lichess.org/learn yoki chess.com da mashq qiling
2. **Tahlil:** O'yinlaringizni tahlil qiling va xatolarni toping
3. **Mashq:** Turli holatlarni mashq qiling
4. **Vaqt:** Har bir debyutga kamida 30 daqiqa ajrating

βœ… **Omad tilaymiz! Yaxshi o'ynang!** β™ŸοΈ
"""
        return result
        
    except Exception as e:
        return f"❌ Xatolik yuz berdi: {str(e)}\n\nIltimos, GOOGLE_API_KEY to'g'ri o'rnatilganligini tekshiring."