enjine 0.2.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +66 -1
  3. data/README.md +2 -1
  4. data/SUPPORTED.md +4 -4
  5. data/docs/ARCHITECTURE.md +2 -0
  6. data/docs/DESIGN.md +12 -5
  7. data/docs/MECHANICS_COVERAGE.md +32 -4
  8. data/docs/guides/api.md +51 -0
  9. data/docs/guides/card-data-format.md +58 -1
  10. data/docs/guides/deck-builder.md +18 -0
  11. data/docs/plans/commander.md +63 -0
  12. data/docs/plans/dsl-gaps.md +76 -0
  13. data/docs/reference/decisions.md +5 -1
  14. data/docs/reference/effects.md +12 -9
  15. data/docs/reference/triggers.md +3 -1
  16. data/lib/enjine/actions/cast.rb +12 -4
  17. data/lib/enjine/card_definition.rb +39 -3
  18. data/lib/enjine/cli/text.rb +23 -1
  19. data/lib/enjine/cli.rb +2 -1
  20. data/lib/enjine/color_identity.rb +38 -0
  21. data/lib/enjine/decisions/commander_zone.rb +36 -0
  22. data/lib/enjine/deck.rb +73 -14
  23. data/lib/enjine/deck_builder.rb +62 -18
  24. data/lib/enjine/engine/casting/alt_casting.rb +9 -0
  25. data/lib/enjine/engine/casting/casting.rb +19 -0
  26. data/lib/enjine/engine/casting/permissions.rb +19 -14
  27. data/lib/enjine/engine/characteristics.rb +29 -12
  28. data/lib/enjine/engine/commander.rb +125 -0
  29. data/lib/enjine/engine/copies.rb +16 -9
  30. data/lib/enjine/engine/damage.rb +3 -1
  31. data/lib/enjine/engine/durations.rb +47 -0
  32. data/lib/enjine/engine/emblems.rb +1 -1
  33. data/lib/enjine/engine/faces.rb +2 -0
  34. data/lib/enjine/engine/pregame.rb +1 -0
  35. data/lib/enjine/engine/priority.rb +1 -0
  36. data/lib/enjine/engine/rules.rb +3 -2
  37. data/lib/enjine/engine/state_based_actions.rb +9 -0
  38. data/lib/enjine/engine/triggers.rb +16 -9
  39. data/lib/enjine/engine/zones.rb +19 -2
  40. data/lib/enjine/events.rb +4 -1
  41. data/lib/enjine/format.rb +53 -0
  42. data/lib/enjine/fuzz.rb +17 -0
  43. data/lib/enjine/game.rb +4 -3
  44. data/lib/enjine/mechanics/abilities/double_counters.rb +1 -1
  45. data/lib/enjine/mechanics/abilities/play_permissions.rb +3 -2
  46. data/lib/enjine/mechanics/abilities/replacement_effects.rb +2 -1
  47. data/lib/enjine/mechanics/abilities/static.rb +7 -0
  48. data/lib/enjine/mechanics/card_spec.rb +54 -12
  49. data/lib/enjine/mechanics/effects/become.rb +35 -13
  50. data/lib/enjine/mechanics/effects/copy.rb +7 -4
  51. data/lib/enjine/mechanics/effects/gain_control.rb +6 -3
  52. data/lib/enjine/mechanics/effects/return_to_battlefield.rb +25 -6
  53. data/lib/enjine/mechanics/filters/base.rb +19 -2
  54. data/lib/enjine/mechanics/filters/stack.rb +1 -1
  55. data/lib/enjine/mechanics/triggers/base.rb +14 -3
  56. data/lib/enjine/mechanics/triggers/casting.rb +1 -1
  57. data/lib/enjine/mechanics/triggers/tap_and_counters.rb +21 -5
  58. data/lib/enjine/mechanics/triggers/zone_changes.rb +1 -1
  59. data/lib/enjine/mechanics/values.rb +10 -7
  60. data/lib/enjine/mechanics.rb +5 -0
  61. data/lib/enjine/player.rb +2 -1
  62. data/lib/enjine/rules_monitor.rb +29 -3
  63. data/lib/enjine/setup.rb +10 -4
  64. data/lib/enjine/snapshot/player_checks.rb +47 -0
  65. data/lib/enjine/snapshot.rb +4 -1
  66. data/lib/enjine/state.rb +33 -14
  67. data/lib/enjine/steps.rb +10 -1
  68. data/lib/enjine/version.rb +1 -1
  69. data/lib/enjine/view.rb +18 -1
  70. data/lib/enjine.rb +2 -0
  71. metadata +7 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 942c6815c091c8bdab9888b68b9b0e612baa78b548342488c863dc1e830a2bf5
4
- data.tar.gz: 1a03106084654c2ab19cb708526552857230066e0fc0cf0c2fd860a10cbbb992
3
+ metadata.gz: dd2564d74c91b41b13b5d630d52be4e837af582d6b030ce29658951dc1cc1061
4
+ data.tar.gz: 4d7a8e15789f58b94e3033016a1c380b8bd978710f59a7b31010145b1b34b4b7
5
5
  SHA512:
6
- metadata.gz: d99c29a1802d4f66b4256d6708d2cc70fb3f8570cb48edf0422faef7b522bf204e959b7247faeadba4ebfd2d5c6b51422510e78ee0c3a24a5bd678bba919b6c9
7
- data.tar.gz: 9757f33c16fc536bc441401c44194592c4ee3875a4db61765128f55d25b906aef61511fefb377272e5d4dcad9edcab9212b13e33a0be17a821674072651b809e
6
+ metadata.gz: 4f5476cb7fee29707c027d5b3bfeb9c9d29446faa76dd67999ce6464b1979c649048916d467fbc2db56bdcd6ee2716dacd7c78c73e694d30c6e9c2b3bc34c78f
7
+ data.tar.gz: f9ac926eb54afa0426bb836a44d258e779e98f9d15a91af7a1e9faac05aac9720a4027a74da5cd6bfb3f69a460062ce5dd9307adf347f9fe5d0e7645b79e17a4
data/CHANGELOG.md CHANGED
@@ -8,6 +8,68 @@ change the public API; the stable surface is described in
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.4.1] - 2026-11-22
12
+
13
+ Includes 0.4.0, which was tagged but never published to RubyGems.
14
+
15
+ ### Added
16
+ - `become` takes `set_types` ("it's an artifact, not a creature", CR 205.1a), `"creature_types": []` ("loses
17
+ all creature types") and `all_creature_types: true` (CR 205.3d).
18
+ - `return_to_battlefield` takes `as`: the `become` changes it has from the moment it enters ("It's an
19
+ enchantment. (It's not a creature.)", CR 614.1c), seen by abilities that trigger on it entering.
20
+
21
+ ### Changed
22
+ - Faster legal options and state-based actions, same behaviour: a random-agent game runs about 2.3x as many
23
+ decisions per second on the fixture pool and 1.7x on the real-card fixtures. Off-board characteristics are
24
+ memoized per decision; cards that can't be played or activated from their zone are skipped
25
+ (`CardDefinition#plays_itself?`, `#activation_zones`); the token scan and graveyard trigger watch are cached
26
+ while no object appears, moves or ceases to exist.
27
+
28
+ ### Fixed
29
+ - The trigger condition `{"triggering": filter}` matches a permanent that left the battlefield with the card
30
+ types it last had ("if it was a creature", CR 603.10a), not its printed ones.
31
+ - The rules monitor's power/toughness check (CR 613.4c) leaves out permanents whose card types were set.
32
+
33
+ ## [0.4.0] - 2026-11-21
34
+
35
+ ### Added
36
+ - `counters_placed` takes `by: you | opponent` ("whenever you put counters", CR 122.6a); the
37
+ `counters_changed` event carries `by`, the player who put them.
38
+ - Filters take `owner: you | opponent` ("a creature you own", "creatures you control but don't own",
39
+ CR 108.3), in targets, selectors and statics.
40
+ - Card specs take `keywords`, `not_subtypes`, `power`, `toughness` and `layout` ("a creature card with
41
+ flying", "a non-Avatar card", "power 1 or less", "a card that has an Adventure").
42
+ - Durations counted in your own turns: `become_copy` `until_your_next_turn`, `gain_control`
43
+ `end_of_your_next_turn`, `play_permission` `until_your_next_end_step` (CR 611.2a).
44
+
45
+ ### Changed
46
+ - `owner` is refused, with a validation error, where a filter matches characteristics only (card specs
47
+ in zone-change triggers, cost modifiers, replacement effects, counted values), instead of being ignored.
48
+
49
+ ## [0.3.0] - 2026-11-20
50
+
51
+ ### Added
52
+ - Duel Commander (CR 903): `Enjine::Setup.new(alice, bob, format: :duel_commander)`
53
+ (`Enjine::Format`). Commanders start in the command zone, players start at 40 life,
54
+ a commander is cast from the command zone with `via: "command"` and pays the commander
55
+ tax, a new `commander_zone` decision lets its owner return it to the command zone
56
+ (903.9a–b), and 21 combat damage from one commander loses the game (reason
57
+ `"commander_damage"`).
58
+ - Deck documents take `"commander"`. `Deck#errors(format)`, `Deck#valid?(format)` and
59
+ `Player#ready?(format)` check a deck against a format. Commander decks need exactly
60
+ 100 cards, singleton, and color identity.
61
+ - `CardDefinition#color_identity`, derived from the card's data across all faces;
62
+ the card field `color_identity` overrides it.
63
+ - `DeckBuilder#build(commander:)` builds Duel Commander decks; `Fuzz.random_commander_deck`;
64
+ `rake fuzz[games,seed,duel_commander]`; the CLI's `--format`.
65
+ - Views show the command zone's commanders and, per player, `commander`,
66
+ `commander_tax` and `commander_damage`.
67
+
68
+ ### Changed
69
+ - Only emblems' abilities function from the command zone (CR 113.6, 114.4); the
70
+ command zone may now also hold commanders.
71
+ - `State::STARTING_LIFE` is gone: starting life comes from the format.
72
+
11
73
  ## [0.2.0] - 2026-11-12
12
74
 
13
75
  ### Added
@@ -52,6 +114,9 @@ change the public API; the stable surface is described in
52
114
  - `enjine` CLI: hot-seat and random play, `--validate`, `--verify`,
53
115
  `--random-deck`, save and load.
54
116
 
55
- [Unreleased]: https://github.com/thisiscetin/enjine/compare/v0.2.0...HEAD
117
+ [Unreleased]: https://github.com/thisiscetin/enjine/compare/v0.4.1...HEAD
118
+ [0.4.1]: https://github.com/thisiscetin/enjine/compare/v0.4.0...v0.4.1
119
+ [0.4.0]: https://github.com/thisiscetin/enjine/compare/v0.3.0...v0.4.0
120
+ [0.3.0]: https://github.com/thisiscetin/enjine/compare/v0.2.0...v0.3.0
56
121
  [0.2.0]: https://github.com/thisiscetin/enjine/compare/v0.1.0...v0.2.0
57
122
  [0.1.0]: https://github.com/thisiscetin/enjine/releases/tag/v0.1.0
data/README.md CHANGED
@@ -12,7 +12,8 @@ simulations, bots and reinforcement learning, or for a game client.
12
12
  current Standard-legal sets. Mechanics found only outside Standard (morph,
13
13
  madness, infect, ...) are out of scope until a Standard card needs them. The
14
14
  [mechanics coverage](docs/MECHANICS_COVERAGE.md) page has the details and the
15
- numbers.
15
+ numbers. Games are constructed by default; two-player **Duel Commander** (CR 903)
16
+ is a `format:` away (`--format duel_commander` in the CLI).
16
17
 
17
18
  - **Strict rules.** Turn structure, priority, the stack, layers, replacement
18
19
  effects, combat, state-based actions, London mulligan. Code and tests cite rule
data/SUPPORTED.md CHANGED
@@ -258,8 +258,8 @@ Rules version: Comprehensive Rules effective 2026-11-06.
258
258
  | [`another_counter`](docs/reference/effects.md#another_counter) | 122.1, 122.6 | For each referenced permanent, the controller chooses a kind of counter already on it (asked only when there are several kinds) and puts one more counter of that kind on it. |
259
259
  | [`assimilate`](docs/reference/effects.md#assimilate) | 701.72a, 701.72b, 701.72c, 607.2a, 205.1b, 613.1b, 613.1d, 614.12a | Assimilate each referenced permanent or permanent card: you gain control of it (or put it onto the battlefield under your control) with a +1/+1 counter, and it becomes a Borg artifact creature while it stays on the battlefield. `for`: only cards matching a card spec; `choose: true`: you choose one of them. |
260
260
  | [`attach`](docs/reference/effects.md#attach) | 701.3a, 701.3b, 701.3c, 301.5c | Attach this Aura or Equipment (the ability's source), or the `attachment` (e.g. a token an earlier effect created, {"result": n}), to the referenced permanent. Nothing happens if it can't legally be attached to it, if it's already attached to it, or if the attachment has left the battlefield. |
261
- | [`become`](docs/reference/effects.md#become) | 611.2a, 611.2b, 611.2c, 613.1d, 613.1e, 613.1f, 613.4b, 613.7b, 205.1a, 205.1b, 301.7b, 514.2 | Each referenced permanent becomes what the parameters say, for `duration` (end_of_turn, default; until_your_next_turn: until your next turn begins; indefinite: as long as it stays on the battlefield; while_source_on_battlefield: for as long as this effect's source remains on the battlefield; while_you_control_source: for as long as you control it): it has the card `types`, `supertypes` and `subtypes` in addition to its other types (layer 4, "becomes an artifact creature"), its creature types are exactly `creature_types` (layer 4), its colors are `colors` (layer 5), with `loses_abilities: true` it loses all the abilities it had (layer 6; abilities granted later, keyword counters put on it later and this effect's own `keywords` and `abilities` stay, CR 613.7), it has the `keywords` and `abilities` (layer 6: triggered, activated, mana, play_from or additional_land_plays abilities) and its base power and toughness are `base_power_toughness` (layer 7b). A permanent that becomes a creature has its printed power and toughness (a Vehicle's), or 0/0. |
262
- | [`become_copy`](docs/reference/effects.md#become_copy) | 707.2, 707.4, 613.2a, 613.7, 611.2a, 514.2 | Each referenced permanent becomes a copy of the (first) object `of` refers to, with the `except` modifications, until end of turn (default) or for as long as it stays on the battlefield (`duration: "permanent"`). It keeps its counters, status and other effects; nothing enters or leaves, so no enter or leave abilities trigger. Several copy effects apply in timestamp order. |
261
+ | [`become`](docs/reference/effects.md#become) | 611.2a, 611.2b, 611.2c, 613.1d, 613.1e, 613.1f, 613.4b, 613.7b, 205.1a, 205.1b, 301.7b, 514.2 | Each referenced permanent becomes what the parameters say, for `duration` (end_of_turn, default; until_your_next_turn: until your next turn begins; indefinite: as long as it stays on the battlefield; while_source_on_battlefield: for as long as this effect's source remains on the battlefield; while_you_control_source: for as long as you control it): it has the card `types`, `supertypes` and `subtypes` in addition to its other types (layer 4, "becomes an artifact creature"; with `set_types` its card types are exactly those first, "it's an enchantment, not a creature", and subtypes of a card type it loses go), its creature types are exactly `creature_types` ([] for "loses all creature types"; `all_creature_types: true` for "all creature types") (layer 4), its colors are `colors` (layer 5), with `loses_abilities: true` it loses all the abilities it had (layer 6; abilities granted later, keyword counters put on it later and this effect's own `keywords` and `abilities` stay, CR 613.7), it has the `keywords` and `abilities` (layer 6: triggered, activated, mana, play_from or additional_land_plays abilities) and its base power and toughness are `base_power_toughness` (layer 7b). A permanent that becomes a creature has its printed power and toughness (a Vehicle's), or 0/0. |
262
+ | [`become_copy`](docs/reference/effects.md#become_copy) | 707.2, 707.4, 613.2a, 613.7, 611.2a, 514.2 | Each referenced permanent becomes a copy of the (first) object `of` refers to, with the `except` modifications, until end of turn (default), until your next turn (`until_your_next_turn`) or for as long as it stays on the battlefield (`duration: "permanent"`). It keeps its counters, status and other effects; nothing enters or leaves, so no enter or leave abilities trigger. Several copy effects apply in timestamp order. |
263
263
  | [`become_saddled`](docs/reference/effects.md#become_saddled) | 702.171a, 702.171b | Each referenced permanent (default: this one) becomes saddled until end of turn (filters: `"saddled": true`). |
264
264
  | [`behold`](docs/reference/effects.md#behold) | 701.4a, 701.4b, 118.3 | You behold an object matching the card spec `card`: reveal such a card from your hand or choose such a permanent you control. Under `may`, "yes" is offered only when there is one. |
265
265
  | [`bite`](docs/reference/effects.md#bite) | 120.3, 120.4, 608.2b | Each creature referenced by `from` deals damage equal to its power to each creature, planeswalker or player referenced by `to` (one damage event per source; not combat damage, and nothing is dealt back). |
@@ -319,7 +319,7 @@ Rules version: Comprehensive Rules effective 2026-11-06.
319
319
  | [`mill`](docs/reference/effects.md#mill) | 701.17a | Each referenced player puts the top `amount` cards of their library into their graveyard (default: you). |
320
320
  | [`pay`](docs/reference/effects.md#pay) | 118.12, 118.12a, 118.3, 119.4, 605.3a, 701.67a, 701.67c | You may pay `cost` (a list of costs: mana, life, discarding, sacrificing, a `one_of` choice, ...) as it resolves; `mana`, `life` and `waterbend` are shorthands for one cost. If you do, `then` happens; if you don't, `otherwise`. Paying mana works like paying a spell's cost (mana abilities may be activated; a `waterbend` cost may also be paid by tapping artifacts and creatures, CR 701.67a); a cost that can't be paid can't be chosen (CR 118.3). For another player paying, see `counter_unless_pays`. |
321
321
  | [`phase_out`](docs/reference/effects.md#phase_out) | 702.26a, 702.26b, 702.26d, 702.26g, 702.26h, 502.1, 506.4 | Each referenced permanent phases out, with the Auras and Equipment attached to it (indirectly). It phases in during the untap step of the player who controlled it as it phased out. Phasing isn't a zone change: no enters or leaves triggers. |
322
- | [`play_permission`](docs/reference/effects.md#play_permission) | 611.2a, 601.3, 305.1, 400.7, 514.2, 601.2f, 108.3, 406.3b, 609.4b | A player may play (`play: "play"`, default) or cast (`"cast"`) each referenced exiled card matching `for`/`not_types`, paying its costs and following timing rules, for `duration`: end_of_turn (default), end_of_your_next_turn or while_exiled. With `choose: "one_per_owner"` only one chosen card per owner. `to_player`: who may play it, "controller" (default, the effect's controller), "owner" (the card's owner) or a player selector (a face-down card: only someone who may look at it). `cost_increase`: spells cast this way cost that much generic mana more. `any_mana_type: true`: mana of any type can be spent to cast those spells. |
322
+ | [`play_permission`](docs/reference/effects.md#play_permission) | 611.2a, 601.3, 305.1, 400.7, 514.2, 601.2f, 108.3, 406.3b, 609.4b | A player may play (`play: "play"`, default) or cast (`"cast"`) each referenced exiled card matching `for`/`not_types`, paying its costs and following timing rules, for `duration`: end_of_turn (default), end_of_your_next_turn, until_your_next_end_step or while_exiled. With `choose: "one_per_owner"` only one chosen card per owner. `to_player`: who may play it, "controller" (default, the effect's controller), "owner" (the card's owner) or a player selector (a face-down card: only someone who may look at it). `cost_increase`: spells cast this way cost that much generic mana more. `any_mana_type: true`: mana of any type can be spent to cast those spells. |
323
323
  | [`player_rule`](docs/reference/effects.md#player_rule) | 702.11c, 115.4, 508.1c, 402.2, 514.1, 615.1, 615.1a, 704.5a, 104.3b, 701.21a, 614.17b, 101.2, 601.3, 701.6a, 119.7, 602.5, 615.12, 702.16b, 702.16e, 702.16k, 611.2a, 514.2 | Each referenced player (default you) gets `rule` for the `duration`: end_of_turn (default) or until_your_next_turn (until the controller's next turn begins). Rules: hexproof, cant_attack, no_max_hand_size, prevent_all_damage, cant_lose_for_life, cant_cast, cant_cast_except_from_hand, spells_cant_be_countered, abilities_cant_be_countered, cant_gain_life, cant_activate, damage_cant_be_prevented, combat_damage_cant_be_prevented, protection_from_opponents. |
324
324
  | [`plot`](docs/reference/effects.md#plot) | 702.170c, 702.170d, 406.1 | Each referenced card or spell is exiled (if it isn't already) and becomes plotted: its owner may cast it from exile without paying its mana cost during their main phase while the stack is empty, on any later turn (cast option `via: "plotted"`). |
325
325
  | [`prepare`](docs/reference/effects.md#prepare) | 723.3a, 723.3c | Each referenced permanent (default: this one) becomes prepared, if it has a prepare spell and isn't prepared already: its controller creates a copy of the prepare spell in exile and may cast that copy while the permanent stays prepared. Casting it unprepares the permanent. |
@@ -333,7 +333,7 @@ Rules version: Comprehensive Rules effective 2026-11-06.
333
333
  | [`remove_counters`](docs/reference/effects.md#remove_counters) | 122.8 | Remove up to `amount` counters named `counter` from each referenced permanent. |
334
334
  | [`remove_damage`](docs/reference/effects.md#remove_damage) | 120.6, 514.2 | Remove all damage marked on each referenced permanent. |
335
335
  | [`return_choice`](docs/reference/effects.md#return_choice) | 101.4, 400.7, 608.2c | Each referenced player (default: you) returns `count` (default 1; "any": any number) permanents they control matching `filter` to their owners' hands, chosen by them in turn order starting with the active player (not targeted); all move at once. |
336
- | [`return_to_battlefield`](docs/reference/effects.md#return_to_battlefield) | 400.7, 400.4a, 110.2, 111.8, 603.7c, 614.1c, 122.6, 712.11a, 712.11b | Put each referenced card that is in exile or a graveyard onto the battlefield under its owner's control (`under: "you"`: under the controller's), tapped if `tapped: true`. A card that is no longer in the zone it was expected in, or isn't a permanent card, stays where it is. `transformed: true`: it enters with its back face up; a card that isn't double-faced, or whose back face isn't a permanent, stays where it is. |
336
+ | [`return_to_battlefield`](docs/reference/effects.md#return_to_battlefield) | 400.7, 400.4a, 110.2, 111.8, 603.7c, 614.1c, 122.6, 712.11a, 712.11b, 205.1a | Put each referenced card that is in exile or a graveyard onto the battlefield under its owner's control (`under: "you"`: under the controller's), tapped if `tapped: true`. A card that is no longer in the zone it was expected in, or isn't a permanent card, stays where it is. `transformed: true`: it enters with its back face up; a card that isn't double-faced, or whose back face isn't a permanent, stays where it is. `as`: what it is as it enters, for as long as it stays (the `become` changes, without abilities): "It's an enchantment. (It's not a creature.)" is `{"set_types": ["enchantment"]}`; abilities that trigger on it entering see it so. |
337
337
  | [`return_to_hand`](docs/reference/effects.md#return_to_hand) | 400.6, 404.1, 608.2b | Return each referenced permanent, spell ("return target spell to its owner's hand"), or card in a graveyard or exile ("target creature card from your graveyard"), to its owner's hand. |
338
338
  | [`reveal_until`](docs/reference/effects.md#reveal_until) | 701.20a, 401.4, 400.7j | Reveal cards from the top of your library until `count` (an amount, default 1) cards matching `for` are revealed (or the library runs out). Put those into `put` (`tapped` onto the battlefield, under your control) and the rest to `rest` (default the bottom in a random order). |
339
339
  | [`roll_dice`](docs/reference/effects.md#roll_dice) | 706.1, 706.1a, 706.2, 706.3a, 608.2c | You roll `amount` dice (default 1) with `sides` sides (default 6). The total of the results is this effect's amount: {"this_way": n} in later effects and conditions (a results table is effects with an `if` on it). |
data/docs/ARCHITECTURE.md CHANGED
@@ -19,6 +19,7 @@ lib/enjine/
19
19
  card_definition.rb # immutable, validated blueprint built from a data Hash
20
20
  catalog.rb # id -> CardDefinition, conflict detection
21
21
  deck.rb player.rb setup.rb # decklists, players, compiled pairings
22
+ format.rb color_identity.rb # game formats (constructed, duel_commander); CR 903.4 color identity
22
23
 
23
24
  mechanics/ # ONE PLACE PER MECHANIC: <category>/<mechanic>.rb, all registered primitives
24
25
  types/ supertypes/ subtypes/ card types, supertypes, subtypes (permanent_types spell_types land saga auras_and_equipment ...)
@@ -50,6 +51,7 @@ lib/enjine/
50
51
  state_based_actions.rb # CR 704 and game end (CR 104)
51
52
  characteristics.rb # CR 613 layer pipeline for P/T, continuous effects, cleanup
52
53
  rules.rb copies.rb faces.rb ... # player rules and control; copies (CR 707); faces; sagas, phasing, speed ...
54
+ commander.rb # CR 903 (Duel Commander): command zone, tax, 903.9 returns, commander damage
53
55
  steps.rb # 12 step objects with turn-based actions
54
56
  events.rb # typed, serializable events + per-viewer redaction
55
57
  decisions/ # one class per decision kind
data/docs/DESIGN.md CHANGED
@@ -9,11 +9,18 @@ agents in a separate project later) drive it through an atomic decision API.
9
9
 
10
10
  - **Standard.** The target is every mechanic on the cards of the current
11
11
  Standard-legal sets, plus the core rules (CR 1–6) every game needs. Mechanics
12
- found only on cards outside Standard, multiplayer and casual variants are out of
13
- scope until a Standard card needs them. New Standard sets add mechanics; rotated
14
- sets keep theirs.
15
- - Two-player constructed: 20 life, deck ≥ 60 cards, max 4 copies of a card
16
- (basic lands and "any number" cards exempt). No sideboard tracking.
12
+ found only on cards outside Standard and multiplayer variants are out of scope
13
+ until a Standard card needs them. New Standard sets add mechanics; rotated sets
14
+ keep theirs.
15
+ - Two-player constructed by default: 20 life, deck ≥ 60 cards, max 4 copies of a
16
+ card (basic lands and "any number" cards exempt). No sideboard tracking.
17
+ - **Duel Commander** (CR 903, two players) is in scope as a game-setup variant,
18
+ chosen with `Setup.new(..., format: :duel_commander)` (`Enjine::Format`): 40
19
+ life, 100-card singleton decks led by a commander, the command zone, commander
20
+ tax, returning to the command zone and 21 commander damage. Which *card*
21
+ mechanics exist is still decided by Standard; partner, companion and cards that
22
+ refer to "your commander" wait for a card that needs them. See
23
+ [plans/commander.md](plans/commander.md).
17
24
  - Single games, start to finish. No best-of-3 / match object.
18
25
  - The engine knows **no cards**: every card arrives as data, in a deck document or a
19
26
  `DeckBuilder` pool. The test and fuzz cards live in `spec/fixtures/cards/`.
@@ -30,8 +30,9 @@ Comprehensive Rules (measured by the rule numbers the code implements and cites,
30
30
  face-down cards (CR 708), madness, delve, persist, undying, infect, toxic,
31
31
  ninjutsu, cumulative upkeep, echo, bestow, mutate, split and flip cards,
32
32
  levelers, Prototype, Cases, day/night, the monarch and the initiative.
33
- - Battles and dungeons; multiplayer and casual variants (Commander, Planechase,
34
- Archenemy, Conspiracy); ante; matches and sideboarding.
33
+ - Battles and dungeons; multiplayer and casual variants (multiplayer Commander,
34
+ Planechase, Archenemy, Conspiracy); ante; matches and sideboarding. Two-player
35
+ **Duel Commander** is supported (CR 903, see below).
35
36
 
36
37
  A card that uses an unsupported mechanic can't be written: validation rejects it
37
38
  with an error naming the unknown key. Some older keywords can still be written
@@ -343,7 +344,8 @@ These rules cut across every mechanic. All numbers follow the 2026-11-06 text.
343
344
  | 704.5y | A battle with an illegal protector is reassigned or goes to the graveyard | M5 |
344
345
  | 704.5z | Multiple Roles from the same controller on one permanent: only the newest stays | M5 |
345
346
  | 704.5aa | A controller of a start-your-engines! permanent who has no speed gets speed 1 | M5 |
346
- | 704.6a–f | Variant SBAs (Two-Headed Giant, Commander, Archenemy, Planechase) | OOS |
347
+ | 704.6c | Commander: 21 or more combat damage from one commander loses the game (903.10a) | ✓ |
348
+ | 704.6a–b, d–f | Other variant SBAs (Two-Headed Giant, Archenemy, Planechase) | OOS |
347
349
 
348
350
  ---
349
351
 
@@ -648,10 +650,36 @@ replacement/prevention (614–616), "dies" and leaves-the-battlefield triggers
648
650
 
649
651
  ---
650
652
 
653
+ ## Commander (903)
654
+
655
+ Two-player Duel Commander, chosen with `format: :duel_commander` (`Enjine::Format`, `Engine::Commander`).
656
+
657
+ | CR | Rule | Status |
658
+ | --- | --- | --- |
659
+ | 903.3 | A commander is a legendary creature, Vehicle or Spacecraft with P/T; the designation belongs to the card (copies and tokens aren't commanders) | ✓ |
660
+ | 903.3 | Cards that say "can be your commander" | OOS until a card needs it |
661
+ | 903.4, 903.4c–e | Color identity from the card's data (never its text), every face included; `color_identity` overrides | ✓ |
662
+ | 903.4b | Choosing a commander's color before the game | OOS |
663
+ | 903.5a–d | Exactly 100 cards, singleton (basic lands exempt), color identity, basic land types | ✓ |
664
+ | 903.6 | Commanders start in the command zone; their abilities don't function there (113.6) | ✓ |
665
+ | 903.7 | 40 starting life | ✓ |
666
+ | 903.8 | Casting a commander from the command zone, {2} more per earlier cast | ✓ |
667
+ | 903.9a | A commander put into a graveyard or exile may go to the command zone (state-based action, a choice) | ✓ |
668
+ | 903.9b | A commander that would go to its owner's hand or library may go to the command zone instead | ✓ (offered right after the move, see below) |
669
+ | 903.9c | Melded or merged commanders | OOS |
670
+ | 903.10a | 21 combat damage from one commander loses the game | ✓ |
671
+ | 702.124 | Partner and Background (two commanders); commander ninjutsu; cards that refer to "your commander" | OOS until a card needs them |
672
+
673
+ 903.9b is a replacement effect, but replacement effects in the engine can't stop to ask a player. The
674
+ commander moves to its owner's hand or library, and before anyone gets priority its owner chooses whether to
675
+ put it into the command zone (the same `commander_zone` decision as 903.9a). The difference shows only if the
676
+ rest of the effect that moved it acts on that hand or library.
677
+
651
678
  ## Out of scope (listed for completeness)
652
679
 
653
680
  - **Section 8, Multiplayer Rules (800–811)**: range of influence, attack multiple players, Two-Headed Giant, Emperor, and the other team variants.
654
- - **Section 9, Casual Variants (900–905)**: Planechase, Vanguard, Commander, Archenemy, Conspiracy Draft.
681
+ - **Section 9, Casual Variants (900–905)**: Planechase, Vanguard, Archenemy, Conspiracy Draft, and multiplayer
682
+ Commander. Two-player Duel Commander is supported (see "Commander (903)").
655
683
  - Variant-only card types (311–315), ante (407), stickers (123), Attractions (718, 701.51–52, 702.159), Contraptions (701.45), Space Sculptor (702.158, 704.5u), and the variant SBAs and turn-based actions (704.6, 703.4e, 703.4h).
656
684
  - Mechanics that are legal in two-player games but rare (goad, vote, monarch, initiative, companion, dethrone) are kept as **M5**, not OOS.
657
685
 
data/docs/guides/api.md CHANGED
@@ -138,6 +138,9 @@ A **deck document** carries the cards it uses, so it is self-contained:
138
138
  - `outside` (optional): cards the player owns outside the game — the sideboard
139
139
  that "from outside the game" effects use (CR 400.11). At most 15 (CR 100.4a);
140
140
  the copy limit counts both lists.
141
+ - `commander` (optional): the name of the card that leads a Commander deck
142
+ (CR 903.3). It is one of `cards` but not part of `main`, which then holds the
143
+ other 99. See "Commander" below.
141
144
 
142
145
  ```ruby
143
146
  player = Enjine::Player.new(name: "alice", deck: doc) # doc: Hash or Enjine::Deck
@@ -155,6 +158,20 @@ reference) raises `Enjine::InvalidDeck`.
155
158
  While a player is seated in an unfinished game, editing their deck raises
156
159
  `Enjine::DeckLocked`.
157
160
 
161
+ **Commander.** Whether a deck is legal depends on the format the game uses
162
+ (`Enjine::Format`). `deck.errors(format)` and `player.ready?(format)` take it;
163
+ both default to constructed. A Duel Commander deck (`Enjine::Format::DUEL_COMMANDER`)
164
+ has exactly 100 cards with its commander, one copy of each card but basic lands
165
+ (CR 903.5b: "any number" cards are limited to one too), and only cards whose color
166
+ identity is inside the commander's (CR 903.5c). `CardDefinition#color_identity` is
167
+ derived from the card's data, never its text (see the card data format). The engine
168
+ knows no banlist: that is the caller's business.
169
+
170
+ ```ruby
171
+ doc = { "cards" => [...], "main" => [{ "card" => "Forest", "count" => 40 }, ...], "commander" => "Wort, the Raidmother" }
172
+ Enjine::Player.new(name: "alice", deck: doc).ready?(:duel_commander) # => true
173
+ ```
174
+
158
175
  ## 4. Setups and games
159
176
 
160
177
  ```ruby
@@ -169,6 +186,34 @@ games from it is cheap, so keep one `Setup` per matchup and create games from it
169
186
  game = setup.new_game(seed: 42) # Integer seed; drives every random event of the game
170
187
  ```
171
188
 
189
+ `format:` picks the rules: `Enjine::Setup.new(alice, bob, format: :duel_commander)`
190
+ plays Duel Commander (CR 903). Each commander starts in the command zone and both
191
+ players start at 40 life. Leaving `format:` out plays constructed, exactly as before.
192
+ In a Commander game:
193
+
194
+ - A commander in the command zone is cast with `{type: "cast", object: id, via: "command"}`.
195
+ Its cost includes the commander tax, {2} for each earlier cast from the command zone (CR 903.8).
196
+ - When a commander goes to a graveyard, exile, hand or library, its owner gets a
197
+ `commander_zone` decision before anyone gets priority: put it into the command zone or leave it (CR 903.9).
198
+ - 21 combat damage from one commander loses the game, with the result reason `"commander_damage"` (CR 903.10a).
199
+
200
+ ```ruby
201
+ alice = Enjine::Player.new(name: "alice", deck: alice_doc) # each doc names its "commander"
202
+ bob = Enjine::Player.new(name: "bob", deck: bob_doc)
203
+ game = Enjine::Setup.new(alice, bob, format: :duel_commander).new_game(seed: 1)
204
+
205
+ game.state.command # ids of both commanders, waiting in the command zone
206
+ game.legal_options # at sorcery speed, with enough mana for cost + tax:
207
+ # => [..., {type: "cast", object: "wort_the_raidmother#3", via: "command"}, ...]
208
+
209
+ # After the commander dies (or is exiled, bounced, tucked) its owner decides:
210
+ game.pending_decision.kind # => "commander_zone"
211
+ game.submit(type: "command", object: id) # back to the command zone ({type: "stay", ...} leaves it)
212
+
213
+ game.view_for("alice")["players"][0].slice("commander", "commander_tax", "commander_damage")
214
+ # => {"commander" => "Wort, the Raidmother", "commander_tax" => 2, "commander_damage" => {}}
215
+ ```
216
+
172
217
  The game starts at its very first decision: the die-roll winner chooses to play
173
218
  or draw (CR 103.1), then each player decides on a mulligan.
174
219
 
@@ -291,6 +336,7 @@ then `{type: "done"}`. `done` is only offered when the declaration is legal
291
336
  | `enter_choice` | as a permanent enters ("choose a color", "pay 2 life or enters tapped", "behold or enters tapped") | `color`, `creature_type`, `number`, `name`, `option`, `pay_life`, `behold`, `enter_tapped`, ... |
292
337
  | `untap_choice` | "you may choose not to untap" | `untap`, `keep_tapped` |
293
338
  | `legend_rule` | two legends with one name | `{type: "keep", object:}` |
339
+ | `commander_zone` | Commander: your commander went to a graveyard, exile, hand or library (CR 903.9) | `{type: "command", object:}`, `{type: "stay", object:}` |
294
340
  | `declare_attackers` | your combat | `attack`, `withdraw`, `done` |
295
341
  | `declare_blockers` | opponent's combat | `block`, `unblock`, `done` |
296
342
  | `assign_damage` | splitting combat damage | `{type: "assign", object:}` |
@@ -345,6 +391,11 @@ A player entry:
345
391
  "hand":[ ... ], "outside":[ ... ]}
346
392
  ```
347
393
 
394
+ In a Commander game, a player entry also has `"commander"` (the card's name),
395
+ `"commander_tax"` (the extra generic mana their next cast from the command zone
396
+ costs) and `"commander_damage"` (`{commander name => combat damage it dealt them}`).
397
+ The view's `"command"` list holds emblems and the commanders waiting there.
398
+
348
399
  `hand` and `outside` appear only for their owner (and the observer); `library`
349
400
  (in order, top first) only for the observer; `speed` once the player has one.
350
401
 
@@ -59,6 +59,7 @@ Tips:
59
59
  | `abilities` | no | list | Section 4. |
60
60
  | `rules_text` | no | string | Informational only (shown in the CLI). Never interpreted. |
61
61
  | `deck_limit` | no | `"any"` or integer | CR 100.2a exception: "A deck can have any number of cards named ~" is `"deck_limit": "any"`; "up to seven cards named ~" is `7`. Without it a deck may hold four (basic lands: any number). |
62
+ | `color_identity` | no | list of `W U B R G` | Commander only (CR 903.4): states the color identity of this card (or face) instead of deriving it. Rarely needed: the identity is derived from the card's data, see "Commander decks" in §6. |
62
63
  | `rarity` | no | string | Catalogue data, e.g. `"rare"`. The rules never read it. |
63
64
  | `printing` | no | object | `{ "set": "trk", "number": "12" }`: the set code and collector number printed on the card (a number may be given as an integer; it is stored as a string, since numbers like `"12a"` exist). The rules never read it, and two cards differing only in `rarity`/`printing` are the same card (a reprint). On a card with faces it sits beside `faces`. |
64
65
 
@@ -234,6 +235,7 @@ have '[−2]: …'" is `{ "static": { "affects": { "each": "planeswalker", "cont
234
235
  | Oracle words | Data |
235
236
  | --- | --- |
236
237
  | "you control" / "an opponent controls" | `{ "creature": { "controller": "you" } }` |
238
+ | "you own" / "an opponent owns", "you control but don't own" | `{ "creature": { "owner": "you" } }`, `{ "creature": { "controller": "you", "owner": "opponent" } }` (CR 108.3; also in a `static`'s `affects.each`) |
237
239
  | "another" | `{ "creature": { "other": true } }` |
238
240
  | "nonland", "artifact or creature" | `{ "permanent": { "not": ["land"] } }`, `{ "permanent": { "any_of": ["artifact", "creature"] } }` |
239
241
  | "artifact creature" | `{ "creature": { "types": ["artifact"] } }` |
@@ -251,6 +253,21 @@ have '[−2]: …'" is `{ "static": { "affects": { "each": "planeswalker", "cont
251
253
  | "with flying", "with flying or reach", "without flying" | `{ "creature": { "keywords": ["flying"] } }`, `{ "creature": { "keywords": ["flying", "reach"] } }`, `{ "creature": { "not_keywords": ["flying"] } }` (current keywords: granted ones count, CR 702.1) |
252
254
  | "of the chosen color / creature type / card type", "not of the chosen type" | `{ "creature": { "subtypes": "chosen" } }`, `{ "spell": { "colors": "chosen" } }`, `{ "permanent": { "types": "chosen" } }`, `{ "creature": { "not_subtypes": "chosen" } }` (see 4.15) |
253
255
 
256
+ **Card specs.** Effects that look at cards in any zone (graveyard, hand, library, exile; `for`,
257
+ `card`, `cards`, `spells`) describe the card with a card spec: `"card"` (any card) or an object
258
+ whose qualities must all match:
259
+
260
+ | Card words | Card spec |
261
+ | --- | --- |
262
+ | "a basic land card", "a Swamp card", "a card named X" | `{ "types": ["land"], "supertypes": ["basic"] }`, `{ "subtypes": ["swamp"] }`, `{ "name": "X" }` |
263
+ | "a noncreature, nonland card", "a permanent card" | `{ "not_types": ["creature", "land"] }`, `{ "permanent": true }` |
264
+ | "a non-Avatar creature card" | `{ "types": ["creature"], "not_subtypes": ["avatar"] }` |
265
+ | "a creature card with flying" | `{ "types": ["creature"], "keywords": ["flying"] }` (any listed keyword) |
266
+ | "with mana value 3 or less", "with power or toughness 1 or less" | `{ "mana_value": { "at_most": 3 } }`, `{ "any_of": [{ "power": { "at_most": 1 } }, { "toughness": { "at_most": 1 } }] }` |
267
+ | "a black card", "a monocolored card" | `{ "colors": ["B"] }`, `{ "color_count": { "equal": 1 } }` |
268
+ | "a card that has an Adventure" | `{ "layout": "adventure" }` (any card layout: adventure, omen, prepare, transform, modal, meld) |
269
+ | "an instant or sorcery card" | `{ "any_of": [{ "types": ["instant"] }, { "types": ["sorcery"] }] }` |
270
+
254
271
  ### 4.5 Who an effect applies to: the `to` selector
255
272
 
256
273
  | Selector | Oracle words |
@@ -297,6 +314,7 @@ is a flicker ("exile …, then return it to the battlefield under its owner's co
297
314
  | --- | --- |
298
315
  | "Whenever ~ becomes tapped" | `{ "becomes_tapped": {} }` |
299
316
  | "Whenever one or more +1/+1 counters are put on ~" | `{ "counters_placed": { "counter": "+1/+1" } }` |
317
+ | "Whenever you put one or more +1/+1 counters on a creature you control" | `{ "counters_placed": { "subject": { "each": "creature", "controller": "you" }, "counter": "+1/+1", "by": "you" } }` (who put them, CR 122.6a; a permanent's controller puts the counters it enters with) |
300
318
  | one of your creatures is targeted by an opponent's spell or ability | `{ "becomes_target": { "subject": { "each": "creature", "controller": "you" }, "by": "opponent" } }` |
301
319
  | "Whenever a card leaves your graveyard" / "one or more cards leave" | `{ "leaves_graveyard": {} }` / `{ "leaves_graveyard": { "batched": true } }` |
302
320
  | "Whenever an opponent activates an ability" (not mana abilities) | `{ "activates_ability": { "controller": "opponent" } }` |
@@ -356,6 +374,9 @@ See `docs/reference/effects.md` for the generated list. Currently:
356
374
  | `pump` | "gets +X/+Y until end of turn" | `{ "pump": { "power": X, "toughness": Y, "to": … } }` |
357
375
  | `pump` | "get -1/-0 until your next turn" | `{ "pump": { "power": -1, "toughness": 0, "duration": "until_your_next_turn", "to": … } }` (ends as your next turn begins, CR 611.2a) |
358
376
  | `grant`, `become` | "gain flying until your next turn", "until your next turn, it becomes a land" | `"duration": "until_your_next_turn"` on `grant` or `become` |
377
+ | `become_copy` | "it becomes a copy of that creature until your next turn" | `"duration": "until_your_next_turn"` |
378
+ | `gain_control` | "gain control of it until the end of your next turn" | `"duration": "end_of_your_next_turn"` (control returns at that turn's cleanup) |
379
+ | `play_permission` | "you may play that card until your next end step" | `"duration": "until_your_next_end_step"` (ends as your next end step begins; made during your own end step, it lasts until next turn's) |
359
380
  | `add_counters` | "put N +1/+1 counters on …" | `{ "add_counters": { "counter": "+1/+1", "amount": N, "to": … } }` (any counter name: `+1/+1`, `stun`, `shield`, `oil`, a keyword; see `docs/reference/counters.md`) |
360
381
  | `gain_life` | "you gain N life" | `{ "gain_life": { "amount": N } }` (`to` defaults to `"you"`) |
361
382
  | `lose_life` | "each opponent loses N life" | `{ "lose_life": { "amount": N, "to": "each_opponent" } }` |
@@ -792,6 +813,23 @@ Elemental creature with haste until end of turn. It's still a land.":
792
813
  "becomes a legendary Spider Hero in addition to its other types" is `"supertypes": ["legendary"],
793
814
  "subtypes": ["spider", "hero"]`. Static abilities take `types` the same way.
794
815
 
816
+ **Setting card types and creature types** (CR 205.1a, 205.3d). `set_types` replaces the card types
817
+ (in timestamp order with the types other resolved effects add, CR 613.7a; static abilities that change
818
+ types apply after resolved effects for now); subtypes correlated with a
819
+ card type it no longer has are lost (creature types without creature, Treasure without artifact), and
820
+ a permanent that is no longer a creature has no power or toughness. `"creature_types": []` removes
821
+ every creature type; `"all_creature_types": true` gives them all (not the changeling ability).
822
+ `return_to_battlefield` takes the same changes as `as`: what the card is from the moment it enters, so
823
+ abilities that trigger on it entering see it so (CR 614.1c).
824
+
825
+ | Card text | Script |
826
+ |---|---|
827
+ | "When this dies, if it was a creature, return it to the battlefield under its owner's control. It's an enchantment. (It's not a creature.)" | trigger `{ "dies": {} }` with `"if": { "triggering": "creature" }` (past tense: the card types it last had on the battlefield, CR 603.10a) and `{ "return_to_battlefield": { "to": { "triggering": "object" }, "as": { "set_types": ["enchantment"] } } }` |
828
+ | "the chosen permanents become Treasure artifacts with '…' and lose all other abilities" | `{ "become": { "set_types": ["artifact"], "subtypes": ["treasure"], "loses_abilities": true, "abilities": [ … ], "to": { "target": 0 } } }` |
829
+ | "Until your next turn, he becomes a land and gains '{T}: Add {U}.' (He's not a creature during that time.)" | `become` with `"set_types": ["land"]`, `"duration": "until_your_next_turn"` |
830
+ | "gets +3/-3 and loses all creature types until end of turn" | `pump`, then `{ "become": { "creature_types": [], "to": { "target": 0 } } }` |
831
+ | "becomes a 3/3 creature with vigilance and all creature types" | `become` with `"types": ["creature"]`, `"all_creature_types": true`, `"keywords": ["vigilance"]`, `base_power_toughness` |
832
+
795
833
  **Exhaust** (CR 702.177). "Exhaust — {2}{G}: …" is an activated ability with `"exhaust": true`: it
796
834
  can be activated only once for as long as the permanent stays. "Whenever you activate an exhaust
797
835
  ability" is `{ "activates_ability": { "exhaust": true } }`.
@@ -1425,6 +1463,25 @@ view. A `play_from` ability with `"outside"` among its zones offers them as
1425
1463
  `{ "type": "cast", "object": "outside:hill_giant", "via": ... }` (or `play_land`). The
1426
1464
  object is created as the card enters the game, and that player owns it (CR 108.3).
1427
1465
 
1466
+ **Commander decks** (CR 903). A deck that names a `commander` is played with
1467
+ `format: :duel_commander`. The commander is one of `cards` but isn't listed in
1468
+ `main`, which holds the other 99 cards:
1469
+
1470
+ ```json
1471
+ { "cards": [ ... ],
1472
+ "main": [ { "card": "Forest", "count": 38 }, { "card": "Grizzly Bears", "count": 1 }, "..." ],
1473
+ "commander": "Wort, the Raidmother" }
1474
+ ```
1475
+
1476
+ It must be a legendary creature, Vehicle, or Spacecraft with power and toughness
1477
+ (CR 903.3). There is one copy of each card, except basic lands (CR 903.5b), and
1478
+ every card's **color identity** must be inside the commander's (CR 903.5c). A card's
1479
+ identity is the colors of every mana symbol in its data (mana cost, ability costs,
1480
+ produced mana, kicker, and so on), plus `colors`, the colors of its basic land types
1481
+ (CR 903.5d) and those of all its faces (CR 903.4d–e). `rules_text` is never read
1482
+ (reminder text doesn't count, CR 903.4c). For the odd card whose identity the data
1483
+ can't show, a card or face may state it with `"color_identity"`.
1484
+
1428
1485
  ---
1429
1486
 
1430
1487
  ## 7. Validating
@@ -1438,7 +1495,7 @@ bundle exec exe/enjine --validate cards.json
1438
1495
  `cards.json` is a JSON array of card blocks (or a single block). The report:
1439
1496
 
1440
1497
  ```json
1441
- { "rules_version": "2026-11-06", "engine_version": "0.2.0",
1498
+ { "rules_version": "2026-11-06", "engine_version": "0.3.0",
1442
1499
  "valid": [ { "index": 0, "id": "lightning_bolt", "name": "Lightning Bolt", "card": { ...canonical... } } ],
1443
1500
  "invalid": [ { "index": 1, "name": "Gale Drifter", "errors": ["keywords[0]: unknown keyword \"flyng\" ..."] } ] }
1444
1501
  ```
@@ -36,6 +36,24 @@ The same pool, arguments and seed always give the same deck, whatever the order
36
36
  of the pool. The `description` records the colors (including ones picked at
37
37
  random) and the seed, so you can rebuild any deck.
38
38
 
39
+ ## Commander decks
40
+
41
+ `commander:` builds a Duel Commander deck (CR 903) around a pool card that may lead
42
+ one: 99 distinct cards whose color identity fits the commander's, plus basic lands
43
+ of its colors. The colors and the size come from the commander, so don't pass
44
+ `colors:` or `size:`. Play it with `format: :duel_commander`.
45
+
46
+ ```ruby
47
+ doc = builder.build(commander: "Wort, the Raidmother", seed: 3)
48
+ doc["commander"] # => "Wort, the Raidmother"
49
+ Enjine::Setup.new(Enjine::Player.new(name: "a", deck: doc), Enjine::Player.new(name: "b", deck: other),
50
+ format: :duel_commander)
51
+ ```
52
+
53
+ The proportions are the same ranges as for 60 cards, scaled to 99 (about 40 lands).
54
+ A colorless commander isn't supported: it would need Wastes, which the builder
55
+ doesn't add.
56
+
39
57
  ## The pool
40
58
 
41
59
  Each entry is a card data block (the [card DSL](card-data-format.md), optionally
@@ -0,0 +1,63 @@
1
+ # Plan: Duel Commander (0.3.0)
2
+
3
+ **Goal.** Enjine plays Duel Commander: two players, 100-card singleton decks led by a
4
+ commander, 40 life (CR 903). Commander is a *game-setup variant*: `DESIGN.md` §1 now
5
+ lists it as in scope. Which card mechanics we implement is still governed by the
6
+ Standard program.
7
+
8
+ ## Decisions (settled with the user)
9
+
10
+ - **Format.** Duel Commander only: 1v1, 100 cards including the commander, 40 life.
11
+ Multiplayer Commander and Brawl are separate, later work.
12
+ - **Rules in the cut.** Command zone for commanders (903.6), life 40 (903.7), tax (903.8),
13
+ returning to the command zone (903.9a, 903.9b), 21 combat damage from one commander
14
+ (903.10a), deck construction (903.3–903.5).
15
+ - **Deferred (OOS in `MECHANICS_COVERAGE.md`).** Partner, background, companion, commander
16
+ ninjutsu, "can be your commander" on non-creatures, cards that refer to "your commander".
17
+ - **Commander picked up front.** The deck carries `"commander": "Card Name"` beside `main`
18
+ (99 cards + the commander). The format is a `Setup`/`Game.start` option; the default stays
19
+ constructed and unchanged.
20
+ - **Engine knows no banlist.** It validates structure only: 100 cards, singleton, color
21
+ identity, a legal commander card.
22
+ - **Color identity** is derived from structured card data (never rules text), with an
23
+ optional explicit `color_identity` override.
24
+ - **Identity of the commander** is a predicate (owner + the card's own id, not a token, not a
25
+ copy), never a flag on the object, so zone changes and cancelled casts can't lose it.
26
+
27
+ ## Design
28
+
29
+ | Piece | Where |
30
+ | --- | --- |
31
+ | Format presets | `Enjine::Format` (`CONSTRUCTED`, `DUEL_COMMANDER`) |
32
+ | Color identity | `Enjine::ColorIdentity`, `CardDefinition#color_identity` |
33
+ | Deck validity per format | `Deck#errors(format)`, `Deck#commander` |
34
+ | Per-game config | `State#format`, `State#commanders`; `PlayerState#commander_casts`, `#commander_damage` |
35
+ | Rules | `Engine::Commander` (setup, predicate, casting method + tax, damage, 903.9) |
36
+ | Cast from the command zone | a play *method* (`via: "command"`) with a `cost_increase` rider: tax is part of the cost |
37
+ | 903.9 choice | `Decisions::CommanderZone` + a `commander_zone` frame, like the legend rule |
38
+ | 21 damage | counted in `deal_proposed_damage!`, checked as a state-based action |
39
+
40
+ Command-zone cards that are not emblems have no abilities that function there
41
+ (CR 113.6): `Engine#emblems` is the one accessor for "objects in the command zone that act".
42
+
43
+ ## Open point: 903.9b
44
+
45
+ 903.9b is an optional *replacement* ("would be put into hand or library"), but replacements
46
+ are synchronous and cannot ask a player. The engine instead lets the move happen and, before
47
+ anyone gets priority, offers the move to the command zone (the same decision as 903.9a). The
48
+ visible difference: during the resolution that bounced it, the commander is briefly in the
49
+ hand/library. See "Decisions to confirm" in the release notes.
50
+
51
+ ## Slices
52
+
53
+ 1. Format, color identity, deck commander and validation, `Setup` option.
54
+ 2. Command zone, casting from it, tax.
55
+ 3. 903.9 decision, 21-damage state-based action.
56
+ 4. Snapshot, view, `DeckBuilder`, CLI.
57
+ 5. Fuzz, rules monitor, docs, 0.3.0 release.
58
+
59
+ ## Snapshot compatibility
60
+
61
+ New keys (`format`, `commanders`, per-player `commander_casts` and `commander_damage`) are
62
+ optional with defaults, as every earlier addition was; constructed snapshots are unchanged
63
+ and old ones still load. `VERSION` stays 2.