// Cardea Phase 2 — debug evolve() dispatch
use crypto::cardea
use crypto::dna

fn main() {
    println("=== Cardea Evolve Debug ===")

    let key = livingkey_new()
    println("Created key. Generation: " + int_to_str(key.generation))

    // Test: can we call evolve at all?
    println("Calling key.evolve(1.0)...")
    key.evolve(1.0)
    println("After evolve. Generation: " + int_to_str(key.generation))

    // If generation is still 0, the issue is inside evolve.
    // Let's manually trace the gate logic.
    println("")
    println("=== Manual Gate Trace ===")
    let v = entropy_pressure(key.entropy_pool, key.cascade_coupling)
    println("entropy_pressure v = " + float_to_str(v))

    let m_inf = hh_m_inf(v)
    let h_inf = hh_h_inf(v)
    println("m_inf = " + float_to_str(m_inf))
    println("h_inf = " + float_to_str(h_inf))

    println("mg_m = " + float_to_str(key.mg_m))
    println("mg_h = " + float_to_str(key.mg_h))

    let gate = key.mg_m * key.mg_h
    println("gate_open (mg_m * mg_h) = " + float_to_str(gate))

    if gate < 0.5 {
        println("GATE BLOCKED — this is why evolve does nothing")
    } else {
        println("Gate is open — problem is elsewhere")
    }

    // Try multiple evolves
    println("")
    println("=== 10 evolve() calls ===")
    let mut i = 0
    while i < 10 {
        key.evolve(1.0)
        println("tick " + int_to_str(i) + " -> gen=" + int_to_str(key.generation) + " mg_m=" + float_to_str(key.mg_m) + " mg_h=" + float_to_str(key.mg_h))
        i = i + 1
    }
}
