weiss_core/env/actions/
decode.rs

1use crate::legal::ActionDesc;
2
3use super::super::GameEnv;
4
5impl GameEnv {
6    /// Decode an action id into a canonical descriptor, if legal.
7    pub fn action_for_id(&self, action_id: usize) -> Option<ActionDesc> {
8        if !self.action_id_is_legal(action_id) {
9            return None;
10        }
11        crate::encode::action_desc_for_id(action_id)
12    }
13
14    /// Enumerate legal actions in canonical form for the current decision.
15    pub fn legal_actions(&self) -> Vec<ActionDesc> {
16        let mut out = Vec::with_capacity(self.action_cache.last_action_ids.len());
17        for &id in self.action_cache.last_action_ids.iter() {
18            if let Some(action) = crate::encode::action_desc_for_id(id as usize) {
19                out.push(action);
20            }
21        }
22        out
23    }
24}