weiss_core/pool/helpers/
mod.rs

1use super::core::EnvPool;
2
3mod fill_minimal;
4mod fill_trajectory;
5mod fingerprint;
6mod legal_sampling;
7mod masks;
8mod unsafe_bytes;
9mod validate;
10
11impl EnvPool {
12    /// Debug event ring capacity configured for the pool.
13    pub fn debug_event_ring_capacity(&self) -> usize {
14        self.debug_config.event_ring_capacity
15    }
16
17    /// Render a single env to an ANSI string for debugging.
18    pub fn render_ansi(&self, env_index: usize, perspective: u8) -> String {
19        if env_index >= self.envs.len() {
20            return "Invalid env index".to_string();
21        }
22        if perspective > 1 {
23            return "Invalid perspective".to_string();
24        }
25        let env = &self.envs[env_index];
26        let p0 = perspective as usize;
27        let p1 = 1 - p0;
28        let state = &env.state;
29        let mut out = String::new();
30        out.push_str(&format!("Phase: {:?}\n", state.turn.phase));
31        out.push_str(&format!("Active: {}\n", state.turn.active_player));
32        out.push_str(&format!(
33            "P{} Level: {} Clock: {} Hand: {} Deck: {}\n",
34            p0,
35            state.players[p0].level.len(),
36            state.players[p0].clock.len(),
37            state.players[p0].hand.len(),
38            state.players[p0].deck.len()
39        ));
40        out.push_str(&format!(
41            "P{} Level: {} Clock: {} Hand: {} Deck: {}\n",
42            p1,
43            state.players[p1].level.len(),
44            state.players[p1].clock.len(),
45            state.players[p1].hand.len(),
46            state.players[p1].deck.len()
47        ));
48        out.push_str("Stage:\n");
49        out.push_str(&format!(
50            " P{}: {}\n",
51            p0,
52            Self::format_stage(&state.players[p0].stage)
53        ));
54        out.push_str(&format!(
55            " P{}: {}\n",
56            p1,
57            Self::format_stage(&state.players[p1].stage)
58        ));
59        if let Some(action) = &env.last_action_desc {
60            let hide_action = env.curriculum.enable_visibility_policies
61                && env.config.observation_visibility
62                    == crate::config::ObservationVisibility::Public
63                && env
64                    .last_action_player
65                    .map(|p| p != perspective)
66                    .unwrap_or(false);
67            if !hide_action {
68                out.push_str(&format!("Last action: {:?}\n", action));
69            }
70        }
71        out
72    }
73
74    fn format_stage(stage: &[crate::state::StageSlot; 5]) -> String {
75        let mut parts = Vec::with_capacity(stage.len());
76        for slot in stage {
77            if let Some(card) = slot.card {
78                parts.push(format!("{}:{:?}", card.id, slot.status));
79            } else {
80                parts.push("Empty".to_string());
81            }
82        }
83        format!("[{}]", parts.join(", "))
84    }
85}