How radar/mtg works
Main Components
• Card Definition & DSL
– CardBuilder DSL (lib/magic/card_builder.rb)
– Card modules under lib/magic/cards/*
• Core Domain Model
– Entities: Card, Permanent, Player, Game, Stack, Zone, Event
– Value objects: Mana, Cost, Counter, Filter, Target
• Engine & Runtime
– Game loop and phases (lib/magic/game/*.rb)
– Action handlers (lib/magic/actions/*)
– Stack processor (lib/magic/stack/*)
– Effect resolver (lib/magic/effects/*)
– Event broadcaster and listeners (lib/magic/events/*)
– Static & replacement abilities (lib/magic/abilities/*, lib/magic/static_ability.rb)
• Supporting Infrastructure
– Configuration & entrypoints: bin/console, bin/setup, Rakefile
– Test harness: RSpec suite under spec/
– Gem metadata: magic.gemspec, Bundler files (Gemfile, .tool-versions)
Relationships & Data Flows
• Card Registration Flow
[Card Definitions] → (via DSL) → [Card Registry]
• Game Initialization
[Player modules] + [Card Registry] → instantiate → [Game State]
• Turn & Phase Loop
[Game Engine] triggers → [Phase Handlers] → [Action Prompts]
Player invokes → [Action objects] → pushed onto → [Stack]
• Stack Resolution
[Stack] pops → [Effect Resolver] applies → modifies → [Game State]
Emitted → [Event Bus] → triggers → [Triggered Abilities] / [Replacement Effects]
• Continuous Effects
Monitored by → [Static Ability Manager] → adjusts attributes on → [Permanents]
Architectural Patterns
• Domain-Driven Design – clear separation of domain entities (cards, players, zones) vs. engine logic
• Event-Driven – game state changes emit events consumed by triggered abilities and replacement effects
• Strategy & Polymorphism – abilities, costs, effects, event handlers implemented as interchangeable classes/modules
• DSL Extension Points – adding new cards boils down to new Ruby files under lib/magic/cards
Technologies & Frameworks
• Ruby 3.x – core language
• Bundler & Gem – project packaging (Gemfile, magic.gemspec)
• RSpec – automated testing (spec/ directory)
• Rake – build & test tasks