Magic: The Gathering Rules Reference

This section provides a comprehensive reference to the Magic: The Gathering rules as implemented in Rummage. It serves as a bridge between the official comprehensive rules and our game engine implementation.

How Rules Are Organized

The Rummage documentation organizes Magic: The Gathering rules into three layers:

  1. MTG Rules Reference (this section) - A high-level explanation of the rules and mechanics with links to implementation details
  2. MTG Core Rules - Detailed implementation of fundamental rules shared by all formats
  3. Format-Specific Rules - Extensions and modifications for specific formats (e.g., Commander)

This layered approach ensures that common rules are documented once in the core layer, while format-specific variations are documented in their respective format sections.

Core Rules vs. Format Rules

Understanding the distinction between core rules and format rules is essential:

  • Core Rules: Universal mechanics that apply to all Magic: The Gathering games (turn structure, stack, zones, etc.)
  • Format Rules: Additional rules and modifications specific to a format (Commander damage, partner commanders, etc.)

In Rummage, both are implemented as composable ECS systems, allowing shared core systems with format-specific extensions.

Implementation Methodology

Our rules implementation follows a methodology designed for correctness, testability, and extensibility:

  1. Rule Extraction: Rules are extracted from the Comprehensive Rules
  2. System Design: Rules are modeled as composable Bevy ECS systems
  3. State Representation: Game state is represented as entities with components
  4. Event-Driven Logic: Rules are triggered by and produce game events
  5. Deterministic Execution: Rules execute deterministically for network play

Integration with Core Systems

The rules implementation integrates with several core systems:

Snapshot System

The Snapshot System works closely with the rules implementation to:

  • Capture game state at specific points in the turn structure
  • Ensure deterministic rule application for networked games
  • Enable replay and analysis of rule applications
  • Support testing of complex rule interactions

For more information on how snapshots are used in testing rule implementations, see Snapshot Testing.

Rules Categories

The MTG rules are broken down into the following main categories:

Game Structure Rules

Card Rules

  • Card Types - The various types of cards and their characteristics
  • Card States - Different states a card can be in (tapped, face-down, etc.)
  • Mana Costs - How mana costs work and are calculated

Gameplay Rules

  • Combat (Implementation) - Rules for attacking, blocking, and combat damage
  • Targeting - How targets are selected and validated
  • Effects - Different types of effects and how they're applied
  • Keywords - Standard keyword abilities and their implementations

Advanced Rules

Format-Specific Rules

This reference provides high-level explanations of format-specific rules. For detailed implementation details, refer to the format-specific documentation:

Note: Currently, only the Commander format is fully documented. Additional formats like Two-Headed Giant and Planechase may be added in the future.

Implementation Examples

Throughout the rules documentation, you'll find code examples showing how the rules are implemented in Rummage:

#![allow(unused)]
fn main() {
// Example: A system implementing state-based actions
pub fn check_state_based_actions(
    mut commands: Commands,
    mut creatures: Query<(Entity, &Creature, &Health)>,
    mut players: Query<(Entity, &Player)>,
    mut game_events: EventWriter<GameEvent>,
) {
    // Check for creatures with lethal damage
    for (entity, creature, health) in creatures.iter() {
        if health.damage >= creature.toughness {
            // Creature has lethal damage, destroy it
            commands.entity(entity).insert(Destroyed);
            game_events.send(GameEvent::CreatureDestroyed { entity });
        }
    }
    
    // Check for players with zero or less life
    for (entity, player) in players.iter() {
        if player.life <= 0 {
            game_events.send(GameEvent::PlayerLost { 
                player: entity,
                reason: LossReason::ZeroLife,
            });
        }
    }
    
    // Other state-based actions...
}
}

Rules Interactions

Magic: The Gathering is known for its complex rule interactions. The documentation explains how different rule systems interact:

  • How the stack interacts with state-based actions
  • How replacement effects modify zone changes
  • How continuous effects are applied in layers
  • How priority flows during complex game scenarios

Testing Rules Correctness

The Rummage engine extensively tests rules correctness:

  • Unit tests for individual rule applications
  • Integration tests for interactions between rule systems
  • Scenario tests for complex game states
  • Regression tests for previously identified issues

For more details on how rules are tested, see the Testing Overview.

Rules Implementation Resources

How to Use This Documentation

  • For a high-level overview of a rule, start with the relevant page in this MTG Rules section
  • For implementation details, follow the links to the MTG Core Rules section
  • For format-specific rules, check the format's dedicated rules documentation
  • For code examples, look at the implementation snippets provided throughout

Next: Comprehensive Rules Overview