Skip to main content

weiss_core/env/
harness.rs

1use super::GameEnv;
2use crate::legal::{Decision, DecisionKind};
3use crate::state::{ChoiceOptionRef, ChoiceReason, ChoiceState, ChoiceZone};
4
5/// Install a synthetic choice state with paging for tests.
6pub fn install_choice_paging(env: &mut GameEnv, total: usize) {
7    assert!(
8        total <= u16::MAX as usize,
9        "choice paging total {total} exceeds u16::MAX ({})",
10        u16::MAX
11    );
12    let options = (0..total)
13        .map(|idx| ChoiceOptionRef {
14            card_id: (idx + 1) as u32,
15            instance_id: (idx + 1) as u32,
16            zone: ChoiceZone::WaitingRoom,
17            index: Some(idx as u16),
18            target_slot: None,
19        })
20        .collect::<Vec<_>>();
21    env.state.turn.choice = Some(ChoiceState {
22        id: 1,
23        reason: ChoiceReason::TriggerTreasureSelect,
24        player: 0,
25        options,
26        total_candidates: total as u16,
27        page_start: 0,
28        pending_trigger: None,
29    });
30    env.decision = Some(Decision {
31        player: 0,
32        kind: DecisionKind::Choice,
33        focus_slot: None,
34    });
35    env.update_action_cache();
36}
37
38/// Force a deck refresh for a player (test harness only).
39pub fn force_deck_refresh(env: &mut GameEnv, player: usize) {
40    let deck = std::mem::take(&mut env.state.players[player].deck);
41    env.state.players[player].waiting_room.extend(deck);
42    env.update_action_cache();
43}