Spaces:
Sleeping
Sleeping
File size: 2,854 Bytes
463f868 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | use crate::core::logic::*;
fn load_test_db() -> CardDatabase {
let paths = ["data/cards_compiled.json", "../data/cards_compiled.json"];
for path in paths {
if let Ok(json_str) = std::fs::read_to_string(path) {
return CardDatabase::from_json(&json_str).expect("Failed to parse CardDatabase");
}
}
panic!("Could not find cards_compiled.json in any of the expected locations");
}
#[ignore]
#[test]
fn test_strict_condition_logic_no_bypass() {
let mut state = GameState::default();
state.phase = Phase::Main;
let db = load_test_db();
// Reset bypass mode to ensure strictness
state.debug.debug_ignore_conditions = false;
let p0 = 0;
// Give enough energy to play any card
for _ in 0..10 { state.players[p0].energy_zone.push(40000); }
state.players[p0].tapped_energy_mask = 0;
// Put card 278 in hand (PL!HS-PR-019-PR)
state.players[p0].hand.push(4135);
// SETUP FAILURE: Put non-heart 04 cards on top of deck
state.players[p0].deck.clear();
state.players[p0].deck.push(1);
state.players[p0].deck.push(11);
state.players[p0].deck.push(12);
// Play card 278 (Action ID for hand 0, slot 0 is 1)
let res = state.step(&db, (ACTION_BASE_HAND + 0) as i32);
assert!(res.is_ok(), "Play should succeed with enough energy, res: {:?}", res);
// Check state: 3 cards should be in discard from the deck
assert_eq!(state.players[p0].discard.len(), 3);
// Buff should NOT be applied because cards were not heart 04 members
assert_eq!(state.players[p0].heart_buffs[0].get_color_count(4), 0, "Buff should not be applied if condition fails");
// SETUP SUCCESS
let mut state = GameState::default();
state.phase = Phase::Main;
state.players[p0].energy_zone = vec![40000; 10].into();
state.players[p0].tapped_energy_mask = 0;
state.players[p0].hand.push(4135);
state.players[p0].deck.push(4135);
state.players[p0].deck.push(4135);
state.players[p0].deck.push(4135);
let res = state.step(&db, (ACTION_BASE_HAND + 0) as i32);
assert!(res.is_ok());
// Buff SHOULD be applied
assert_eq!(state.players[p0].heart_buffs[0].get_color_count(4), 1);
}
#[test]
fn test_effect_dissipation_manual() {
let mut state = GameState::default();
state.phase = Phase::Main;
let p0 = 0;
// Manually add a buff
state.players[p0].blade_buffs[0] = 5;
assert_eq!(state.players[p0].blade_buffs[0], 5);
// Simulate Turn Start (which calls untap_all in Active Phase)
state.phase = Phase::Active;
let db = load_test_db();
state.do_active_phase(&db);
// Buff should be cleared
assert_eq!(state.players[p0].blade_buffs[0], 0, "Buff should be cleared during Active Phase");
}
|