Skip to main content

weiss_core/pool/helpers/
mod.rs

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