pub struct GameEnv {Show 28 fields
pub db: Arc<CardDb>,
pub config: EnvConfig,
pub curriculum: CurriculumConfig,
pub state: GameState,
pub env_id: u32,
pub base_seed: u64,
pub episode_index: u32,
pub decision: Option<Decision>,
pub last_action_desc: Option<ActionDesc>,
pub last_action_player: Option<u8>,
pub last_illegal_action: bool,
pub last_engine_error: bool,
pub last_engine_error_code: EngineErrorCode,
pub last_perspective: u8,
pub pending_damage_delta: [i32; 2],
pub obs_buf: Vec<i32>,
pub replay_config: ReplayConfig,
pub replay_writer: Option<ReplayWriter>,
pub replay_actions: Vec<ActionDesc>,
pub replay_actions_raw: Vec<ActionDesc>,
pub replay_action_ids: Vec<u16>,
pub replay_action_ids_raw: Vec<u16>,
pub replay_events: Vec<ReplayEvent>,
pub replay_steps: Vec<StepMeta>,
pub recording: bool,
pub meta_rng: Rng64,
pub episode_seed: u64,
pub scratch_replacement_indices: Vec<usize>,
/* private fields */
}Expand description
A single Weiss Schwarz environment instance with deterministic RNG state.
Fields§
§db: Arc<CardDb>Shared card database backing this environment.
config: EnvConfigEnvironment configuration (reward, limits, visibility).
curriculum: CurriculumConfigCurriculum feature toggles for rules and mechanics.
state: GameStateCurrent game state.
env_id: u32Stable environment identifier within a pool.
base_seed: u64Base seed used to derive per-episode randomness.
episode_index: u32Episode counter for this environment.
decision: Option<Decision>Current decision, if the engine is waiting for an action.
last_action_desc: Option<ActionDesc>Last action applied in canonical form.
last_action_player: Option<u8>Player index that performed the last action.
last_illegal_action: boolWhether the last action was illegal.
last_engine_error: boolWhether the last step hit an engine error.
last_engine_error_code: EngineErrorCodeError code recorded for the last engine error.
last_perspective: u8Perspective used for the last emitted observation.
pending_damage_delta: [i32; 2]Pending damage deltas awaiting resolution per player.
obs_buf: Vec<i32>Scratch buffer holding the most recent observation.
replay_config: ReplayConfigReplay configuration controlling sampling and storage.
replay_writer: Option<ReplayWriter>Optional writer for replay output.
replay_actions: Vec<ActionDesc>Canonical action list for replay output.
replay_actions_raw: Vec<ActionDesc>Raw action list prior to sanitization.
replay_action_ids: Vec<u16>Canonical action ids for replay output.
replay_action_ids_raw: Vec<u16>Raw action ids prior to sanitization.
replay_events: Vec<ReplayEvent>Collected replay events.
replay_steps: Vec<StepMeta>Per-decision metadata for replay output.
recording: boolWhether replay recording is active.
meta_rng: Rng64RNG for non-gameplay metadata sampling.
episode_seed: u64Current episode seed.
scratch_replacement_indices: Vec<usize>Scratch buffer for slot replacement during play/move.
Implementations§
Source§impl GameEnv
impl GameEnv
Sourcepub fn apply_action_id(&mut self, action_id: usize) -> Result<StepOutcome>
pub fn apply_action_id(&mut self, action_id: usize) -> Result<StepOutcome>
Apply an action by id and return the resulting outcome.
This is the primary stepping entry point for RL-style loops.
Sourcepub fn apply_action_id_no_copy(
&mut self,
action_id: usize,
) -> Result<StepOutcome>
pub fn apply_action_id_no_copy( &mut self, action_id: usize, ) -> Result<StepOutcome>
Apply an action by id without copying the observation buffer.
The returned StepOutcome.obs will be empty; use output buffers instead.
Sourcepub fn apply_action(&mut self, action: ActionDesc) -> Result<StepOutcome>
pub fn apply_action(&mut self, action: ActionDesc) -> Result<StepOutcome>
Apply a canonical action descriptor.
Source§impl GameEnv
impl GameEnv
Sourcepub fn action_for_id(&self, action_id: usize) -> Option<ActionDesc>
pub fn action_for_id(&self, action_id: usize) -> Option<ActionDesc>
Decode an action id into a canonical descriptor, if legal.
Sourcepub fn legal_actions(&self) -> Vec<ActionDesc>
pub fn legal_actions(&self) -> Vec<ActionDesc>
Enumerate legal actions in canonical form for the current decision.
Source§impl GameEnv
impl GameEnv
Sourcepub fn action_mask(&self) -> &[u8] ⓘ
pub fn action_mask(&self) -> &[u8] ⓘ
Action mask for the current decision (1 = legal).
Sourcepub fn action_mask_bits(&self) -> &[u64]
pub fn action_mask_bits(&self) -> &[u64]
Bitset action mask for the current decision.
Sourcepub fn action_id_is_legal(&self, action_id: usize) -> bool
pub fn action_id_is_legal(&self, action_id: usize) -> bool
Whether an action id is legal for the current decision.
Sourcepub fn action_ids_cache(&self) -> &[u16]
pub fn action_ids_cache(&self) -> &[u16]
Cached legal action ids for the current decision.
Source§impl GameEnv
impl GameEnv
Sourcepub fn debug_event_ring_codes(&self, viewer: u8, out: &mut [u32]) -> u16
pub fn debug_event_ring_codes(&self, viewer: u8, out: &mut [u32]) -> u16
Snapshot debug event ring as compact numeric codes.
Sourcepub fn debug_event_ring_snapshot(&self, viewer: u8) -> Vec<ReplayEvent> ⓘ
pub fn debug_event_ring_snapshot(&self, viewer: u8) -> Vec<ReplayEvent> ⓘ
Snapshot debug event ring as full event records.
Source§impl GameEnv
impl GameEnv
Sourcepub fn validate_state(&self) -> Result<()>
pub fn validate_state(&self) -> Result<()>
Run expensive invariants checks over the full game state.
Intended for debug builds or diagnostics; returns a detailed error.
Source§impl GameEnv
impl GameEnv
Sourcepub fn new(
db: Arc<CardDb>,
config: EnvConfig,
curriculum: CurriculumConfig,
seed: u64,
replay_config: ReplayConfig,
replay_writer: Option<ReplayWriter>,
env_id: u32,
) -> Result<Self, EnvError>
pub fn new( db: Arc<CardDb>, config: EnvConfig, curriculum: CurriculumConfig, seed: u64, replay_config: ReplayConfig, replay_writer: Option<ReplayWriter>, env_id: u32, ) -> Result<Self, EnvError>
Construct a new environment and immediately reset it to a valid decision.
Validates deck lists and initializes replay/config caches.
§Examples
use std::sync::Arc;
use weiss_core::{CardDb, CurriculumConfig, EnvConfig, GameEnv};
use weiss_core::replay::ReplayConfig;
let mut env = GameEnv::new(
Arc::new(db),
config,
CurriculumConfig::default(),
0,
ReplayConfig::default(),
None,
0,
)?;
let outcome = env.apply_action_id(weiss_core::encode::PASS_ACTION_ID)?;Sourcepub fn new_or_panic(
db: Arc<CardDb>,
config: EnvConfig,
curriculum: CurriculumConfig,
seed: u64,
replay_config: ReplayConfig,
replay_writer: Option<ReplayWriter>,
env_id: u32,
) -> Self
pub fn new_or_panic( db: Arc<CardDb>, config: EnvConfig, curriculum: CurriculumConfig, seed: u64, replay_config: ReplayConfig, replay_writer: Option<ReplayWriter>, env_id: u32, ) -> Self
Compatibility helper for tests/benches.
Sourcepub fn reset(&mut self) -> StepOutcome
pub fn reset(&mut self) -> StepOutcome
Reset the environment and return a full observation.
Sourcepub fn reset_no_copy(&mut self) -> StepOutcome
pub fn reset_no_copy(&mut self) -> StepOutcome
Reset the environment without copying the observation buffer.
The returned StepOutcome.obs will be empty; use this when you
manage observation buffers externally (e.g. EnvPool outputs).
Sourcepub fn reset_with_episode_seed(&mut self, episode_seed: u64) -> StepOutcome
pub fn reset_with_episode_seed(&mut self, episode_seed: u64) -> StepOutcome
Reset the environment with an explicit episode seed.
Passing the same episode_seed with identical config/db yields the same
initial game state and first decision.
Sourcepub fn reset_with_episode_seed_no_copy(
&mut self,
episode_seed: u64,
) -> StepOutcome
pub fn reset_with_episode_seed_no_copy( &mut self, episode_seed: u64, ) -> StepOutcome
Reset the environment with an explicit seed, without copying obs.
Sourcepub fn canonical_events(&self) -> &[Event]
pub fn canonical_events(&self) -> &[Event]
Canonical event stream for the current episode.
Sourcepub fn decision_id(&self) -> u32
pub fn decision_id(&self) -> u32
Monotonic decision id for the current episode.
Sourcepub fn set_debug_config(&mut self, debug: DebugConfig)
pub fn set_debug_config(&mut self, debug: DebugConfig)
Update debug settings for this environment instance.
Sourcepub fn set_output_mask_enabled(&mut self, enabled: bool)
pub fn set_output_mask_enabled(&mut self, enabled: bool)
Enable or disable output action masks.
Sourcepub fn set_output_mask_bits_enabled(&mut self, enabled: bool)
pub fn set_output_mask_bits_enabled(&mut self, enabled: bool)
Enable or disable output action mask bits.
Source§impl GameEnv
impl GameEnv
Sourcepub fn finish_episode_replay(&mut self)
pub fn finish_episode_replay(&mut self)
Finalize and flush replay output for the current episode.
Source§impl GameEnv
impl GameEnv
Sourcepub fn add_modifier(
&mut self,
source: CardId,
target_player: u8,
target_slot: u8,
kind: ModifierKind,
magnitude: i32,
duration: ModifierDuration,
) -> Option<u32>
pub fn add_modifier( &mut self, source: CardId, target_player: u8, target_slot: u8, kind: ModifierKind, magnitude: i32, duration: ModifierDuration, ) -> Option<u32>
Add a temporary or permanent modifier to a stage slot.
Auto Trait Implementations§
impl Freeze for GameEnv
impl RefUnwindSafe for GameEnv
impl Send for GameEnv
impl Sync for GameEnv
impl Unpin for GameEnv
impl UnwindSafe for GameEnv
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more