enjine 0.6.2 → 0.6.3
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 +9 -1
- data/docs/guides/api.md +12 -0
- data/lib/enjine/engine/state_based_actions.rb +12 -1
- data/lib/enjine/game.rb +6 -3
- data/lib/enjine/setup.rb +12 -3
- data/lib/enjine/snapshot/player_checks.rb +6 -0
- data/lib/enjine/snapshot.rb +2 -0
- data/lib/enjine/state.rb +13 -4
- data/lib/enjine/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 853cd6e6c1fa6e8ea3038049debaa947f18b6c948c595d3e546604c8a3dbc865
|
|
4
|
+
data.tar.gz: 87ae58e7c4561df98afa3a6924214e0c3bbfd1fd30fa2242be66656fdac9d019
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c39a7f897e7c56df2a8939af69de53453751711520f005ded7f5c94d669d08e1bddc5a51c37b35a99c02316f64feb0ced04e6dfbbea74f84ceab4d2b8852af4a
|
|
7
|
+
data.tar.gz: 698779f724842481530bd5f474e3fbaa316c3cbdcef0aceb0e58e59b1a88c975021fa220660e89f1c1f8768a5fd4ab33aa083c0c01a0ab08edcf668095e9954f
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,13 @@ change the public API; the stable surface is described in
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.6.3] - 2026-11-29
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
- `Setup.new(..., permanent_limit: n)`: an opt-in guard for simulations, not a rule of the game. Once more than `n`
|
|
15
|
+
permanents are on the battlefield the game is a draw with the reason `permanent_limit`, checked with state-based
|
|
16
|
+
actions. Off by default; kept in snapshots.
|
|
17
|
+
|
|
11
18
|
## [0.6.2] - 2026-11-29
|
|
12
19
|
|
|
13
20
|
### Added
|
|
@@ -342,7 +349,8 @@ Includes 0.4.0, which was tagged but never published to RubyGems.
|
|
|
342
349
|
- `enjine` CLI: hot-seat and random play, `--validate`, `--verify`,
|
|
343
350
|
`--random-deck`, save and load.
|
|
344
351
|
|
|
345
|
-
[Unreleased]: https://github.com/thisiscetin/enjine/compare/v0.6.
|
|
352
|
+
[Unreleased]: https://github.com/thisiscetin/enjine/compare/v0.6.3...HEAD
|
|
353
|
+
[0.6.3]: https://github.com/thisiscetin/enjine/compare/v0.6.2...v0.6.3
|
|
346
354
|
[0.6.2]: https://github.com/thisiscetin/enjine/compare/v0.6.1...v0.6.2
|
|
347
355
|
[0.6.1]: https://github.com/thisiscetin/enjine/compare/v0.6.0...v0.6.1
|
|
348
356
|
[0.6.0]: https://github.com/thisiscetin/enjine/compare/v0.5.0...v0.6.0
|
data/docs/guides/api.md
CHANGED
|
@@ -240,6 +240,18 @@ or draw (CR 103.1), then each player decides on a mulligan.
|
|
|
240
240
|
players lose at once the game is a draw: `"winner" => nil` and the reasons are
|
|
241
241
|
joined, e.g. `"life,life"` (CR 104.4a).
|
|
242
242
|
|
|
243
|
+
### Limiting the board (simulations)
|
|
244
|
+
|
|
245
|
+
Some boards double every turn, and each decision then takes longer than the
|
|
246
|
+
last. `Enjine::Setup.new(alice, bob, permanent_limit: 150)` ends such a game as
|
|
247
|
+
a draw, `{"winner" => nil, "reason" => "permanent_limit"}`, once more than 150
|
|
248
|
+
permanents (both players' together; phased-out ones aren't counted) are on the
|
|
249
|
+
battlefield. This is not a rule of the game and is off unless you set it. It is
|
|
250
|
+
checked with state-based actions (CR 704.3), after players have lost, so one
|
|
251
|
+
effect can overshoot the limit before the game ends. The limit is part of the
|
|
252
|
+
snapshot, survives `fork` and `restart`, and replays are unaffected: the same
|
|
253
|
+
setup, seed and decisions end the same way.
|
|
254
|
+
|
|
243
255
|
## 5. The decision loop
|
|
244
256
|
|
|
245
257
|
```ruby
|
|
@@ -7,6 +7,7 @@ module Enjine
|
|
|
7
7
|
def check_state_based_actions!
|
|
8
8
|
loop do
|
|
9
9
|
check_player_state_based_actions!
|
|
10
|
+
check_permanent_limit!
|
|
10
11
|
break if state.over? || !check_permanent_state_based_actions!
|
|
11
12
|
end
|
|
12
13
|
end
|
|
@@ -45,7 +46,17 @@ module Enjine
|
|
|
45
46
|
|
|
46
47
|
survivors = state.players.reject(&:lost)
|
|
47
48
|
winner = survivors.size == 1 ? survivors.first.name : nil
|
|
48
|
-
|
|
49
|
+
end_game!(winner, losers.map(&:lost).uniq.join(","))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# The setup's permanent limit (not a rule of the game; off unless set): too large a board is a draw.
|
|
53
|
+
# Checked after players have lost, so a game decided at the same time keeps its winner.
|
|
54
|
+
def check_permanent_limit!
|
|
55
|
+
limit = state.permanent_limit
|
|
56
|
+
end_game!(nil, "permanent_limit") if limit && !state.over? && state.battlefield.size > limit
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def end_game!(winner, reason)
|
|
49
60
|
state.result = { "winner" => winner, "reason" => reason }
|
|
50
61
|
ask!(nil)
|
|
51
62
|
state.frames.clear
|
data/lib/enjine/game.rb
CHANGED
|
@@ -20,8 +20,10 @@ module Enjine
|
|
|
20
20
|
|
|
21
21
|
attr_reader :catalog, :history
|
|
22
22
|
|
|
23
|
-
def self.start(catalog:, names:, decklists:, seed:, outside: nil, format: Format::CONSTRUCTED, commanders: nil
|
|
24
|
-
|
|
23
|
+
def self.start(catalog:, names:, decklists:, seed:, outside: nil, format: Format::CONSTRUCTED, commanders: nil,
|
|
24
|
+
permanent_limit: nil)
|
|
25
|
+
state = State.initial(names: names, decklists: decklists, seed: seed, outside: outside, format: format,
|
|
26
|
+
commanders: commanders, permanent_limit: permanent_limit)
|
|
25
27
|
new(catalog, state).tap(&:start!)
|
|
26
28
|
end
|
|
27
29
|
|
|
@@ -126,7 +128,8 @@ module Enjine
|
|
|
126
128
|
# Starts this game over from its opening, with the same or a new seed.
|
|
127
129
|
def restart(seed: nil)
|
|
128
130
|
fresh = State.initial(names: names, decklists: state.decklists, seed: seed.nil? ? state.seed : seed,
|
|
129
|
-
outside: state.outside_lists, format: state.format, commanders: state.commanders
|
|
131
|
+
outside: state.outside_lists, format: state.format, commanders: state.commanders,
|
|
132
|
+
permanent_limit: state.permanent_limit)
|
|
130
133
|
@engine.state = fresh
|
|
131
134
|
@history = []
|
|
132
135
|
@buffer.clear
|
data/lib/enjine/setup.rb
CHANGED
|
@@ -9,13 +9,22 @@ module Enjine
|
|
|
9
9
|
# The catalog and decklists are captured at compile time and shared by every game,
|
|
10
10
|
# so later deck edits never affect an existing Setup.
|
|
11
11
|
#
|
|
12
|
+
# `permanent_limit:` (off by default; not a rule of the game) ends a game as a draw, with the reason
|
|
13
|
+
# "permanent_limit", once more than that many permanents are on the battlefield: for simulations, where a
|
|
14
|
+
# board that keeps doubling would make every decision slower than the last.
|
|
15
|
+
#
|
|
12
16
|
# `format:` picks the rules (Enjine::Format): constructed by default; `:duel_commander` plays Commander
|
|
13
17
|
# (CR 903), and each deck then names its commander.
|
|
14
18
|
class Setup
|
|
15
|
-
attr_reader :players, :catalog, :decklists, :outside, :format, :commanders
|
|
19
|
+
attr_reader :players, :catalog, :decklists, :outside, :format, :commanders, :permanent_limit
|
|
16
20
|
|
|
17
|
-
def initialize(*players, format: Format::CONSTRUCTED)
|
|
21
|
+
def initialize(*players, format: Format::CONSTRUCTED, permanent_limit: nil)
|
|
18
22
|
@format = Format.fetch(format)
|
|
23
|
+
unless permanent_limit.nil? || (permanent_limit.is_a?(Integer) && permanent_limit.positive?)
|
|
24
|
+
raise ArgumentError, "permanent_limit must be a positive Integer or nil, got #{permanent_limit.inspect}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
@permanent_limit = permanent_limit
|
|
19
28
|
players = players.flatten
|
|
20
29
|
raise ArgumentError, "a game needs exactly 2 players" unless players.size == 2
|
|
21
30
|
raise ArgumentError, "player names must differ" if players.map(&:name).uniq.size != 2
|
|
@@ -36,7 +45,7 @@ module Enjine
|
|
|
36
45
|
|
|
37
46
|
def new_game(seed:)
|
|
38
47
|
Game.start(catalog: @catalog, names: names, decklists: @decklists, seed: seed, outside: @outside,
|
|
39
|
-
format: @format, commanders: @commanders).tap do |game|
|
|
48
|
+
format: @format, commanders: @commanders, permanent_limit: @permanent_limit).tap do |game|
|
|
40
49
|
@players.each { |p| p.seat(game) }
|
|
41
50
|
end
|
|
42
51
|
end
|
|
@@ -49,6 +49,12 @@ module Enjine
|
|
|
49
49
|
# The format and the commanders (CR 903.3): constructed has none; a Commander game has one per player, and
|
|
50
50
|
# only a player's own commander card (besides emblems, CR 114.1) is ever in the command zone. Absent in
|
|
51
51
|
# snapshots of constructed games.
|
|
52
|
+
def validate_permanent_limit(limit, errors)
|
|
53
|
+
return if limit.nil? || (limit.is_a?(Integer) && limit.positive?)
|
|
54
|
+
|
|
55
|
+
errors << "permanent_limit: must be a positive integer (or absent)"
|
|
56
|
+
end
|
|
57
|
+
|
|
52
58
|
def build_commanders(state, data)
|
|
53
59
|
state.format = Format.fetch(data.fetch("format", Format::CONSTRUCTED.name))
|
|
54
60
|
state.commanders = data.fetch("commanders", [nil, nil]).dup.freeze
|
data/lib/enjine/snapshot.rb
CHANGED
|
@@ -31,6 +31,7 @@ module Enjine
|
|
|
31
31
|
validate_extra_phases(data, errors)
|
|
32
32
|
validate_outside(data, catalog, errors)
|
|
33
33
|
validate_commanders(data, catalog, errors)
|
|
34
|
+
validate_permanent_limit(data["permanent_limit"], errors)
|
|
34
35
|
errors
|
|
35
36
|
end
|
|
36
37
|
|
|
@@ -62,6 +63,7 @@ module Enjine
|
|
|
62
63
|
state.extra_phases = deep_copy(data.fetch("extra_phases", State.no_extra_phases))
|
|
63
64
|
state.outside_lists = data.fetch("outside_lists", [[], []]).map { |l| l.dup.freeze }.freeze
|
|
64
65
|
build_commanders(state, data)
|
|
66
|
+
state.permanent_limit = data["permanent_limit"] # absent: no limit
|
|
65
67
|
state.repeat_cleanup = data.fetch("repeat_cleanup", false)
|
|
66
68
|
state.combat_damage_pass = data["combat_damage_pass"]
|
|
67
69
|
state.attacks_declared = data.fetch("attacks_declared", 0)
|
data/lib/enjine/state.rb
CHANGED
|
@@ -88,15 +88,15 @@ module Enjine
|
|
|
88
88
|
# The rules the game was set up with (Enjine::Format), and each player's commander card id or nil (CR 903.3).
|
|
89
89
|
# Like `decklists`, a restart begins from these again.
|
|
90
90
|
attr_accessor :format, :commanders
|
|
91
|
+
# The most permanents the battlefield may hold before the game is drawn, or nil (Setup's `permanent_limit:`).
|
|
92
|
+
attr_accessor :permanent_limit
|
|
91
93
|
# Object ids of commanders put into a graveyard, exile, hand or library since state-based actions were last
|
|
92
94
|
# checked, whose owner may still send them to the command zone (CR 903.9, Engine::Commander).
|
|
93
95
|
attr_accessor :commander_returns
|
|
94
96
|
|
|
95
|
-
def self.initial(names:, decklists:, seed:, outside: nil, format: Format::CONSTRUCTED, commanders: nil)
|
|
97
|
+
def self.initial(names:, decklists:, seed:, outside: nil, format: Format::CONSTRUCTED, commanders: nil, permanent_limit: nil)
|
|
96
98
|
state = new
|
|
97
|
-
state
|
|
98
|
-
state.commanders = (commanders || names.map { nil }).freeze
|
|
99
|
-
state.commander_returns = []
|
|
99
|
+
assign_rules(state, format, commanders || names.map { nil }, permanent_limit)
|
|
100
100
|
state.seed = seed
|
|
101
101
|
state.rng = Rng.from_seed(seed)
|
|
102
102
|
state.decklists = decklists.map { |l| l.dup.freeze }.freeze
|
|
@@ -122,6 +122,14 @@ module Enjine
|
|
|
122
122
|
state
|
|
123
123
|
end
|
|
124
124
|
|
|
125
|
+
def self.assign_rules(state, format, commanders, permanent_limit)
|
|
126
|
+
state.format = format
|
|
127
|
+
state.commanders = commanders.freeze
|
|
128
|
+
state.commander_returns = []
|
|
129
|
+
state.permanent_limit = permanent_limit
|
|
130
|
+
end
|
|
131
|
+
private_class_method :assign_rules
|
|
132
|
+
|
|
125
133
|
# Phases added this turn (CR 500.8): "pending" [{"after": phase, "phases": ["combat", "main"]}] wait for
|
|
126
134
|
# their phase to end, "queue" lists added phases still to come and "resume" the step the turn goes on
|
|
127
135
|
# with after them (Engine::TurnStructure); "combats" counts combat phases begun this turn.
|
|
@@ -158,6 +166,7 @@ module Enjine
|
|
|
158
166
|
**DEEP_FIELDS.to_h { [it, deep_dup(public_send(it))] },
|
|
159
167
|
"repeat_cleanup" => repeat_cleanup, "combat_damage_pass" => combat_damage_pass,
|
|
160
168
|
"attacks_declared" => attacks_declared }.merge("outside_lists" => (outside_lists || []).map(&:dup)).merge(format_h)
|
|
169
|
+
.merge({ "permanent_limit" => permanent_limit }.compact)
|
|
161
170
|
end
|
|
162
171
|
|
|
163
172
|
# What a Commander game adds to a snapshot; a constructed game's is unchanged.
|
data/lib/enjine/version.rb
CHANGED