|
|
"""Deep dive into HOLD system and real-time inference interception."""
|
|
|
import sys
|
|
|
sys.path.insert(0, 'F:/End-Game/glassboxgames/children')
|
|
|
|
|
|
import cascade
|
|
|
from cascade import Hold, HoldPoint, HoldState
|
|
|
import numpy as np
|
|
|
import threading
|
|
|
import time
|
|
|
|
|
|
print("=" * 70)
|
|
|
print("⏸️ CASCADE HOLD SYSTEM - Real-time Inference Interception")
|
|
|
print("=" * 70)
|
|
|
|
|
|
|
|
|
hold = Hold.get()
|
|
|
print(f"\nHold singleton: {hold}")
|
|
|
print(f"Current hold: {hold.current_hold}")
|
|
|
print(f"Stats: {hold.stats}")
|
|
|
|
|
|
|
|
|
hold_points_received = []
|
|
|
|
|
|
def my_listener(hold_point: HoldPoint):
|
|
|
print(f"\n🛑 HOLD POINT RECEIVED!")
|
|
|
print(f" Brain: {hold_point.brain_id}")
|
|
|
print(f" AI choice: {hold_point.ai_choice}")
|
|
|
print(f" Confidence: {hold_point.ai_confidence:.2%}")
|
|
|
print(f" Merkle: {hold_point.merkle_root}")
|
|
|
print(f" State: {hold_point.state}")
|
|
|
hold_points_received.append(hold_point)
|
|
|
|
|
|
|
|
|
time.sleep(0.1)
|
|
|
hold.accept()
|
|
|
|
|
|
hold.register_listener(my_listener)
|
|
|
print("\n✅ Listener registered")
|
|
|
|
|
|
|
|
|
print("\n=== Simulating Hold Point (non-blocking) ===")
|
|
|
|
|
|
def simulate_brain():
|
|
|
|
|
|
action_probs = np.array([0.1, 0.15, 0.5, 0.25])
|
|
|
value = 0.73
|
|
|
observation = {'game': 'test', 'frame': 42}
|
|
|
|
|
|
print(f"Brain: yielding hold point...")
|
|
|
resolution = hold.yield_point(
|
|
|
action_probs=action_probs,
|
|
|
value=value,
|
|
|
observation=observation,
|
|
|
brain_id="test_brain_001",
|
|
|
action_labels=["UP", "DOWN", "FIRE", "STAY"],
|
|
|
blocking=False
|
|
|
)
|
|
|
print(f"Brain: got resolution -> action={resolution.action}, override={resolution.was_override}, source={resolution.override_source}")
|
|
|
return resolution
|
|
|
|
|
|
result = simulate_brain()
|
|
|
|
|
|
print(f"\n=== Result ===")
|
|
|
print(f"Action taken: {result.action}")
|
|
|
print(f"Was override: {result.was_override}")
|
|
|
print(f"Override source: {result.override_source}")
|
|
|
print(f"Hold duration: {result.hold_duration:.4f}s")
|
|
|
print(f"Merkle root: {result.merkle_root}")
|
|
|
|
|
|
|
|
|
print("\n=== Testing Override Scenario ===")
|
|
|
|
|
|
override_received = None
|
|
|
|
|
|
def override_listener(hp: HoldPoint):
|
|
|
global override_received
|
|
|
override_received = hp
|
|
|
print(f"\n🛑 HOLD for override test")
|
|
|
print(f" AI wants action {hp.ai_choice} ({hp.ai_confidence:.0%} confident)")
|
|
|
|
|
|
time.sleep(0.05)
|
|
|
hold.override(action=0, source="human_player")
|
|
|
|
|
|
hold.unregister_listener(my_listener)
|
|
|
hold.register_listener(override_listener)
|
|
|
|
|
|
action_probs = np.array([0.1, 0.8, 0.05, 0.05])
|
|
|
resolution = hold.yield_point(
|
|
|
action_probs=action_probs,
|
|
|
value=0.9,
|
|
|
observation={'test': 'override'},
|
|
|
brain_id="test_brain_002",
|
|
|
action_labels=["CONSERVATIVE", "AGGRESSIVE", "RETREAT", "WAIT"],
|
|
|
blocking=False
|
|
|
)
|
|
|
|
|
|
print(f"\n Final action: {resolution.action}")
|
|
|
print(f" Was override: {resolution.was_override}")
|
|
|
print(f" Override source: {resolution.override_source}")
|
|
|
print(f" AI wanted: 1 (AGGRESSIVE)")
|
|
|
print(f" Human chose: 0 (CONSERVATIVE)")
|
|
|
|
|
|
print("\n=== Hold Stats After Test ===")
|
|
|
print(hold.stats)
|
|
|
|