enjine 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -1
- data/README.md +2 -1
- data/docs/ARCHITECTURE.md +2 -0
- data/docs/DESIGN.md +12 -5
- data/docs/MECHANICS_COVERAGE.md +32 -4
- data/docs/guides/api.md +51 -0
- data/docs/guides/card-data-format.md +21 -1
- data/docs/guides/deck-builder.md +18 -0
- data/docs/plans/commander.md +63 -0
- data/docs/reference/decisions.md +5 -1
- data/lib/enjine/actions/cast.rb +2 -1
- data/lib/enjine/card_definition.rb +24 -3
- data/lib/enjine/cli/text.rb +23 -1
- data/lib/enjine/cli.rb +2 -1
- data/lib/enjine/color_identity.rb +38 -0
- data/lib/enjine/decisions/commander_zone.rb +36 -0
- data/lib/enjine/deck.rb +73 -14
- data/lib/enjine/deck_builder.rb +62 -18
- data/lib/enjine/engine/casting/alt_casting.rb +1 -0
- data/lib/enjine/engine/casting/permissions.rb +2 -2
- data/lib/enjine/engine/commander.rb +125 -0
- data/lib/enjine/engine/damage.rb +1 -0
- data/lib/enjine/engine/emblems.rb +1 -1
- data/lib/enjine/engine/pregame.rb +1 -0
- data/lib/enjine/engine/priority.rb +1 -0
- data/lib/enjine/engine/rules.rb +1 -1
- data/lib/enjine/engine/state_based_actions.rb +1 -0
- data/lib/enjine/engine/triggers.rb +1 -1
- data/lib/enjine/engine/zones.rb +1 -0
- data/lib/enjine/format.rb +53 -0
- data/lib/enjine/fuzz.rb +17 -0
- data/lib/enjine/game.rb +4 -3
- data/lib/enjine/player.rb +2 -1
- data/lib/enjine/rules_monitor.rb +25 -1
- data/lib/enjine/setup.rb +10 -4
- data/lib/enjine/snapshot/player_checks.rb +47 -0
- data/lib/enjine/snapshot.rb +4 -1
- data/lib/enjine/state.rb +33 -14
- data/lib/enjine/version.rb +1 -1
- data/lib/enjine/view.rb +18 -1
- data/lib/enjine.rb +2 -0
- metadata +6 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6185d26cd439c9c35ad53fedbdcfeb548eba3a57c854544e2b19189166fd7741
|
|
4
|
+
data.tar.gz: 66c20bcf046ba5b04e2e8029957355858d666dde6f704368d8268dd90f6932f3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 83201217a12702675bf26d3c888189de9c9c94d72add0372a583b014176d69c0f88e431747a25050bd9f7d6f722942a2b3020c2d66d15e97b56bf352e85ab466
|
|
7
|
+
data.tar.gz: 44cc90a0c0634195e040fdcbcfc9fcece4860b00228b50d15674d65b8645eaa755774479d25697955b2ae43e524862294567cc5ca405a226a73da8103a905f98
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,30 @@ change the public API; the stable surface is described in
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.3.0] - 2026-11-20
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
- Duel Commander (CR 903): `Enjine::Setup.new(alice, bob, format: :duel_commander)`
|
|
15
|
+
(`Enjine::Format`). Commanders start in the command zone, players start at 40 life,
|
|
16
|
+
a commander is cast from the command zone with `via: "command"` and pays the commander
|
|
17
|
+
tax, a new `commander_zone` decision lets its owner return it to the command zone
|
|
18
|
+
(903.9a–b), and 21 combat damage from one commander loses the game (reason
|
|
19
|
+
`"commander_damage"`).
|
|
20
|
+
- Deck documents take `"commander"`. `Deck#errors(format)`, `Deck#valid?(format)` and
|
|
21
|
+
`Player#ready?(format)` check a deck against a format. Commander decks need exactly
|
|
22
|
+
100 cards, singleton, and color identity.
|
|
23
|
+
- `CardDefinition#color_identity`, derived from the card's data across all faces;
|
|
24
|
+
the card field `color_identity` overrides it.
|
|
25
|
+
- `DeckBuilder#build(commander:)` builds Duel Commander decks; `Fuzz.random_commander_deck`;
|
|
26
|
+
`rake fuzz[games,seed,duel_commander]`; the CLI's `--format`.
|
|
27
|
+
- Views show the command zone's commanders and, per player, `commander`,
|
|
28
|
+
`commander_tax` and `commander_damage`.
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
- Only emblems' abilities function from the command zone (CR 113.6, 114.4); the
|
|
32
|
+
command zone may now also hold commanders.
|
|
33
|
+
- `State::STARTING_LIFE` is gone: starting life comes from the format.
|
|
34
|
+
|
|
11
35
|
## [0.2.0] - 2026-11-12
|
|
12
36
|
|
|
13
37
|
### Added
|
|
@@ -52,6 +76,7 @@ change the public API; the stable surface is described in
|
|
|
52
76
|
- `enjine` CLI: hot-seat and random play, `--validate`, `--verify`,
|
|
53
77
|
`--random-deck`, save and load.
|
|
54
78
|
|
|
55
|
-
[Unreleased]: https://github.com/thisiscetin/enjine/compare/v0.
|
|
79
|
+
[Unreleased]: https://github.com/thisiscetin/enjine/compare/v0.3.0...HEAD
|
|
80
|
+
[0.3.0]: https://github.com/thisiscetin/enjine/compare/v0.2.0...v0.3.0
|
|
56
81
|
[0.2.0]: https://github.com/thisiscetin/enjine/compare/v0.1.0...v0.2.0
|
|
57
82
|
[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/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
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- Two-player constructed: 20 life, deck ≥ 60 cards, max 4 copies of a
|
|
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/`.
|
data/docs/MECHANICS_COVERAGE.md
CHANGED
|
@@ -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,
|
|
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.
|
|
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,
|
|
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
|
|
|
@@ -1425,6 +1426,25 @@ view. A `play_from` ability with `"outside"` among its zones offers them as
|
|
|
1425
1426
|
`{ "type": "cast", "object": "outside:hill_giant", "via": ... }` (or `play_land`). The
|
|
1426
1427
|
object is created as the card enters the game, and that player owns it (CR 108.3).
|
|
1427
1428
|
|
|
1429
|
+
**Commander decks** (CR 903). A deck that names a `commander` is played with
|
|
1430
|
+
`format: :duel_commander`. The commander is one of `cards` but isn't listed in
|
|
1431
|
+
`main`, which holds the other 99 cards:
|
|
1432
|
+
|
|
1433
|
+
```json
|
|
1434
|
+
{ "cards": [ ... ],
|
|
1435
|
+
"main": [ { "card": "Forest", "count": 38 }, { "card": "Grizzly Bears", "count": 1 }, "..." ],
|
|
1436
|
+
"commander": "Wort, the Raidmother" }
|
|
1437
|
+
```
|
|
1438
|
+
|
|
1439
|
+
It must be a legendary creature, Vehicle, or Spacecraft with power and toughness
|
|
1440
|
+
(CR 903.3). There is one copy of each card, except basic lands (CR 903.5b), and
|
|
1441
|
+
every card's **color identity** must be inside the commander's (CR 903.5c). A card's
|
|
1442
|
+
identity is the colors of every mana symbol in its data (mana cost, ability costs,
|
|
1443
|
+
produced mana, kicker, and so on), plus `colors`, the colors of its basic land types
|
|
1444
|
+
(CR 903.5d) and those of all its faces (CR 903.4d–e). `rules_text` is never read
|
|
1445
|
+
(reminder text doesn't count, CR 903.4c). For the odd card whose identity the data
|
|
1446
|
+
can't show, a card or face may state it with `"color_identity"`.
|
|
1447
|
+
|
|
1428
1448
|
---
|
|
1429
1449
|
|
|
1430
1450
|
## 7. Validating
|
|
@@ -1438,7 +1458,7 @@ bundle exec exe/enjine --validate cards.json
|
|
|
1438
1458
|
`cards.json` is a JSON array of card blocks (or a single block). The report:
|
|
1439
1459
|
|
|
1440
1460
|
```json
|
|
1441
|
-
{ "rules_version": "2026-11-06", "engine_version": "0.
|
|
1461
|
+
{ "rules_version": "2026-11-06", "engine_version": "0.3.0",
|
|
1442
1462
|
"valid": [ { "index": 0, "id": "lightning_bolt", "name": "Lightning Bolt", "card": { ...canonical... } } ],
|
|
1443
1463
|
"invalid": [ { "index": 1, "name": "Gale Drifter", "errors": ["keywords[0]: unknown keyword \"flyng\" ..."] } ] }
|
|
1444
1464
|
```
|
data/docs/guides/deck-builder.md
CHANGED
|
@@ -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.
|
data/docs/reference/decisions.md
CHANGED
|
@@ -40,6 +40,10 @@ While casting/activating: `{type: "count", count: n}` announces how many targets
|
|
|
40
40
|
|
|
41
41
|
While casting/activating a spell or ability with {X} in its cost: `{type: "x", value: n}` announces X (0 up to `max`, the most the available mana could pay for); `{type: "cancel"}` rewinds.
|
|
42
42
|
|
|
43
|
+
## commander_zone
|
|
44
|
+
|
|
45
|
+
Your commander is in a graveyard, exile, hand or library: `{type: "command", object: id}` puts it into the command zone, `{type: "stay", object: id}` leaves it where it is (CR 903.9).
|
|
46
|
+
|
|
43
47
|
## declare_attackers
|
|
44
48
|
|
|
45
49
|
Declare one attacker: `{type: "attack", object: id, target: ref}` (the defending player or one of their planeswalkers), or `{type: "done"}` (withheld while a creature that attacks each combat if able could still attack, CR 508.1d, or while a creature that can't attack alone attacks alone, CR 506.5; then `{type: "withdraw", object: id}` undoes an attack).
|
|
@@ -96,7 +100,7 @@ Untap step: `{type: "untap", object: id}` or `{type: "keep_tapped", object: id}`
|
|
|
96
100
|
|
|
97
101
|
- `activate` — `{type: "activate", object: id, ability: ref}` — start activating an ability (CR 602.2), including planeswalker loyalty abilities (CR 606) and abilities of cards in your hand (cycling, CR 702.29).
|
|
98
102
|
- `activate_mana` — `{type: "activate_mana", object: id, ability: ref}` — activate a mana ability; it resolves immediately (CR 605.3). `mana: "{G}{G}"` names the mana when it is chosen as the ability is activated.
|
|
99
|
-
- `cast` — `{type: "cast", object: id}` — start casting a card from your hand (CR 601.2). `{type: "cast", object: id, via: method}` casts a card from another zone (graveyard, exile, the top of your library) by the permission or alternative cost `via` names, e.g. beam me up (CR 601.3, 702.196). A card outside the game is named `"outside:<card id>"` (CR 400.11b). `{type: "cast", object: id, face: 1}` casts another face of a card in your hand: a modal double-faced card's back face, an Adventure or an Omen (CR 712.8b, 716.3, 721.3). Offered only when timing allows, targets exist and enough mana is available.
|
|
103
|
+
- `cast` — `{type: "cast", object: id}` — start casting a card from your hand (CR 601.2). `{type: "cast", object: id, via: method}` casts a card from another zone (graveyard, exile, the top of your library) by the permission or alternative cost `via` names, e.g. beam me up (CR 601.3, 702.196). In a Commander game `via: "command"` casts your commander from the command zone, its cost including the commander tax (CR 903.8). A card outside the game is named `"outside:<card id>"` (CR 400.11b). `{type: "cast", object: id, face: 1}` casts another face of a card in your hand: a modal double-faced card's back face, an Adventure or an Omen (CR 712.8b, 716.3, 721.3). Offered only when timing allows, targets exist and enough mana is available.
|
|
100
104
|
- `pass` — `{type: "pass"}` — pass priority. When all players pass in succession with an empty stack, the step ends (CR 117.4).
|
|
101
105
|
- `play_land` — `{type: "play_land", object: id}` — special action: your main phase, empty stack, one land per turn plus additional land plays (CR 305.1, 305.2). With `via`: a land from another zone that an effect lets you play. With `face: 1`: a modal double-faced card played with its land back face up (CR 712.9).
|
|
102
106
|
- `special_action` — `{type: "special_action", object: id, ability: ref}` — a special action of a card in your hand: foretell (during your turn, pay {2} and exile it face down, CR 116.2h) or suspend (when you could begin to cast it, pay its suspend cost and exile it with time counters, CR 116.2f) or plot (in your main phase with an empty stack, pay its plot cost and exile it, CR 116.2k).
|
data/lib/enjine/actions/cast.rb
CHANGED
|
@@ -9,7 +9,8 @@ module Enjine
|
|
|
9
9
|
'`{type: "cast", object: id}` — start casting a card from your hand (CR 601.2). ' \
|
|
10
10
|
'`{type: "cast", object: id, via: method}` casts a card from another zone (graveyard, exile, the top ' \
|
|
11
11
|
"of your library) by the permission or alternative cost `via` names, e.g. beam me up (CR 601.3, " \
|
|
12
|
-
|
|
12
|
+
'702.196). In a Commander game `via: "command"` casts your commander from the command zone, its cost ' \
|
|
13
|
+
"including the commander tax (CR 903.8). A card outside the game is named `\"outside:<card id>\"` (CR 400.11b). " \
|
|
13
14
|
'`{type: "cast", object: id, face: 1}` casts another face of a card in your hand: a modal double-faced ' \
|
|
14
15
|
"card's back face, an Adventure or an Omen (CR 712.8b, 716.3, 721.3). Offered only when timing " \
|
|
15
16
|
"allows, targets exist and enough mana is available."
|
|
@@ -11,7 +11,8 @@ module Enjine
|
|
|
11
11
|
# Enjine.registry. Anything unknown is reported (with its path) in a single
|
|
12
12
|
# InvalidCardDefinition error.
|
|
13
13
|
class CardDefinition
|
|
14
|
-
KEYS = %w[name mana_cost colors types supertypes subtypes keywords power toughness loyalty abilities rules_text deck_limit
|
|
14
|
+
KEYS = %w[name mana_cost colors types supertypes subtypes keywords power toughness loyalty abilities rules_text deck_limit
|
|
15
|
+
color_identity].freeze
|
|
15
16
|
# Optional catalogue data beside the rules data, never read by the rules: rarity, and the set code and
|
|
16
17
|
# collector number printed on the card ({"set" => "trk", "number" => "12"}).
|
|
17
18
|
PRINT_KEYS = %w[rarity printing].freeze
|
|
@@ -63,6 +64,7 @@ module Enjine
|
|
|
63
64
|
@rules_data = @source
|
|
64
65
|
@source = deep_freeze(@source.merge("rarity" => @rarity, "printing" => @printing).compact) if @rarity || @printing
|
|
65
66
|
@printed_characteristics = Characteristics.printed(self) if errors.empty?
|
|
67
|
+
@color_identity = ColorIdentity.of(self) if face.nil? && errors.empty? # a face has its card's (see #color_identity)
|
|
66
68
|
freeze
|
|
67
69
|
end
|
|
68
70
|
|
|
@@ -79,6 +81,7 @@ module Enjine
|
|
|
79
81
|
@keywords, keyword_modules = read_names(card, "keywords", :keyword, errors)
|
|
80
82
|
@colors = read_colors(card, errors)
|
|
81
83
|
@deck_limit = read_deck_limit(card, errors)
|
|
84
|
+
@declared_color_identity = read_color_identity(card, errors)
|
|
82
85
|
@power, @power_amount = read_pt(card, "power", errors)
|
|
83
86
|
@toughness, @toughness_amount = read_pt(card, "toughness", errors)
|
|
84
87
|
@loyalty = read_stat(card, "loyalty", errors)
|
|
@@ -167,6 +170,12 @@ module Enjine
|
|
|
167
170
|
def planeswalker? = @planeswalker
|
|
168
171
|
def deck_limit_exempt? = @deck_limit_exempt
|
|
169
172
|
|
|
173
|
+
# The colors a Commander deck must hold to include this card (CR 903.4), WUBRG-ordered, over every face.
|
|
174
|
+
def color_identity = @front ? @front.color_identity : @color_identity
|
|
175
|
+
|
|
176
|
+
# The identity this face states by hand ("color_identity": ["R"]), nil when derived from its data.
|
|
177
|
+
attr_reader :declared_color_identity
|
|
178
|
+
|
|
170
179
|
# Most copies a constructed deck may hold (CR 100.2a): nil for any number (basic lands, or a card that
|
|
171
180
|
# says "a deck can have any number of cards named ~").
|
|
172
181
|
def deck_limit = @deck_limit_exempt ? nil : (@deck_limit || Deck::MAX_COPIES)
|
|
@@ -319,6 +328,16 @@ module Enjine
|
|
|
319
328
|
ok ? Mana::COLORS.select { |c| list.map { it.to_s.upcase }.include?(c.to_s) }.freeze : [].freeze
|
|
320
329
|
end
|
|
321
330
|
|
|
331
|
+
# "color_identity": colors W U B R G; states a face's color identity instead of deriving it (CR 903.4).
|
|
332
|
+
def read_color_identity(card, errors)
|
|
333
|
+
return nil unless card.key?("color_identity")
|
|
334
|
+
|
|
335
|
+
list = card["color_identity"]
|
|
336
|
+
ok = list.is_a?(Array) && list.all? { Mana::COLORS.include?(it.to_s.upcase.to_sym) }
|
|
337
|
+
errors << "color_identity: must be a list of W, U, B, R, G" unless ok
|
|
338
|
+
ok ? Mana::COLORS.select { |c| list.map { it.to_s.upcase }.include?(c.to_s) }.freeze : nil
|
|
339
|
+
end
|
|
340
|
+
|
|
322
341
|
# CR 100.2a: "a deck can have any number of cards named ~" is `"deck_limit": "any"`; "up to seven" is 7.
|
|
323
342
|
# Reads the PRINT_KEYS of a whole card; returns the card without them.
|
|
324
343
|
def read_print(card, errors)
|
|
@@ -415,10 +434,12 @@ module Enjine
|
|
|
415
434
|
out["loyalty"] = @loyalty unless @loyalty.nil?
|
|
416
435
|
out["abilities"] = Snapshot.deep_stringify(card["abilities"]) if card["abilities"].is_a?(Array) && !card["abilities"].empty?
|
|
417
436
|
out["rules_text"] = @rules_text if @rules_text
|
|
418
|
-
out
|
|
419
|
-
deep_freeze(out)
|
|
437
|
+
deep_freeze(out.merge!(deck_building_h))
|
|
420
438
|
end
|
|
421
439
|
|
|
440
|
+
# What deck construction reads beyond the card's characteristics (CR 100.2a, 903.4).
|
|
441
|
+
def deck_building_h = { "deck_limit" => @deck_limit, "color_identity" => @declared_color_identity&.map(&:to_s) }.compact
|
|
442
|
+
|
|
422
443
|
# An integer, or the amount of a characteristic-defining ability as given.
|
|
423
444
|
def normalized_stat(card, key) = card[key].is_a?(Hash) ? Snapshot.deep_stringify(card[key]) : instance_variable_get("@#{key}")
|
|
424
445
|
|
data/lib/enjine/cli/text.rb
CHANGED
|
@@ -79,6 +79,7 @@ module Enjine
|
|
|
79
79
|
lines << " Lands: #{lands.empty? ? "-" : lands.map { permanent(it) }.join(", ")}"
|
|
80
80
|
lines << " Permanents: #{"-" if others.empty?}"
|
|
81
81
|
others.each { lines << " #{permanent(it)}" }
|
|
82
|
+
lines.concat(commander_lines(view, player)) if player["commander"]
|
|
82
83
|
lines << " Hand: #{player["hand"].map { card(it) }.join(", ")}" if player["hand"]
|
|
83
84
|
if player["library"]
|
|
84
85
|
lines << " Library (top first): #{player["library"].first(5).map do
|
|
@@ -89,6 +90,23 @@ module Enjine
|
|
|
89
90
|
lines
|
|
90
91
|
end
|
|
91
92
|
|
|
93
|
+
# A Commander game: the commander, where it waits, its tax and the damage it has taken from commanders.
|
|
94
|
+
def commander_lines(view, player)
|
|
95
|
+
waiting = view["command"].select { it["owner"] == player["name"] && it["kind"] != "emblem" }
|
|
96
|
+
damage = player["commander_damage"].map { |name, n| "#{n} from #{name}" }.join(", ")
|
|
97
|
+
[" Commander: #{player["commander"]}#{" [#{waiting.first["id"]}] in the command zone" unless waiting.empty?}" \
|
|
98
|
+
"#{" · tax {#{player["commander_tax"]}}" if player["commander_tax"].positive?}" \
|
|
99
|
+
"#{" · commander damage taken: #{damage}" unless damage.empty?}"]
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# " from the command zone (+{2})" on a cast option of a commander.
|
|
103
|
+
def commander_tax(opt)
|
|
104
|
+
return "" unless opt[:via] == "command"
|
|
105
|
+
|
|
106
|
+
tax = Engine::Commander::TAX * @game.state.players[@game.state.object(opt[:object]).owner].commander_casts.to_i
|
|
107
|
+
" from the command zone#{" (+{#{tax}})" if tax.positive?}"
|
|
108
|
+
end
|
|
109
|
+
|
|
92
110
|
def permanent(obj)
|
|
93
111
|
parts = [obj["name"]]
|
|
94
112
|
parts << "#{obj["power"]}/#{obj["toughness"]}" if obj.key?("power")
|
|
@@ -120,6 +138,7 @@ module Enjine
|
|
|
120
138
|
when "bottom" then " — put #{decision.details["count"]} more on the bottom"
|
|
121
139
|
when "assign_damage" then " — #{name_of(decision.details["attacker"])}: #{decision.details["remaining"]} damage left"
|
|
122
140
|
when "choose_target" then " — target ##{decision.details["index"] + 1}"
|
|
141
|
+
when "commander_zone" then " — #{name_of(decision.details["object"])} (your commander)"
|
|
123
142
|
when "choose_target_count" then " — how many for target ##{decision.details["index"] + 1}"
|
|
124
143
|
else ""
|
|
125
144
|
end
|
|
@@ -132,7 +151,9 @@ module Enjine
|
|
|
132
151
|
case opt[:type]
|
|
133
152
|
when "pass" then "Pass priority"
|
|
134
153
|
when "play_land" then "Play land #{name_of(opt[:object])}"
|
|
135
|
-
when "cast" then "Cast #{name_of(opt[:object])} #{cost_of(opt[:object])}".rstrip
|
|
154
|
+
when "cast" then "Cast #{name_of(opt[:object])} #{cost_of(opt[:object])}#{commander_tax(opt)}".rstrip
|
|
155
|
+
when "command" then "Put #{name_of(opt[:object])} into the command zone"
|
|
156
|
+
when "stay" then "Leave #{name_of(opt[:object])} where it is"
|
|
136
157
|
when "activate" then "Activate #{name_of(opt[:object])}: #{ability_text(opt[:object], opt[:ability])}"
|
|
137
158
|
when "special_action" then "#{ability_text(opt[:object], opt[:ability])}: #{name_of(opt[:object])} (special action)"
|
|
138
159
|
when "activate_mana"
|
|
@@ -260,6 +281,7 @@ module Enjine
|
|
|
260
281
|
when "sba_toughness" then "#{what} dies (0 toughness)"
|
|
261
282
|
when "sba_loyalty" then "#{what} is put into the graveyard (0 loyalty)"
|
|
262
283
|
when "countered" then "#{what} is countered"
|
|
284
|
+
when "commander" then "#{ev["owner"]} puts #{what} into the command zone"
|
|
263
285
|
when "mulligan_bottom" then "#{ev["owner"]} puts #{what} on the bottom of their library (mulligan)"
|
|
264
286
|
else "#{ev["owner"]}'s #{what}: #{ev["from"]} → #{ev["to"]} (#{ev["reason"]})"
|
|
265
287
|
end
|
data/lib/enjine/cli.rb
CHANGED
|
@@ -68,6 +68,7 @@ module Enjine
|
|
|
68
68
|
o.on("--random-deck [SPEC]", "Print a random deck from --pool as JSON, e.g. \"colors=WU seed=7\"") do
|
|
69
69
|
@options[:random_deck] = it
|
|
70
70
|
end
|
|
71
|
+
o.on("--format NAME", "constructed (default) or duel_commander: decks then name a \"commander\"") { @options[:format] = it }
|
|
71
72
|
o.on("--names A,B", Array, "Player names (default alice,bob)") { @options[:names] = it }
|
|
72
73
|
o.on("--validate FILE", "Validate a JSON array of card data blocks; prints a JSON report") { @options[:validate] = it }
|
|
73
74
|
o.on("--verify DIR", "Validate and play-test every card in DIR's JSON files; exit 1 on any problem") do
|
|
@@ -161,7 +162,7 @@ module Enjine
|
|
|
161
162
|
def new_game
|
|
162
163
|
decks = [@options[:deck1], @options[:deck2]].each_with_index.map { |deck, i| deck_for(deck, i) }
|
|
163
164
|
players = @options[:names].zip(decks).map { |name, deck| Player.new(name: name, deck: deck) }
|
|
164
|
-
@setup = Setup.new(*players)
|
|
165
|
+
@setup = Setup.new(*players, format: @options.fetch(:format, Format::CONSTRUCTED))
|
|
165
166
|
@setup.new_game(seed: @options[:seed])
|
|
166
167
|
end
|
|
167
168
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Enjine
|
|
4
|
+
# A card's color identity (CR 903.4): the colors of the mana symbols in its mana cost and rules, plus its
|
|
5
|
+
# color indicator, characteristic-defining colors and the mana its basic land types make (CR 903.5d), over
|
|
6
|
+
# every face of the card (CR 903.4d-e). Reminder text doesn't count (CR 903.4c), and the engine never reads
|
|
7
|
+
# text: the symbols are found in the card's *data* (costs, produced mana, kicker, ...), not in `rules_text`.
|
|
8
|
+
# A face may state its identity by hand with "color_identity" instead, for the odd card the data can't tell.
|
|
9
|
+
module ColorIdentity
|
|
10
|
+
SKIPPED_KEYS = %w[name rules_text rarity printing color_identity].freeze
|
|
11
|
+
BASIC_LAND_COLORS = { plains: :W, island: :U, swamp: :B, mountain: :R, forest: :G }.freeze
|
|
12
|
+
|
|
13
|
+
module_function
|
|
14
|
+
|
|
15
|
+
# WUBRG-ordered colors of a whole card.
|
|
16
|
+
def of(definition)
|
|
17
|
+
colors = definition.faces.flat_map { face_colors(it) }
|
|
18
|
+
Mana::COLORS.select { colors.include?(it) }.freeze
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def face_colors(face)
|
|
22
|
+
face.declared_color_identity || (face.colors + land_colors(face) + symbols(face.source.except("faces")))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# The colors of the mana a basic land type makes (CR 305.6, 903.5d).
|
|
26
|
+
def land_colors(face) = face.subtypes.filter_map { BASIC_LAND_COLORS[it] }
|
|
27
|
+
|
|
28
|
+
# The colors named by every mana symbol in the card's data, hybrid and monocolored hybrid symbols included.
|
|
29
|
+
def symbols(node)
|
|
30
|
+
case node
|
|
31
|
+
when Hash then node.flat_map { |key, value| SKIPPED_KEYS.include?(key) ? [] : symbols(value) }
|
|
32
|
+
when Array then node.flat_map { symbols(it) }
|
|
33
|
+
when String then node.scan(Mana::SYMBOL).flatten.flat_map { it.scan(/[WUBRG]/).map(&:to_sym) }
|
|
34
|
+
else []
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|