#pragma once #include #include /** * Fungal (mycelium) population in SoA layout for coalesced GPU access. * Each fungus contributes a local basis φ_h(x,y) to build amplitude/phase masks. */ struct FungiSoA { int F = 0; // number of fungi int H = 0, W = 0; // mask geometry // Genome / state std::vector x, y; // position in [0, W-1] & [0, H-1] std::vector sigma; // radius std::vector alpha; // anisotropy (ellipse) std::vector theta; // orientation std::vector a_base; // amplitude base coeff std::vector p_base; // phase base coeff // Energy & life-cycle std::vector energy; std::vector mass; std::vector age; void resize(int F_, int H_, int W_); void init_random(unsigned seed, float sigma_min=1.5f, float sigma_max=5.5f); void adjust_population(int newF, unsigned seed); }; /** Build masks A(x,y), P(x,y) from fungi population (GPU). */ void fungi_build_masks_GPU(const FungiSoA& pop, float* d_A, float* d_P, // [H*W] int tiles_y=7, int tiles_x=7); /** Evolution step (GPU): compute per-fungus reward and update energy, size, reproduction. */ void fungi_evolve_GPU(FungiSoA& pop, const float* d_grad_map, // e.g., gradient magnitude per pixel [H*W] int evo_pairs, float food=0.05f, float decay=0.98f, float death_th=-0.5f, float cost=1e-3f, unsigned seed=1337); /** Host helpers: download masks (optional debug). */ void download_mask(float* h, const float* d, int HW); /** DIAGNOSTIC TOOLS: Visual debugging for fungi evolution */ void fungi_export_debug_images(const FungiSoA& pop, const float* d_A, const float* d_P, const float* d_grad_map, const char* prefix = "debug"); void fungi_create_test_pattern(float* h_pattern, int H, int W, int pattern_type = 0); void fungi_analyze_mask_statistics(const float* d_A, const float* d_P, int HW);