Skip to main content

manabrew_engine/ability/effects/
game_draw_effect.rs

1use super::EffectContext;
2
3/// Resolve `SP$ GameDraw` — the game ends in a draw.
4///
5/// Mirrors Java `GameDrawEffect.java`.
6///
7/// # Card script examples
8/// ```text
9/// A:SP$ GameDraw
10/// ```
11/// Struct form of this effect so it can participate in the
12/// `SpellAbilityEffect` trait hierarchy — mirrors Java's
13/// `GameDrawEffect` class extending `SpellAbilityEffect`.
14#[manabrew_engine_macros::spell_effect(GameDrawEffect)]
15fn resolve(ctx: &mut EffectContext, _sa: &crate::spellability::SpellAbility) {
16    // All players lose — no winner
17    let all_players: Vec<_> = ctx.game.player_order.clone();
18    for &pid in &all_players {
19        ctx.game
20            .player_mark_lost(pid, crate::replacement::GameLossReason::IntentionalDraw);
21    }
22
23    ctx.game.game_over = true;
24    ctx.game.winner = None;
25}
26
27#[cfg(test)]
28mod tests {
29    use crate::ability::spell_ability_effect::SpellAbilityEffect;
30    use std::collections::HashMap;
31
32    use crate::ability::effects::EffectContext;
33    use crate::agent::PassAgent;
34    use crate::game::GameState;
35    use crate::ids::PlayerId;
36    use crate::mana::ManaPool;
37    use crate::spellability::SpellAbility;
38    use crate::trigger::handler::TriggerHandler;
39
40    #[test]
41    fn game_draw_ends_game_with_no_winner() {
42        let mut game = GameState::new(&["Alice", "Bob"], 20);
43        let p0 = PlayerId(0);
44
45        let sa = SpellAbility::new_simple(None, p0, "SP$ GameDraw");
46
47        let mut th = TriggerHandler::new();
48        let mut agents: Vec<Box<dyn crate::agent::PlayerAgent>> =
49            vec![Box::new(PassAgent), Box::new(PassAgent)];
50        let mut mp = vec![ManaPool::default(), ManaPool::default()];
51        let templates = HashMap::new();
52        let templates_variants = HashMap::new();
53        let token_fallback = HashMap::new();
54        let edition_dates: HashMap<String, String> = HashMap::new();
55        let mut rng_adapter = crate::game_rng::ThreadRngAdapter;
56        let mut ctx = EffectContext {
57            game: &mut game,
58            combat: None,
59            agents: &mut agents,
60            trigger_handler: &mut th,
61            token_templates: &templates,
62            token_art_variants: &templates_variants,
63            token_fallback: &token_fallback,
64            edition_dates: &edition_dates,
65            mana_pools: &mut mp,
66            parent_target_card: None,
67            rng: &mut rng_adapter,
68        };
69        super::GameDrawEffect::resolve(&mut ctx, &sa);
70
71        assert!(ctx.game.game_over);
72        assert_eq!(ctx.game.winner, None);
73        assert!(ctx.game.player(p0).has_lost);
74        assert!(ctx.game.player(PlayerId(1)).has_lost);
75    }
76}