enjine 0.3.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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +41 -1
  3. data/SUPPORTED.md +4 -4
  4. data/docs/guides/card-data-format.md +37 -0
  5. data/docs/plans/dsl-gaps.md +76 -0
  6. data/docs/reference/effects.md +12 -9
  7. data/docs/reference/triggers.md +3 -1
  8. data/lib/enjine/actions/cast.rb +10 -3
  9. data/lib/enjine/card_definition.rb +15 -0
  10. data/lib/enjine/engine/casting/alt_casting.rb +8 -0
  11. data/lib/enjine/engine/casting/casting.rb +19 -0
  12. data/lib/enjine/engine/casting/permissions.rb +17 -12
  13. data/lib/enjine/engine/characteristics.rb +29 -12
  14. data/lib/enjine/engine/copies.rb +16 -9
  15. data/lib/enjine/engine/damage.rb +2 -1
  16. data/lib/enjine/engine/durations.rb +47 -0
  17. data/lib/enjine/engine/faces.rb +2 -0
  18. data/lib/enjine/engine/rules.rb +2 -1
  19. data/lib/enjine/engine/state_based_actions.rb +8 -0
  20. data/lib/enjine/engine/triggers.rb +15 -8
  21. data/lib/enjine/engine/zones.rb +18 -2
  22. data/lib/enjine/events.rb +4 -1
  23. data/lib/enjine/mechanics/abilities/double_counters.rb +1 -1
  24. data/lib/enjine/mechanics/abilities/play_permissions.rb +3 -2
  25. data/lib/enjine/mechanics/abilities/replacement_effects.rb +2 -1
  26. data/lib/enjine/mechanics/abilities/static.rb +7 -0
  27. data/lib/enjine/mechanics/card_spec.rb +54 -12
  28. data/lib/enjine/mechanics/effects/become.rb +35 -13
  29. data/lib/enjine/mechanics/effects/copy.rb +7 -4
  30. data/lib/enjine/mechanics/effects/gain_control.rb +6 -3
  31. data/lib/enjine/mechanics/effects/return_to_battlefield.rb +25 -6
  32. data/lib/enjine/mechanics/filters/base.rb +19 -2
  33. data/lib/enjine/mechanics/filters/stack.rb +1 -1
  34. data/lib/enjine/mechanics/triggers/base.rb +14 -3
  35. data/lib/enjine/mechanics/triggers/casting.rb +1 -1
  36. data/lib/enjine/mechanics/triggers/tap_and_counters.rb +21 -5
  37. data/lib/enjine/mechanics/triggers/zone_changes.rb +1 -1
  38. data/lib/enjine/mechanics/values.rb +10 -7
  39. data/lib/enjine/mechanics.rb +5 -0
  40. data/lib/enjine/rules_monitor.rb +4 -2
  41. data/lib/enjine/steps.rb +10 -1
  42. data/lib/enjine/version.rb +1 -1
  43. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6185d26cd439c9c35ad53fedbdcfeb548eba3a57c854544e2b19189166fd7741
4
- data.tar.gz: 66c20bcf046ba5b04e2e8029957355858d666dde6f704368d8268dd90f6932f3
3
+ metadata.gz: dd2564d74c91b41b13b5d630d52be4e837af582d6b030ce29658951dc1cc1061
4
+ data.tar.gz: 4d7a8e15789f58b94e3033016a1c380b8bd978710f59a7b31010145b1b34b4b7
5
5
  SHA512:
6
- metadata.gz: 83201217a12702675bf26d3c888189de9c9c94d72add0372a583b014176d69c0f88e431747a25050bd9f7d6f722942a2b3020c2d66d15e97b56bf352e85ab466
7
- data.tar.gz: 44cc90a0c0634195e040fdcbcfc9fcece4860b00228b50d15674d65b8645eaa755774479d25697955b2ae43e524862294567cc5ca405a226a73da8103a905f98
6
+ metadata.gz: 4f5476cb7fee29707c027d5b3bfeb9c9d29446faa76dd67999ce6464b1979c649048916d467fbc2db56bdcd6ee2716dacd7c78c73e694d30c6e9c2b3bc34c78f
7
+ data.tar.gz: f9ac926eb54afa0426bb836a44d258e779e98f9d15a91af7a1e9faac05aac9720a4027a74da5cd6bfb3f69a460062ce5dd9307adf347f9fe5d0e7645b79e17a4
data/CHANGELOG.md CHANGED
@@ -8,6 +8,44 @@ 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
+
11
49
  ## [0.3.0] - 2026-11-20
12
50
 
13
51
  ### Added
@@ -76,7 +114,9 @@ change the public API; the stable surface is described in
76
114
  - `enjine` CLI: hot-seat and random play, `--validate`, `--verify`,
77
115
  `--random-deck`, save and load.
78
116
 
79
- [Unreleased]: https://github.com/thisiscetin/enjine/compare/v0.3.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
80
120
  [0.3.0]: https://github.com/thisiscetin/enjine/compare/v0.2.0...v0.3.0
81
121
  [0.2.0]: https://github.com/thisiscetin/enjine/compare/v0.1.0...v0.2.0
82
122
  [0.1.0]: https://github.com/thisiscetin/enjine/releases/tag/v0.1.0
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). |
@@ -235,6 +235,7 @@ have '[−2]: …'" is `{ "static": { "affects": { "each": "planeswalker", "cont
235
235
  | Oracle words | Data |
236
236
  | --- | --- |
237
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`) |
238
239
  | "another" | `{ "creature": { "other": true } }` |
239
240
  | "nonland", "artifact or creature" | `{ "permanent": { "not": ["land"] } }`, `{ "permanent": { "any_of": ["artifact", "creature"] } }` |
240
241
  | "artifact creature" | `{ "creature": { "types": ["artifact"] } }` |
@@ -252,6 +253,21 @@ have '[−2]: …'" is `{ "static": { "affects": { "each": "planeswalker", "cont
252
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) |
253
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) |
254
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
+
255
271
  ### 4.5 Who an effect applies to: the `to` selector
256
272
 
257
273
  | Selector | Oracle words |
@@ -298,6 +314,7 @@ is a flicker ("exile …, then return it to the battlefield under its owner's co
298
314
  | --- | --- |
299
315
  | "Whenever ~ becomes tapped" | `{ "becomes_tapped": {} }` |
300
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) |
301
318
  | one of your creatures is targeted by an opponent's spell or ability | `{ "becomes_target": { "subject": { "each": "creature", "controller": "you" }, "by": "opponent" } }` |
302
319
  | "Whenever a card leaves your graveyard" / "one or more cards leave" | `{ "leaves_graveyard": {} }` / `{ "leaves_graveyard": { "batched": true } }` |
303
320
  | "Whenever an opponent activates an ability" (not mana abilities) | `{ "activates_ability": { "controller": "opponent" } }` |
@@ -357,6 +374,9 @@ See `docs/reference/effects.md` for the generated list. Currently:
357
374
  | `pump` | "gets +X/+Y until end of turn" | `{ "pump": { "power": X, "toughness": Y, "to": … } }` |
358
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) |
359
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) |
360
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`) |
361
381
  | `gain_life` | "you gain N life" | `{ "gain_life": { "amount": N } }` (`to` defaults to `"you"`) |
362
382
  | `lose_life` | "each opponent loses N life" | `{ "lose_life": { "amount": N, "to": "each_opponent" } }` |
@@ -793,6 +813,23 @@ Elemental creature with haste until end of turn. It's still a land.":
793
813
  "becomes a legendary Spider Hero in addition to its other types" is `"supertypes": ["legendary"],
794
814
  "subtypes": ["spider", "hero"]`. Static abilities take `types` the same way.
795
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
+
796
833
  **Exhaust** (CR 702.177). "Exhaust — {2}{G}: …" is an activated ability with `"exhaust": true`: it
797
834
  can be activated only once for as long as the permanent stays. "Whenever you activate an exhaust
798
835
  ability" is `{ "activates_ability": { "exhaust": true } }`.
@@ -1,5 +1,81 @@
1
1
  # DSL gaps: mechanics missing for FAIL and PARTIAL cards
2
2
 
3
+ ## Ranking of 2026-11-20 (enjine 0.3.0)
4
+
5
+ Source: deckfinder `card_scripts`, all 303 PARTIAL and 60 FAIL scripts (365 cards with the
6
+ "missing" note of each). Every card was tagged by hand with **every** gap its note names, so a card
7
+ counts as made exact only when all of its gaps are closed. The order is greedy: at each step, the change
8
+ that makes the most cards exact per unit of effort (S = 1, M = 2, L = 3+, from a skim of `lib/`).
9
+
10
+ - **Batch 1 done (Unreleased), verified:** `counters_placed by`, filter `owner`, card-spec keywords/
11
+ not_subtypes/power/toughness/layout, and the turn-counted durations. Re-scripted and passing
12
+ `enjine --verify` (10–12 rules-monitored games each): Ant-Man, Exemplar of Light, Inspired Tethermage,
13
+ Knight of Wundagore, Mikey & Leo, The Great Goblin, Charming Prince, Get Out, Northampton Farm,
14
+ The Eagles Are Coming!, Laughing Jasper Flint, Steamcore Scholar, Absorbing Man, Haste Magic, Inti
15
+ (**15 exact**, against the 30 the tag count promised). Still blocked by a second gap: Beast and Kid
16
+ Loki (a live static), Invisible Woman (batching across permanents), Terrasymbiosis (once-each-turn
17
+ may), Boiling Rock Rioter and Starfall Invocation (owner on exiled/destroyed card specs), Clash of
18
+ Elements (the owner decides and is dealt the damage), Iroh (computed enters-with counters), April
19
+ O'Neil and Codie (kindred / prepared spell filters), Hearth Elemental (the graveyard count uses a
20
+ permanent-style filter, not a card spec), Leonardo (play_from has no "during your turn"),
21
+ Evil's Thrall (mana-value comparison condition), Dragonhawk ("still exiled").
22
+ - **Batch 2 done (Unreleased), verified:** `become` `set_types`, `"creature_types": []`,
23
+ `all_creature_types`, `return_to_battlefield` `as`, and `{"triggering": filter}` reading last-known card
24
+ types. Re-scripted and passing `enjine --verify` (seeds 0 and 7): Enduring Courage, Enduring Curiosity,
25
+ Enduring Innocence, Tom, Bert, and William, Kitesail Larcenist, Hydro-Man, Nameless Inversion, Soulstone
26
+ Sanctuary (**8 exact**, of the 10 change 5 promised). Still blocked: The Irencrag (become a named
27
+ Equipment with equip), Brilliance Unleashed (its own return effect, not yet re-scripted with `as`).
28
+ Known gap: layer 4 applies resolved type effects (in timestamp order) before statics that change types,
29
+ whatever their timestamps (CR 613.7a wants one order for both).
30
+ - 81 cards have only a one-off gap (no change below helps them); 284 share at least one listed gap.
31
+ - The first 4 changes (all S) make **30** cards exact; the first 20 make about **95**; the first 30
32
+ about **150**.
33
+ - Notes that look stale (written before 0.2.0, worth re-scripting first, no engine work): The Wind Crystal
34
+ (cost_modifier colors exist), Armor Wars chapter III (`greatest_mana_value`), Fblthp (`library_size`),
35
+ Dina's Guidance (`search_library put: graveyard`), Terror of the Peaks and Bolg of the North (0.2.0
36
+ last-known-information work; check in a game).
37
+
38
+ | # | Change | Effort | Cards made exact | Cumulative effort → exact | Examples |
39
+ |---|---|---|---|---|---|
40
+ | 1 | `counters_placed` `by: you`; a "you put counters on it this turn" filter (CountersChanged carries who put them) | S | 9 | 1 → 9 | Ant-Man, Beast, Exemplar of Light, Inspired Tethermage |
41
+ | 2 | `owner: you/opponent` on permanent filters and selectors ("creature you own") | S | 9 | 2 → 18 | Boiling Rock Rioter, Charming Prince, Clash of Elements, Get Out |
42
+ | 3 | card-spec filters: keyword, Adventure/prepared layout, kindred, non-subtype, power/toughness in `play_from` | S | 6 | 3 → 24 | April O'Neil, Bandit's Talent, Codie, Hearth Elemental |
43
+ | 4 | `until_your_next_turn` / until-your-next-end-step on `become_copy`, `gain_control`, permissions | S | 6 | 4 → 30 | Absorbing Man, Dragonhawk, Evil's Thrall, Haste Magic |
44
+ | 5 | `become` `set_types` (and lose creature types/add supertype/set name); fix the monitor's CR 613.4c recompute | M | 10 | 6 → 40 | Brilliance Unleashed, Enduring Courage, Enduring Curiosity, Enduring Innocence |
45
+ | 6 | cost_modifier: condition, first spell each turn, one-turn effect, keyword or chosen-type spells | M | 6 | 8 → 46 | Arachne, Armor Wars, Don & Raph, Eluge |
46
+ | 7 | last-known counters and combat status of a creature that left; move every counter kind | M | 6 | 10 → 52 | Aerith Gainsborough, Ares, Donatello, Essence Channeler |
47
+ | 8 | "descended this turn" (a permanent card put into your graveyard from anywhere) | S | 3 | 11 → 55 | Corpses of the Lost, Molten Collapse, Stalactite Stalker |
48
+ | 9 | "one or two targets": a minimum target count | S | 3 | 12 → 58 | Atlantis Attacks, Heroes' Hangout, Leonardo's Technique |
49
+ | 10 | must-change form of `choose_new_targets`; single-target stack filter | S | 4 | 13 → 62 | Bolt Bend, Redirect Lightning, Return the Favor, Untimely Malfunction |
50
+ | 11 | offspring keyword (CR 702.175) | S | 3 | 14 → 65 | Coruscation Mage, Iridescent Vinelasher, Starscape Cleric |
51
+ | 12 | attack triggers know whether a player or a planeswalker is attacked | S | 3 | 15 → 68 | Attuma, Garruk, Preacher of the Schism |
52
+ | 13 | `remove_counters` cost from this permanent | S | 3 | 16 → 71 | Drake Hatcher, Flitterwing Nuisance, Leatherhead |
53
+ | 14 | `enters_with_counters` with a condition or computed count for others | M | 6 | 18 → 77 | Dust Animus, Gev, Giada, Myojin of Night's Reach |
54
+ | 15 | `add_mana` `until: end_of_turn` (mana not lost as steps end) | S | 3 | 19 → 80 | Electro, Raphael, The Last Agni Kai |
55
+ | 16 | "you've scried or surveilled this turn" condition | S | 3 | 20 → 83 | Desperate Futurescribe, Proctor of Potential, Surveillance Phantasm |
56
+ | 17 | `deal_damage` with a `source` selector | S | 3 | 21 → 86 | Compel Brutality, Hawkeye's Bow, Ingris Stingerquill |
57
+ | 18 | one-turn / conditional additional land plays as an effect | S | 3 | 22 → 89 | Beorn, Thranduil's Company, Way of the Paradox |
58
+ | 19 | static "that many plus one" counter replacement | S | 3 | 23 → 92 | Doc Samson, Michelangelo, Yoshimaru |
59
+ | 20 | "put into a graveyard from the battlefield / library this turn" filters and amounts | S | 3 | 24 → 95 | Bringer of the Last Gift, Cruel Calculations, Supper for Spiders |
60
+ | 21 | equip: once each turn, creature filter, cost reduction by target, alternative cost | M | 5 | 26 → 100 | Dark Knight's Greatsword, Dragonfire Blade, Kíli the Resourceful, Shredder's Armor |
61
+ | 22 | search destinations: choose per card (hand or graveyard, battlefield and hand), exile | M | 5 | 28 → 105 | Dina's Guidance, Part in Friendship, Roads Go Ever, Town Greeter |
62
+ | 23 | attach to the entering / enchanted / triggering creature without targeting | M | 5 | 30 → 110 | Doc Ock's Tentacles, Quintessential Katana, Super-Soldier Serum, Thorin |
63
+ | 24 | choose a card name; same-name filters across zones | L | 7 | 33 → 117 | Ancestral Anger, Ancient Vendetta, Key to the Side-Door, Maelstrom Pulse |
64
+ | 25 | cost modifiers for activated abilities of other permanents (equip, power-up, plot) | M | 5 | 35 → 122 | Doc Aurlock, Dwarven Mauler, Hulk, Mutagen Man |
65
+ | 26 | costs: put stun/page counter, exile a permanent, return a tapped creature, sacrifice the Aura, computed life, variable count | L | 7 | 38 → 129 | Jessica Jones, Madame Null, Mazemind Tome, Rottenmouth Viper |
66
+ | 27 | attack tax, can't be attacked, max attackers, block-count limits | L | 7 | 41 → 136 | Archangel of Tithes, Dáin, Meltstrider's Resolve, Storm |
67
+ | 28 | simultaneous per-player actions (wheel, mass discard/return/sacrifice) | L | 9 | 45 → 145 | Deadly Brew, Garruk, Raphael's Technique, Rush of Dread |
68
+ | 29 | copy exceptions that add abilities or types | M | 4 | 47 → 149 | Ardyn, Electroduplicate, Face Yourself, Likeness Looter |
69
+ | 30 | "attacks alone" trigger | M | 4 | 49 → 153 | Black Widow, Jiang Yanggu, Luke Cage, Spider-Man Noir |
70
+
71
+ Further down (2–4 cards each): Cases, total-mana-value limits on chosen cards, entering attacking from a
72
+ return or reveal, impending, token-type replacements, draw/life replacements, counter doubling, "once each
73
+ turn" on may-abilities, hone counters, attacks-alone triggers. Large, low-yield: face-down permanents
74
+ (manifest dread, disguise; 4 cards, L), split and Room layouts (3, L), another player choosing (End of the
75
+ Hunt, Taster of Wares; 9 cards but L).
76
+
77
+ ## Snapshot of 2026-11-11 (history)
78
+
3
79
  Snapshot of 2026-11-11, taken from deckfinder through its MCP connection (`dsl_status scope: all`).
4
80
  Of 1,025 cards in scope (the user's collection, decks and imported opponent decklists), 192 are
5
81
  DSL FAIL (no script possible yet) and 87 are DSL PARTIAL (a best-effort script that leaves something out).
@@ -224,16 +224,18 @@ Rules: CR 701.3a, CR 701.3b, CR 701.3c, CR 301.5c
224
224
 
225
225
  ## become
226
226
 
227
- 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.
227
+ 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.
228
228
 
229
229
  Rules: CR 611.2a, CR 611.2b, CR 611.2c, CR 613.1d, CR 613.1e, CR 613.1f, CR 613.4b, CR 613.7b, CR 205.1a, CR 205.1b, CR 301.7b, CR 514.2
230
230
 
231
231
  | Parameter | Description |
232
232
  | --- | --- |
233
+ | `set_types` | card types it has instead of its others: artifact, creature, enchantment, land |
233
234
  | `types` | card types it also has: artifact, creature, enchantment, land |
234
235
  | `supertypes` | supertypes it also has ("legendary") |
235
236
  | `subtypes` | subtypes it also has ("in addition to its other types") |
236
- | `creature_types` | list of creature types (replaces the others) |
237
+ | `creature_types` | list of creature types (replaces the others; [] removes them all) |
238
+ | `all_creature_types` | true: it has every creature type |
237
239
  | `colors` | list of W, U, B, R, G (replaces its colors) |
238
240
  | `loses_abilities` | true: it loses all abilities ("loses all abilities") |
239
241
  | `keywords` | list of keywords it gains |
@@ -268,7 +270,7 @@ Rules: CR 611.2a, CR 611.2b, CR 611.2c, CR 613.1d, CR 613.1e, CR 613.1f, CR 613.
268
270
 
269
271
  ## become_copy
270
272
 
271
- 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.
273
+ 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.
272
274
 
273
275
  Rules: CR 707.2, CR 707.4, CR 613.2a, CR 613.7, CR 611.2a, CR 514.2
274
276
 
@@ -277,7 +279,7 @@ Rules: CR 707.2, CR 707.4, CR 613.2a, CR 613.7, CR 611.2a, CR 514.2
277
279
  | `to` | selector (the permanents that become copies) |
278
280
  | `of` | selector (what they copy) |
279
281
  | `except` | {"legendary": false, "keywords": [...], "types": [...], "subtypes": [...], "supertypes": [...], "name": ..., "power": n, "toughness": n, "colors": [...]} |
280
- | `duration` | end_of_turn | permanent |
282
+ | `duration` | end_of_turn | until_your_next_turn | permanent |
281
283
 
282
284
  ```json
283
285
  {
@@ -1327,7 +1329,7 @@ Rules: CR 613.1b, CR 108.4, CR 506.4, CR 302.6, CR 514.2, CR 611.2b
1327
1329
  | --- | --- |
1328
1330
  | `to` | selector (permanents) |
1329
1331
  | `gains` | selector (a player; default "you") |
1330
- | `duration` | permanent | end_of_turn | while_source_on_battlefield | while_source_tapped | while_you_control_source |
1332
+ | `duration` | permanent | end_of_turn | end_of_your_next_turn | while_source_on_battlefield | while_source_tapped | while_you_control_source |
1331
1333
 
1332
1334
  ```json
1333
1335
  {
@@ -1609,14 +1611,14 @@ Rules: CR 702.26a, CR 702.26b, CR 702.26d, CR 702.26g, CR 702.26h, CR 502.1, CR
1609
1611
 
1610
1612
  ## play_permission
1611
1613
 
1612
- 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.
1614
+ 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.
1613
1615
 
1614
1616
  Rules: CR 611.2a, CR 601.3, CR 305.1, CR 400.7, CR 514.2, CR 601.2f, CR 108.3, CR 406.3b, CR 609.4b
1615
1617
 
1616
1618
  | Parameter | Description |
1617
1619
  | --- | --- |
1618
1620
  | `to` | selector (usually {"result": n}) |
1619
- | `duration` | end_of_turn | end_of_your_next_turn | while_exiled |
1621
+ | `duration` | end_of_turn | end_of_your_next_turn | until_your_next_end_step | while_exiled |
1620
1622
  | `play` | play | cast |
1621
1623
  | `for` | card spec |
1622
1624
  | `not_types` | list of card types |
@@ -1924,9 +1926,9 @@ Rules: CR 101.4, CR 400.7, CR 608.2c
1924
1926
 
1925
1927
  ## return_to_battlefield
1926
1928
 
1927
- 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.
1929
+ 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.
1928
1930
 
1929
- Rules: CR 400.7, CR 400.4a, CR 110.2, CR 111.8, CR 603.7c, CR 614.1c, CR 122.6, CR 712.11a, CR 712.11b
1931
+ Rules: CR 400.7, CR 400.4a, CR 110.2, CR 111.8, CR 603.7c, CR 614.1c, CR 122.6, CR 712.11a, CR 712.11b, CR 205.1a
1930
1932
 
1931
1933
  | Parameter | Description |
1932
1934
  | --- | --- |
@@ -1935,6 +1937,7 @@ Rules: CR 400.7, CR 400.4a, CR 110.2, CR 111.8, CR 603.7c, CR 614.1c, CR 122.6,
1935
1937
  | `transformed` | boolean |
1936
1938
  | `under` | owner | you |
1937
1939
  | `counters` | {counter name: n}: it enters with these counters ("with a +1/+1 counter on it") |
1940
+ | `as` | {set_types, types, supertypes, subtypes, creature_types, all_creature_types, colors, loses_abilities, keywords, base_power_toughness}: as `become`, from the moment it enters |
1938
1941
 
1939
1942
  ```json
1940
1943
  {
@@ -298,11 +298,13 @@ Rules: CR 122.6, CR 603.2, CR 603.2c
298
298
  | `subject` | "self" (default) or {"each": filter, ...} |
299
299
  | `counter` | counter name |
300
300
  | `first_time_this_turn` | true: only the first time each turn such counters are put on that permanent (an earlier placement counts even if nothing could trigger then) |
301
+ | `by` | you | opponent: only counters that player puts ("whenever you put ...", CR 122.6a; a permanent's controller puts the counters it enters with) |
301
302
 
302
303
  ```json
303
304
  {
304
305
  "counters_placed": {
305
- "counter": "+1/+1"
306
+ "counter": "+1/+1",
307
+ "by": "you"
306
308
  }
307
309
  }
308
310
  ```
@@ -39,12 +39,19 @@ module Enjine
39
39
  engine.state.battlefield.each do |id|
40
40
  add_options(engine, index, id, out) if engine.object(id).controller == index
41
41
  end
42
- engine.player(index).hand.each { add_options(engine, index, it, out) } # CR 602.2: the owner activates
43
- engine.player(index).graveyard.each { add_options(engine, index, it, out) } # CR 113.6m: e.g. "exile this card from your graveyard"
44
- engine.state.exile.each { add_options(engine, index, it, out) if engine.object(it).owner == index } # CR 113.6b
42
+ off_board(engine, index).each { add_options(engine, index, it, out) }
45
43
  out
46
44
  end
47
45
 
46
+ # Cards whose abilities may function off the battlefield (CR 113.6b): the hand (the owner activates, CR 602.2),
47
+ # graveyard ("exile this card from your graveyard", CR 113.6m) and exiled cards `index` owns, less those with
48
+ # no activated ability for their zone.
49
+ def self.off_board(engine, index)
50
+ pl = engine.player(index)
51
+ ids = pl.hand + pl.graveyard + engine.state.exile.select { engine.object(it).owner == index }
52
+ engine.own_abilities_only? ? ids.reject { engine.no_activations_here?(engine.object(it)) } : ids
53
+ end
54
+
48
55
  def self.add_options(engine, index, id, out)
49
56
  engine.chars(id).activated_abilities.each do |inst|
50
57
  out << { type: "activate", object: id, ability: inst.ref } if engine.activatable?(index, id, inst.ref)
@@ -165,6 +165,13 @@ module Enjine
165
165
  attr_reader :all_effects
166
166
 
167
167
  def triggered? = @triggered
168
+ # This face has an ability of its own to be played from outside its owner's hand: "you may cast this card
169
+ # from your graveyard" (CR 113.6e), beam me up (CR 702.196a) or an alternative cost (Engine::Permissions).
170
+ def plays_itself? = @plays_itself
171
+ # The zones this face's activated abilities function from (CR 113.6): [:battlefield], or [:hand] for cycling.
172
+ attr_reader :activation_zones
173
+
174
+ def self.self_play?(ability) = %i[beam_me_up alternative_cost].include?(ability.kind) || (ability.kind == :play_from && ability.self?)
168
175
  def land? = @land
169
176
  def creature? = @creature
170
177
  def planeswalker? = @planeswalker
@@ -208,6 +215,13 @@ module Enjine
208
215
 
209
216
  private
210
217
 
218
+ # What lets this face be used off the battlefield, from all its abilities (keyword abilities and nested ones too).
219
+ def precompute_off_board
220
+ own = @ability_instances.map(&:ability) + @nested_instances.map(&:ability)
221
+ @plays_itself = own.any? { CardDefinition.self_play?(it) }
222
+ @activation_zones = own.filter_map { it.zone if %i[activated loyalty].include?(it.kind) }.uniq.freeze
223
+ end
224
+
211
225
  def precompute_predicates
212
226
  @land = @types.include?(:land)
213
227
  @creature = @types.include?(:creature)
@@ -219,6 +233,7 @@ module Enjine
219
233
  @spell_ability = @abilities.find { it.kind == :spell } || aura_spell_ability
220
234
  every = @abilities + @nested_instances.map(&:ability)
221
235
  @triggered = every.any? { it.kind == :triggered }
236
+ precompute_off_board
222
237
  @all_effects = nested(every.flat_map do |ability|
223
238
  ability.respond_to?(:modes) && ability.modal? ? ability.modes.flat_map(&:effects) : ability.try_effects
224
239
  end).freeze
@@ -24,6 +24,14 @@ module Enjine
24
24
  # The cards in a hand with an alternative cost (only those can be cast from it with a method).
25
25
  def alt_cost_hand(player) = player.hand.select { |id| chars(id).abilities.any? { it.ability.kind == :alternative_cost } }
26
26
 
27
+ # A card in a graveyard or library, not a copy, with no face that has an ability to play itself
28
+ # (CardDefinition#plays_itself?) has no play method (Engine::Permissions#play_methods): a quick no for most candidates.
29
+ # Exiled cards (permissions, plot, warp, foretell) and a commander always get the full look.
30
+ def unplayable_elsewhere?(obj)
31
+ %i[graveyard library].include?(obj.zone) && !obj.memory.key?("copy_except") && !obj.memory.key?("copy_effects") &&
32
+ !card_off_board(obj.card)[:plays_itself]
33
+ end
34
+
27
35
  # The alternative-cost methods of `obj` (a card `index` owns) that function now. A face-down card its owner
28
36
  # may look at is seen face up (a foretold card, CR 702.143a, 406.3a).
29
37
  def alt_methods(index, obj)
@@ -28,6 +28,25 @@ module Enjine
28
28
  kicked_castable?(index, obj) # CR 702.33g: only the kicked spell has legal targets
29
29
  end
30
30
 
31
+ # No effect gives a card off the battlefield an ability (CR 113.6b): each has only its own (and its copiable
32
+ # values'), so the quick nos below hold.
33
+ def own_abilities_only? = state.effects.none? { it["kind"] == "card_ability" }
34
+
35
+ # A card that isn't a copy, none of whose faces has an activated ability functioning from the zone it's in
36
+ # (CardDefinition#activation_zones, CR 113.6): nothing of it can be activated there.
37
+ def no_activations_here?(obj)
38
+ !obj.memory.key?("copy_except") && !obj.memory.key?("copy_effects") &&
39
+ !card_off_board(obj.card)[:activation_zones].include?(obj.zone)
40
+ end
41
+
42
+ # What a card's faces can do off the battlefield (CardDefinition#plays_itself?, #activation_zones), once per
43
+ # card: printed facts that never change.
44
+ def card_off_board(card)
45
+ (@card_off_board ||= {})[card] ||= catalog.fetch(card).faces.then do |faces|
46
+ { plays_itself: faces.any?(&:plays_itself?), activation_zones: faces.flat_map(&:activation_zones).uniq }
47
+ end
48
+ end
49
+
31
50
  def activatable?(index, id, ability_ref)
32
51
  obj = object(id)
33
52
  ability = chars(obj).ability(ability_ref)
@@ -50,25 +50,30 @@ module Enjine
50
50
 
51
51
  # Priority options: `{type: "cast", object: id, via: method}` for every castable card and method.
52
52
  def permission_cast_options(index)
53
- sources = permission_sources(index)
54
- permission_candidates(index, sources).flat_map do |ref|
55
- obj = candidate_object(index, ref)
56
- play_methods(index, obj, sources).filter_map do |method|
57
- { type: "cast", object: ref, via: method["via"] } if castable_via?(index, obj, method)
58
- end
53
+ candidate_methods(index) do |ref, obj, method|
54
+ { type: "cast", object: ref, via: method["via"] } if castable_via?(index, obj, method)
59
55
  end
60
56
  end
61
57
 
62
- # Priority options: lands `index` may play from outside their hand (CR 305.1, 305.2).
58
+ # Priority options: lands `index` may play from outside their hand (CR 305.1, 305.2). A face-down card is
59
+ # played face up (CR 406.3a).
63
60
  def permission_land_options(index)
61
+ candidate_methods(index, land: true) do |ref, _obj, method|
62
+ { type: "play_land", object: ref, via: method["via"] } if method["play"] == "play"
63
+ end
64
+ end
65
+
66
+ # The options the block makes of each [candidate ref, object, play method]. While no permanent lets `index`
67
+ # play cards from other zones and no card was granted an ability, a card in a graveyard or library can only
68
+ # be played by an ability of its own (#unplayable_elsewhere?).
69
+ def candidate_methods(index, land: false, &)
64
70
  sources = permission_sources(index)
71
+ plain = sources.empty? && own_abilities_only?
65
72
  permission_candidates(index, sources).flat_map do |ref|
66
73
  obj = candidate_object(index, ref)
67
- next [] unless face_up(obj.id) { chars(obj).land? } # a face-down card is played face up (CR 406.3a)
74
+ next [] if (plain && unplayable_elsewhere?(obj)) || (land && !face_up(obj.id) { chars(obj).land? })
68
75
 
69
- play_methods(index, obj, sources).filter_map do |method|
70
- { type: "play_land", object: ref, via: method["via"] } if method["play"] == "play"
71
- end
76
+ play_methods(index, obj, sources).filter_map { yield ref, obj, it }
72
77
  end
73
78
  end
74
79
 
@@ -292,7 +297,7 @@ module Enjine
292
297
 
293
298
  state.effects << { "kind" => "permission", "timestamp" => next_timestamp!, "controller" => index,
294
299
  "affected" => ids, "duration" => duration, "turn" => state.turn, "play" => play,
295
- **riders.transform_keys(&:to_s).slice(*RIDERS) }
300
+ **end_step_timing(index, duration), **riders.transform_keys(&:to_s).slice(*RIDERS) }
296
301
  emit Events::EffectStarted.new(kind: "permission", affected: ids, details: { "duration" => duration, "play" => play })
297
302
  end
298
303