File size: 7,371 Bytes
ca22e9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f3ce80
 
 
 
 
ca22e9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f3ce80
 
 
ca22e9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f3ce80
 
ca22e9e
8f3ce80
 
ca22e9e
 
8f3ce80
ca22e9e
 
 
8f3ce80
 
 
 
 
 
 
ca22e9e
 
 
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import gradio as gr
import time
import threading
from datetime import datetime
import numpy as np

from rng_system import get_rng, RandomBufferMonitor
from alien_system import AlienSpawner, AlienPatternLibrary

# গ্লোবাল ইন্সট্যান্স
rng = get_rng()
buffer_monitor = RandomBufferMonitor(rng)
pattern_library = AlienPatternLibrary()
spawner = AlienSpawner(pattern_library)

# ব্যাকগ্রাউন্ড আপডেট থ্রেড
running = True

def background_updater():
    """পটভূমিতে গেম স্টেট আপডেট করে"""
    last_time = time.time()
    while running:
        current_time = time.time()
        dt = current_time - last_time
        
        # এলিয়েন আপডেট
        spawner.update(dt)
        
        # বাফার মনিটর
        if int(current_time) % 5 == 0:  # প্রতি ৫ সেকেন্ডে
            buffer_monitor.log_status()
        
        last_time = current_time
        time.sleep(0.016)  # ~60 FPS

# ব্যাকগ্রাউন্ড থ্রেড স্টার্ট
thread = threading.Thread(target=background_updater, daemon=True)
thread.start()

# ==================== UI ফাংশন ====================

def get_rng_status():
    """RNG স্ট্যাটাস"""
    stats = rng.get_stats()
    health = buffer_monitor.check_health()
    
    return f"""
    **র‍্যান্ডম বাফার স্ট্যাটাস**:
    - বাফার লেভেল: {stats.buffer_size}/1000
    - খালি পড়া: {stats.empty_reads}
    - গড় পড়ার সময়: {stats.average_read_time*1000:.3f}ms
    - স্বাস্থ্য স্কোর: {health['health_score']}/100
    - স্ট্যাটাস: {health['status']}
    """

def get_aliens_status():
    """এলিয়েন স্ট্যাটাস"""
    aliens = spawner.get_aliens_data()
    stats = spawner.get_stats()
    history = spawner.get_spawn_history(10)
    
    alien_lines = []
    for alien in aliens[:5]:  # প্রথম ৫টি দেখায়
        alien_lines.append(f"ID:{alien['id']} {alien['type']} @({alien['x']},{alien['y']}) HP:{alien['health']}")
    
    history_lines = []
    for h in history:
        history_lines.append(f"{h['time']} - {h['type']} at {h['position']}")
    
    return f"""
    **এলিয়েন স্ট্যাটাস**:
    - সক্রিয় এলিয়েন: {stats['active_aliens']}
    - মোট স্পন: {stats['total_spawned']}
    - মোট নিহত: {stats['total_killed']}
    
    **সক্রিয় এলিয়েন**:
    {chr(10).join(alien_lines) if alien_lines else 'কোন এলিয়েন নেই'}
    
    **সাম্প্রতিক স্পন**:
    {chr(10).join(history_lines) if history_lines else 'কোন স্পন নেই'}
    """

def spawn_alien_manually():
    """ম্যানুয়ালি এলিয়েন স্পন"""
    alien_type = spawner._select_alien_type()
    x, y = spawner._get_random_spawn_position()
    alien = spawner._create_alien(alien_type, x, y)
    spawner.aliens.append(alien)
    return get_aliens_status()

def reset_system():
    """সবকিছু রিসেট"""
    global spawner
    rng.reset()
    spawner = AlienSpawner(pattern_library)
    return get_rng_status(), get_aliens_status()

def get_next_random():
    """পরবর্তী র‍্যান্ডম ভ্যালু"""
    value = rng.next_random()
    return f"পরবর্তী র‍্যান্ডম ভ্যালু: {value}"

def refresh_all():
    """সব ডাটা রিফ্রেশ"""
    return get_rng_status(), get_aliens_status()

# ==================== কাস্টম CSS ====================

CUSTOM_CSS = """
.gradio-container {
    background: #0a0a0f !important;
    color: #ffffff !important;
    font-family: 'Inter', sans-serif !important;
}
footer {visibility: hidden}
h1 { 
    color: #00d4ff !important; 
    text-align: center; 
    margin-bottom: 20px; 
    text-shadow: 0 0 10px #00d4ff; 
}
.gr-box { 
    border: 1px solid #333 !important; 
    background: rgba(255,255,255,0.05) !important; 
}
.gr-button-primary { 
    background: linear-gradient(135deg, #00d4ff, #0088ff) !important; 
    border: none !important; 
}
.gr-button-secondary { 
    background: rgba(255,255,255,0.1) !important; 
    border: 1px solid #00d4ff !important; 
}
"""

# ==================== Gradio UI (Gradio 6.0+ কম্প্যাটিবল) ====================

with gr.Blocks(title="AVOLD - Aviator Engine") as demo:
    gr.HTML("""
    <div style="text-align: center; margin-bottom: 20px;">
        <h1 style="color: #00d4ff; font-size: 48px; margin: 0;">✈️ AVOLD ENGINE</h1>
        <p style="color: #888; font-size: 14px;">টাইমার-ভিত্তিক RNG + এলিয়েন স্পনিং সিস্টেম</p>
    </div>
    """)
    
    with gr.Tabs():
        with gr.TabItem("RNG সিস্টেম"):
            rng_status = gr.Markdown(value=get_rng_status())
            with gr.Row():
                random_btn = gr.Button("🎲 পরবর্তী র‍্যান্ডম ভ্যালু", variant="primary")
                random_value = gr.Textbox(label="র‍্যান্ডম ভ্যালু", interactive=False)
            random_btn.click(fn=get_next_random, outputs=random_value)
        
        with gr.TabItem("এলিয়েন সিস্টেম"):
            alien_status = gr.Markdown(value=get_aliens_status())
            with gr.Row():
                spawn_btn = gr.Button("👾 ম্যানুয়াল এলিয়েন স্পন", variant="primary")
                refresh_btn = gr.Button("🔄 রিফ্রেশ", variant="secondary")
            spawn_btn.click(fn=spawn_alien_manually, outputs=alien_status)
            refresh_btn.click(fn=get_aliens_status, outputs=alien_status)
        
        with gr.TabItem("মনিটরিং"):
            monitor_status = gr.Markdown(value=get_rng_status())
            refresh_monitor = gr.Button("🔄 রিফ্রেশ মনিটর")
            refresh_monitor.click(fn=get_rng_status, outputs=monitor_status)
    
    with gr.Row():
        reset_btn = gr.Button("🔄 সম্পূর্ণ সিস্টেম রিসেট", variant="secondary")
    
    reset_btn.click(
        fn=reset_system,
        outputs=[rng_status, alien_status]
    )
    
    # Gradio 6.0-এ 'every' প্যারামিটার কাজ করে না
    # তাই আমরা JavaScript দিয়ে auto-refresh করব
    demo.load(
        fn=refresh_all,
        outputs=[rng_status, alien_status]
    )

# ==================== অ্যাপ রান (Gradio 6.0+ কম্প্যাটিবল) ====================

if __name__ == "__main__":
    try:
        # theme এবং css এখন launch()-এ দেওয়া হয়
        demo.launch(
            server_name="0.0.0.0", 
            server_port=7860,
            theme='dark',
            css=CUSTOM_CSS
        )
    finally:
        running = False
        rng.stop()