@pkmn/engine 0.1.0-dev.e5b5a998 → 0.1.0-dev.f918c3bd
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.
- package/README.md +53 -42
- package/build/pkg/addon.js +3 -2
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data/layout.json +24 -2
- package/build/pkg/data/protocol.json +69 -12
- package/build/pkg/gen1.js +13 -16
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/protocol.js +56 -37
- package/build/pkg/protocol.js.map +1 -1
- package/build.zig +82 -57
- package/package.json +33 -15
- package/src/bin/install-pkmn-engine +10 -5
- package/src/lib/binding/node.zig +46 -141
- package/src/lib/binding/wasm.zig +4 -2
- package/src/lib/common/battle.zig +17 -0
- package/src/lib/common/data.zig +15 -27
- package/src/lib/common/debug.zig +20 -11
- package/src/lib/common/js.zig +118 -0
- package/src/lib/common/optional.zig +60 -0
- package/src/lib/common/options.zig +9 -0
- package/src/lib/common/protocol.zig +643 -138
- package/src/lib/common/rational.zig +353 -0
- package/src/lib/common/rng.zig +15 -15
- package/src/lib/common/util.zig +12 -0
- package/src/lib/gen1/README.md +257 -177
- package/src/lib/gen1/calc.zig +426 -0
- package/src/lib/gen1/chance.zig +1058 -0
- package/src/lib/gen1/data/moves.zig +168 -170
- package/src/lib/gen1/data/types.zig +2 -2
- package/src/lib/gen1/data.zig +61 -51
- package/src/lib/gen1/helpers.zig +588 -17
- package/src/lib/gen1/mechanics.zig +776 -502
- package/src/lib/gen2/README.md +102 -83
- package/src/lib/gen2/data/items.zig +1 -1
- package/src/lib/gen2/data/moves.zig +634 -562
- package/src/lib/gen2/data/types.zig +1 -1
- package/src/lib/gen2/data.zig +100 -67
- package/src/lib/gen2/helpers.zig +15 -21
- package/src/lib/gen2/mechanics.zig +1147 -11
- package/src/lib/pkmn.zig +61 -2
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
|
|
3
|
+
const pkmn = @import("../pkmn.zig");
|
|
4
|
+
|
|
5
|
+
const common = @import("../common/data.zig");
|
|
6
|
+
const DEBUG = @import("../common/debug.zig").print;
|
|
7
|
+
const optional = @import("../common/optional.zig");
|
|
8
|
+
const protocol = @import("../common/protocol.zig");
|
|
9
|
+
const rational = @import("../common/rational.zig");
|
|
10
|
+
const util = @import("../common/util.zig");
|
|
11
|
+
|
|
12
|
+
const chance = @import("chance.zig");
|
|
13
|
+
const data = @import("data.zig");
|
|
14
|
+
const helpers = @import("helpers.zig");
|
|
15
|
+
|
|
16
|
+
const assert = std.debug.assert;
|
|
17
|
+
|
|
18
|
+
const expect = std.testing.expect;
|
|
19
|
+
const expectEqual = std.testing.expectEqual;
|
|
20
|
+
|
|
21
|
+
const enabled = pkmn.options.calc;
|
|
22
|
+
|
|
23
|
+
const Player = common.Player;
|
|
24
|
+
const Result = common.Result;
|
|
25
|
+
const Choice = common.Choice;
|
|
26
|
+
|
|
27
|
+
const Optional = optional.Optional;
|
|
28
|
+
|
|
29
|
+
const Rational = rational.Rational;
|
|
30
|
+
|
|
31
|
+
const PointerType = util.PointerType;
|
|
32
|
+
|
|
33
|
+
const Actions = chance.Actions;
|
|
34
|
+
const Action = chance.Action;
|
|
35
|
+
const Chance = chance.Chance;
|
|
36
|
+
const Durations = chance.Durations;
|
|
37
|
+
const Duration = chance.Duration;
|
|
38
|
+
|
|
39
|
+
const Rolls = helpers.Rolls;
|
|
40
|
+
|
|
41
|
+
/// Information relevant to damage calculation that occured during a Generation I battle `update`.
|
|
42
|
+
pub const Summaries = extern struct {
|
|
43
|
+
/// Relevant information for Player 1.
|
|
44
|
+
p1: Summary = .{},
|
|
45
|
+
/// Relevant information for Player 2.
|
|
46
|
+
p2: Summary = .{},
|
|
47
|
+
|
|
48
|
+
comptime {
|
|
49
|
+
assert(@sizeOf(Summaries) == 12);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/// Returns the `Summary` for the given `player`.
|
|
53
|
+
pub inline fn get(self: anytype, player: Player) PointerType(@TypeOf(self), Summary) {
|
|
54
|
+
assert(@typeInfo(@TypeOf(self)).Pointer.child == Summaries);
|
|
55
|
+
return if (player == .P1) &self.p1 else &self.p2;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/// Information relevant to damage calculation that occured during a Generation I battle `update`
|
|
60
|
+
/// for a single player.
|
|
61
|
+
pub const Summary = extern struct {
|
|
62
|
+
/// The computed raw damage values.
|
|
63
|
+
damage: Damage = .{},
|
|
64
|
+
|
|
65
|
+
/// Intermediate raw damage values computed during a calculation.
|
|
66
|
+
pub const Damage = extern struct {
|
|
67
|
+
/// The base computed damage before the damage roll is applied.
|
|
68
|
+
base: u16 = 0,
|
|
69
|
+
/// The final computed damage that gets applied to the Pokémon. May exceed the target's HP
|
|
70
|
+
// (to determine the *actual* damage done compare the target's stored HP before and after).
|
|
71
|
+
final: u16 = 0,
|
|
72
|
+
/// Whether higher damage will saturate / result in the same outcome (e.g. additional damage
|
|
73
|
+
/// gets ignored due to it already breaking a Substitute or causing the target to faint).
|
|
74
|
+
capped: bool = false,
|
|
75
|
+
|
|
76
|
+
// NOTE: 15 bits padding
|
|
77
|
+
|
|
78
|
+
comptime {
|
|
79
|
+
assert(@sizeOf(Damage) == 6);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
comptime {
|
|
84
|
+
assert(@sizeOf(Summary) == 6);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/// TODO
|
|
89
|
+
pub const Overrides = extern struct {
|
|
90
|
+
/// TODO
|
|
91
|
+
actions: Actions = .{},
|
|
92
|
+
/// TODO
|
|
93
|
+
durations: Durations = .{},
|
|
94
|
+
|
|
95
|
+
_: u32 = 0,
|
|
96
|
+
|
|
97
|
+
comptime {
|
|
98
|
+
assert(@sizeOf(Overrides) == 24);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/// Allows for forcing the value of specific RNG events during a Generation I battle `update` via
|
|
103
|
+
/// `overrides` and tracks `summaries` of information relevant to damage calculation.
|
|
104
|
+
pub const Calc = struct {
|
|
105
|
+
/// Overrides the normal behavior of the RNG during an `update` to force specific outcomes.
|
|
106
|
+
overrides: Overrides = .{},
|
|
107
|
+
/// Information relevant to damage calculation.
|
|
108
|
+
summaries: Summaries = .{},
|
|
109
|
+
|
|
110
|
+
pub fn overridden(
|
|
111
|
+
self: Calc,
|
|
112
|
+
player: Player,
|
|
113
|
+
comptime field: Action.Field,
|
|
114
|
+
) ?std.meta.FieldType(Action, field) {
|
|
115
|
+
if (!enabled) return null;
|
|
116
|
+
|
|
117
|
+
const overrides =
|
|
118
|
+
if (player == .P1) self.overrides.actions.p1 else self.overrides.actions.p2;
|
|
119
|
+
const val = @field(overrides, @tagName(field));
|
|
120
|
+
return if (switch (@typeInfo(@TypeOf(val))) {
|
|
121
|
+
.Enum => val != .None,
|
|
122
|
+
.Int => val != 0,
|
|
123
|
+
else => unreachable,
|
|
124
|
+
}) val else null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
pub fn modify(self: Calc, player: Player, comptime field: Duration.Field) ?bool {
|
|
128
|
+
if (!enabled) return null;
|
|
129
|
+
|
|
130
|
+
const durations = self.overrides.durations;
|
|
131
|
+
const set = @field(if (player == .P1) durations.p1 else durations.p2, @tagName(field));
|
|
132
|
+
if (set == 0) return null;
|
|
133
|
+
|
|
134
|
+
const actions = self.overrides.actions;
|
|
135
|
+
const overrides = if (player == .P1) actions.p1.durations else actions.p2.durations;
|
|
136
|
+
return @field(overrides, @tagName(field)) != 0;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
pub fn base(self: *Calc, player: Player, val: u16) void {
|
|
140
|
+
if (!enabled) return;
|
|
141
|
+
|
|
142
|
+
self.summaries.get(player).damage.base = val;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
pub fn final(self: *Calc, player: Player, val: u16) void {
|
|
146
|
+
if (!enabled) return;
|
|
147
|
+
|
|
148
|
+
self.summaries.get(player).damage.final = val;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
pub fn capped(self: *Calc, player: Player) void {
|
|
152
|
+
if (!enabled) return;
|
|
153
|
+
|
|
154
|
+
self.summaries.get(player).damage.capped = true;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/// Null object pattern implementation of Generation I `Calc` which does nothing, though damage
|
|
159
|
+
/// calculator support should additionally be turned off entirely via `options.calc`.
|
|
160
|
+
pub const NULL: Null = .{};
|
|
161
|
+
|
|
162
|
+
const Null = struct {
|
|
163
|
+
pub fn overridden(
|
|
164
|
+
self: Null,
|
|
165
|
+
player: Player,
|
|
166
|
+
comptime field: Action.Field,
|
|
167
|
+
) ?std.meta.FieldType(Action, field) {
|
|
168
|
+
_ = .{ self, player };
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
pub fn modify(self: Null, player: Player, comptime field: Duration.Field) ?bool {
|
|
173
|
+
_ = .{ self, player, field };
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
pub fn base(self: Null, player: Player, val: u16) void {
|
|
178
|
+
_ = .{ self, player, val };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
pub fn final(self: Null, player: Player, val: u16) void {
|
|
182
|
+
_ = .{ self, player, val };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
pub fn capped(self: Null, player: Player) void {
|
|
186
|
+
_ = .{ self, player };
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
pub const Stats = struct {
|
|
191
|
+
frontier: usize = 0,
|
|
192
|
+
updates: usize = 0,
|
|
193
|
+
seen: usize = 0,
|
|
194
|
+
saved: usize = 0,
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
pub const Options = struct {
|
|
198
|
+
actions: Actions = .{},
|
|
199
|
+
seed: ?u64 = null,
|
|
200
|
+
cap: bool = false,
|
|
201
|
+
metronome: bool = false,
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
pub fn transitions(
|
|
205
|
+
battle: anytype,
|
|
206
|
+
c1: Choice,
|
|
207
|
+
c2: Choice,
|
|
208
|
+
allocator: std.mem.Allocator,
|
|
209
|
+
writer: anytype,
|
|
210
|
+
options: Options,
|
|
211
|
+
) !?Stats {
|
|
212
|
+
var stats: Stats = .{};
|
|
213
|
+
|
|
214
|
+
var actions = options.actions;
|
|
215
|
+
var cap = options.cap;
|
|
216
|
+
|
|
217
|
+
var seen = std.AutoHashMap(Actions, void).init(allocator);
|
|
218
|
+
defer seen.deinit();
|
|
219
|
+
var frontier = std.ArrayList(Actions).init(allocator);
|
|
220
|
+
defer frontier.deinit();
|
|
221
|
+
|
|
222
|
+
var opts = pkmn.battle.options(
|
|
223
|
+
protocol.NULL,
|
|
224
|
+
Chance(Rational(u128)){ .probability = .{}, .actions = actions },
|
|
225
|
+
Calc{ .overrides = .{ .actions = actions, .durations = .{
|
|
226
|
+
.p1 = actions.p1.durations,
|
|
227
|
+
.p2 = actions.p2.durations,
|
|
228
|
+
} } },
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
var b = battle;
|
|
232
|
+
_ = try b.update(c1, c2, &opts);
|
|
233
|
+
stats.updates += 1;
|
|
234
|
+
|
|
235
|
+
var p1 = b.side(.P1);
|
|
236
|
+
var p2 = b.side(.P2);
|
|
237
|
+
|
|
238
|
+
var p: Rational(u128) = .{ .p = 0, .q = 1 };
|
|
239
|
+
try frontier.append(opts.chance.actions);
|
|
240
|
+
|
|
241
|
+
// zig fmt: off
|
|
242
|
+
for (Rolls.metronome(frontier.items[0].p1)) |p1_move| {
|
|
243
|
+
for (Rolls.metronome(frontier.items[0].p2)) |p2_move| {
|
|
244
|
+
|
|
245
|
+
if (!options.metronome and (p1_move != .None or p2_move != .None)) return null;
|
|
246
|
+
|
|
247
|
+
var i: usize = 0;
|
|
248
|
+
assert(frontier.items.len == 1);
|
|
249
|
+
while (i < frontier.items.len) : (i += 1) {
|
|
250
|
+
var template = frontier.items[i];
|
|
251
|
+
opts.calc.overrides.durations = .{
|
|
252
|
+
.p1 = template.p1.durations,
|
|
253
|
+
.p2 = template.p2.durations,
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
try debug(writer, template, true, .{ .color = i, .bold = true, .background = true });
|
|
257
|
+
|
|
258
|
+
var a: Actions = .{ .p1 = .{ .metronome = p1_move }, .p2 = .{ .metronome = p2_move } };
|
|
259
|
+
|
|
260
|
+
for (Rolls.speedTie(template.p1)) |tie| { a.p1.speed_tie = tie; a.p2.speed_tie = tie;
|
|
261
|
+
for (Rolls.sleep(template.p1, actions.p1)) |p1_slp| { a.p1.durations.sleep = p1_slp;
|
|
262
|
+
for (Rolls.sleep(template.p2, actions.p2)) |p2_slp| { a.p2.durations.sleep = p2_slp;
|
|
263
|
+
for (Rolls.disable(template.p1, actions.p1, p1_slp)) |p1_disable| { a.p1.durations.disable = p1_disable;
|
|
264
|
+
for (Rolls.disable(template.p2, actions.p2, p2_slp)) |p2_disable| { a.p2.durations.disable = p2_disable;
|
|
265
|
+
for (Rolls.confusion(template.p1, actions.p1, p1_slp)) |p1_cfz| { a.p1.durations.confusion = p1_cfz;
|
|
266
|
+
for (Rolls.confusion(template.p2, actions.p2, p1_slp)) |p2_cfz| { a.p2.durations.confusion = p2_cfz;
|
|
267
|
+
for (Rolls.confused(template.p1, p1_cfz)) |p1_cfzd| { a.p1.confused = p1_cfzd;
|
|
268
|
+
for (Rolls.confused(template.p2, p2_cfz)) |p2_cfzd| { a.p2.confused = p2_cfzd;
|
|
269
|
+
for (Rolls.paralyzed(template.p1, p1_cfzd)) |p1_par| { a.p1.paralyzed = p1_par;
|
|
270
|
+
for (Rolls.paralyzed(template.p2, p2_cfzd)) |p2_par| { a.p2.paralyzed = p2_par;
|
|
271
|
+
for (Rolls.attacking(template.p1, actions.p1, p1_par)) |p1_atk| { a.p1.durations.attacking = p1_atk;
|
|
272
|
+
for (Rolls.attacking(template.p2, actions.p2, p2_par)) |p2_atk| { a.p2.durations.attacking = p2_atk;
|
|
273
|
+
for (Rolls.binding(template.p1, actions.p1, p1_par)) |p1_bind| { a.p1.durations.binding = p1_bind;
|
|
274
|
+
for (Rolls.binding(template.p2, actions.p2, p2_par)) |p2_bind| { a.p2.durations.binding = p2_bind;
|
|
275
|
+
for (Rolls.duration(template.p1, p1_par)) |p1_dur| { a.p1.duration = p1_dur;
|
|
276
|
+
for (Rolls.duration(template.p2, p2_par)) |p2_dur| { a.p2.duration = p2_dur;
|
|
277
|
+
for (Rolls.hit(template.p1, p1_par)) |p1_hit| { a.p1.hit = p1_hit;
|
|
278
|
+
for (Rolls.hit(template.p2, p2_par)) |p2_hit| { a.p2.hit = p2_hit;
|
|
279
|
+
for (Rolls.psywave(template.p1, p1, p1_hit)) |p1_psywave| { a.p1.psywave = p1_psywave;
|
|
280
|
+
for (Rolls.psywave(template.p2, p2, p2_hit)) |p2_psywave| { a.p2.psywave = p2_psywave;
|
|
281
|
+
for (Rolls.moveSlot(template.p1, p1_hit)) |p1_slot| { a.p1.move_slot = p1_slot;
|
|
282
|
+
for (Rolls.moveSlot(template.p2, p2_hit)) |p2_slot| { a.p2.move_slot = p2_slot;
|
|
283
|
+
for (Rolls.multiHit(template.p1, p1_hit)) |p1_multi| { a.p1.multi_hit = p1_multi;
|
|
284
|
+
for (Rolls.multiHit(template.p2, p1_hit)) |p2_multi| { a.p2.multi_hit = p2_multi;
|
|
285
|
+
for (Rolls.secondaryChance(template.p1, p1_hit)) |p1_sec| { a.p1.secondary_chance = p1_sec;
|
|
286
|
+
for (Rolls.secondaryChance(template.p2, p2_hit)) |p2_sec| { a.p2.secondary_chance = p2_sec;
|
|
287
|
+
for (Rolls.criticalHit(template.p1, p1_hit)) |p1_crit| { a.p1.critical_hit = p1_crit;
|
|
288
|
+
for (Rolls.criticalHit(template.p2, p2_hit)) |p2_crit| { a.p2.critical_hit = p2_crit;
|
|
289
|
+
|
|
290
|
+
var p1_dmg = Rolls.damage(template.p1, p1_hit);
|
|
291
|
+
while (p1_dmg.min < p1_dmg.max) : (p1_dmg.min += 1) {
|
|
292
|
+
a.p1.damage = @intCast(p1_dmg.min);
|
|
293
|
+
var p1_min: u8 = 0;
|
|
294
|
+
|
|
295
|
+
var p2_dmg = Rolls.damage(template.p2, p2_hit);
|
|
296
|
+
while (p2_dmg.min < p2_dmg.max) : (p2_dmg.min += 1) {
|
|
297
|
+
a.p2.damage = @intCast(p2_dmg.min);
|
|
298
|
+
|
|
299
|
+
opts.calc.overrides.actions = a;
|
|
300
|
+
opts.chance = .{ .probability = .{}, .actions = actions };
|
|
301
|
+
const q = &opts.chance.probability;
|
|
302
|
+
|
|
303
|
+
b = battle;
|
|
304
|
+
_ = try b.update(c1, c2, &opts);
|
|
305
|
+
stats.updates += 1;
|
|
306
|
+
|
|
307
|
+
const p1_max: u8 = @intCast(p1_dmg.min);
|
|
308
|
+
const p2_max: u8 = @intCast(p2_dmg.min);
|
|
309
|
+
_ = cap;
|
|
310
|
+
|
|
311
|
+
// var p1_max = if (p1_min != 0) p1_min else
|
|
312
|
+
// try Rolls.coalesce(.P1, @intCast(u8, p1_dmg.min), &opts.calc.summaries, cap);
|
|
313
|
+
// var p2_max =
|
|
314
|
+
// try Rolls.coalesce(.P2, @intCast(u8, p2_dmg.min), &opts.calc.summaries, cap);
|
|
315
|
+
|
|
316
|
+
if (opts.chance.actions.matches(template)) {
|
|
317
|
+
if (!opts.chance.actions.eql(a)) {
|
|
318
|
+
try debug(writer, opts.chance.actions, false, .{ .color = i, .dim = true });
|
|
319
|
+
|
|
320
|
+
p1_min = p1_max;
|
|
321
|
+
p2_dmg.min = p2_max;
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
try debug(writer, opts.chance.actions, false, .{ .color = i });
|
|
326
|
+
|
|
327
|
+
for (p1_dmg.min..@as(u9, p1_max) + 1) |p1d| {
|
|
328
|
+
for (p2_dmg.min..@as(u9, p2_max) + 1) |p2d| {
|
|
329
|
+
var acts = opts.chance.actions;
|
|
330
|
+
acts.p1.damage = @intCast(p1d);
|
|
331
|
+
acts.p2.damage = @intCast(p2d);
|
|
332
|
+
if ((try seen.getOrPut(acts)).found_existing) {
|
|
333
|
+
err("already seen {}", .{acts}, options.seed);
|
|
334
|
+
return error.TestUnexpectedResult;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (p1_max != p1_dmg.min) try q.update(p1_max - p1_dmg.min + 1, 1);
|
|
340
|
+
if (p2_max != p2_dmg.min) try q.update(p2_max - p2_dmg.min + 1, 1);
|
|
341
|
+
try p.add(q);
|
|
342
|
+
stats.saved += 1;
|
|
343
|
+
|
|
344
|
+
if (p.q < p.p) {
|
|
345
|
+
err("improper fraction {}", .{p}, options.seed);
|
|
346
|
+
return error.TestUnexpectedResult;
|
|
347
|
+
}
|
|
348
|
+
} else {
|
|
349
|
+
try debug(writer, opts.chance.actions, false, .{ .dim = true });
|
|
350
|
+
|
|
351
|
+
if (!matches(opts.chance.actions, i, frontier.items)) {
|
|
352
|
+
try frontier.append(opts.chance.actions);
|
|
353
|
+
|
|
354
|
+
try debug(writer, opts.chance.actions, true, .{
|
|
355
|
+
.color = frontier.items.len - 1,
|
|
356
|
+
.dim = true,
|
|
357
|
+
.background = true
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
p1_min = p1_max;
|
|
363
|
+
p2_dmg.min = p2_max;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
assert(p1_min > 0 or p1_dmg.min == 0);
|
|
367
|
+
p1_dmg.min = p1_min;
|
|
368
|
+
|
|
369
|
+
}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
assert(frontier.items.len == i);
|
|
373
|
+
stats.frontier = @max(stats.frontier, i);
|
|
374
|
+
frontier.shrinkRetainingCapacity(1);
|
|
375
|
+
|
|
376
|
+
}}
|
|
377
|
+
// zig fmt: on
|
|
378
|
+
|
|
379
|
+
stats.seen = seen.count();
|
|
380
|
+
|
|
381
|
+
p.reduce();
|
|
382
|
+
if (p.p != 1 or p.q != 1) {
|
|
383
|
+
err("expected 1, found {}", .{p}, options.seed);
|
|
384
|
+
return error.TestExpectedEqual;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return stats;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
inline fn matches(actions: Actions, i: usize, frontier: []Actions) bool {
|
|
391
|
+
for (frontier, 0..) |f, j| {
|
|
392
|
+
// TODO: is skipping this redundant check worth it?
|
|
393
|
+
if (i == j) continue;
|
|
394
|
+
if (f.matches(actions)) return true;
|
|
395
|
+
}
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
fn err(comptime fmt: []const u8, v: anytype, seed: ?u64) void {
|
|
400
|
+
const w = std.io.getStdErr().writer();
|
|
401
|
+
w.print(fmt, v) catch return;
|
|
402
|
+
if (seed) |s| return w.print("{}\n", .{s}) catch return;
|
|
403
|
+
return w.writeByte('\n') catch return;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const Style = struct {
|
|
407
|
+
color: ?usize = null,
|
|
408
|
+
bold: bool = false,
|
|
409
|
+
background: bool = false,
|
|
410
|
+
dim: bool = false,
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
fn debug(writer: anytype, actions: Actions, shape: bool, style: Style) !void {
|
|
414
|
+
_ = .{ writer, actions, shape, style };
|
|
415
|
+
// const mod: usize = if (style.dim) 2 else 1;
|
|
416
|
+
// const background: usize = if (style.background) 4 else 3;
|
|
417
|
+
// const color: usize = if (style.color) |c| (c % 6) + 1 else 7;
|
|
418
|
+
// if (style.dim or style.bold) try writer.print("\x1b[{d}m", .{mod});
|
|
419
|
+
// try writer.print("\x1b[{d}{d}m", .{ background, color });
|
|
420
|
+
// try actions.fmt(writer, shape);
|
|
421
|
+
// try writer.writeAll("\x1b[0m\n");
|
|
422
|
+
// DEBUG
|
|
423
|
+
// if (style.dim) try writer.writeAll(" ");
|
|
424
|
+
// try actions.fmt(writer, shape);
|
|
425
|
+
// try writer.writeByte('\n');
|
|
426
|
+
}
|