GameEnv

Struct GameEnv 

Source
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: EnvConfig

Environment configuration (reward, limits, visibility).

§curriculum: CurriculumConfig

Curriculum feature toggles for rules and mechanics.

§state: GameState

Current game state.

§env_id: u32

Stable environment identifier within a pool.

§base_seed: u64

Base seed used to derive per-episode randomness.

§episode_index: u32

Episode 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: bool

Whether the last action was illegal.

§last_engine_error: bool

Whether the last step hit an engine error.

§last_engine_error_code: EngineErrorCode

Error code recorded for the last engine error.

§last_perspective: u8

Perspective 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: ReplayConfig

Replay 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: bool

Whether replay recording is active.

§meta_rng: Rng64

RNG for non-gameplay metadata sampling.

§episode_seed: u64

Current episode seed.

§scratch_replacement_indices: Vec<usize>

Scratch buffer for slot replacement during play/move.

Implementations§

Source§

impl GameEnv

Source

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.

Source

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.

Source

pub fn apply_action(&mut self, action: ActionDesc) -> Result<StepOutcome>

Apply a canonical action descriptor.

Source§

impl GameEnv

Source

pub fn action_for_id(&self, action_id: usize) -> Option<ActionDesc>

Decode an action id into a canonical descriptor, if legal.

Source

pub fn legal_actions(&self) -> Vec<ActionDesc>

Enumerate legal actions in canonical form for the current decision.

Source§

impl GameEnv

Source

pub fn action_mask(&self) -> &[u8]

Action mask for the current decision (1 = legal).

Source

pub fn action_mask_bits(&self) -> &[u64]

Bitset action mask for the current decision.

Whether an action id is legal for the current decision.

Source

pub fn action_ids_cache(&self) -> &[u16]

Cached legal action ids for the current decision.

Source§

impl GameEnv

Source

pub fn debug_event_ring_codes(&self, viewer: u8, out: &mut [u32]) -> u16

Snapshot debug event ring as compact numeric codes.

Source

pub fn debug_event_ring_snapshot(&self, viewer: u8) -> Vec<ReplayEvent>

Snapshot debug event ring as full event records.

Source§

impl GameEnv

Source

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

Source

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)?;
Source

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.

Source

pub fn reset(&mut self) -> StepOutcome

Reset the environment and return a full observation.

Source

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).

Source

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.

Source

pub fn reset_with_episode_seed_no_copy( &mut self, episode_seed: u64, ) -> StepOutcome

Reset the environment with an explicit seed, without copying obs.

Source

pub fn canonical_events(&self) -> &[Event]

Canonical event stream for the current episode.

Source

pub fn decision_id(&self) -> u32

Monotonic decision id for the current episode.

Source

pub fn set_debug_config(&mut self, debug: DebugConfig)

Update debug settings for this environment instance.

Source

pub fn set_output_mask_enabled(&mut self, enabled: bool)

Enable or disable output action masks.

Source

pub fn set_output_mask_bits_enabled(&mut self, enabled: bool)

Enable or disable output action mask bits.

Source§

impl GameEnv

Source

pub fn finish_episode_replay(&mut self)

Finalize and flush replay output for the current episode.

Source§

impl GameEnv

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.