Skip to content

Instantly share code, notes, and snippets.

@scheibo
Created September 17, 2024 23:01
Show Gist options
  • Save scheibo/4f322f305094ea822d0f0f2e3cb1d524 to your computer and use it in GitHub Desktop.
Save scheibo/4f322f305094ea822d0f0f2e3cb1d524 to your computer and use it in GitHub Desktop.
diff --git a/src/lib/gen1/calc.zig b/src/lib/gen1/calc.zig
index a1cb8797..e801ba4f 100644
--- a/src/lib/gen1/calc.zig
+++ b/src/lib/gen1/calc.zig
@@ -449,7 +449,10 @@ pub fn update(
if (try transitions(unfix(original), c1, c2, allocator, writer, .{
.durations = durations,
.cap = true,
- })) |stats| try expect(stats.frontier <= MAX_FRONTIER);
+ })) |stats| {
+ if (stats.frontier > MAX_FRONTIER) DEBUG(stats.frontier);
+ try expect(stats.frontier <= MAX_FRONTIER);
+ }
}
// Demonstrate that we can produce the same state by forcing the RNG to behave the
diff --git a/src/lib/gen1/helpers.zig b/src/lib/gen1/helpers.zig
index 3048647d..02805964 100644
--- a/src/lib/gen1/helpers.zig
+++ b/src/lib/gen1/helpers.zig
@@ -266,14 +266,8 @@ fn blocked(m: Move) bool {
fn durations(m: Move) bool {
// Any moves that have effects that result in duration tracking with -Dchance
return switch (Move.get(m).effect) {
- .Confusion,
- .Bide,
- .Sleep,
- .Rage,
- .Binding,
.Thrashing,
- .ConfusionChance,
- .Disable,
+ .Haze,
.Metronome,
=> true,
else => false,
diff --git a/src/test/fuzz.zig b/src/test/fuzz.zig
index 4b841783..3ee6e844 100644
--- a/src/test/fuzz.zig
+++ b/src/test/fuzz.zig
@@ -18,7 +18,7 @@ var initial: []u8 = &.{};
var buf: ?std.ArrayList(u8) = null;
var frames: ?std.ArrayList(Frame) = null;
-const transitions = false; // DEBUG
+const transitions = true; // DEBUG
const showdown = pkmn.options.showdown;
const chance = pkmn.options.chance;
@@ -71,7 +71,7 @@ pub fn fuzz(allocator: std.mem.Allocator, seed: u64, duration: usize) !void {
while (elapsed.read() < duration) {
last = random.src.seed;
- const opt = .{ .cleric = showdown, .block = false, .durations = false };
+ const opt = .{ .cleric = showdown, .block = false, .durations = true };
var battle = switch (gen) {
1 => pkmn.gen1.helpers.Battle.random(&random, opt),
else => unreachable,
diff --git a/src/tools/transitions.zig b/src/tools/transitions.zig
index fb6b4ddc..84d8f3f8 100644
--- a/src/tools/transitions.zig
+++ b/src/tools/transitions.zig
@@ -37,11 +37,12 @@ pub fn main() !void {
const seed = if (args.len > 2) try std.fmt.parseUnsigned(u64, args[2], 0) else 0x1234568;
// const PAR = pkmn.gen1.Status.init(.PAR);
+ const s = .{ .hp = 0xFFFF, .atk = 0xFFFF, .def = 0xFFFF, .spe = 0xFFFF, .spc = 0xEE00 };
var battle = switch (gen) {
1 => pkmn.gen1.helpers.Battle.init(
seed,
- &.{.{ .species = .Haunter, .moves = &.{ .Sing, .FireSpin } }},
- &.{.{ .species = .Arcanine, .moves = &.{ .Teleport, .MirrorMove } }},
+ &.{.{ .species = .Ivysaur, .stats = s, .hp = 22, .moves = &.{ .LightScreen, .Amnesia } }},
+ &.{.{ .species = .Rapidash, .moves = &.{ .Teleport, .Surf } }},
// ONE DAMAGE
// &.{.{ .species = .Wartortle, .level = 33, .moves = &.{.Scratch} }},
@@ -76,6 +77,14 @@ pub fn main() !void {
format(gen, &stream);
options.chance.reset();
+ _ = try battle.update(move(2), move(1), &options);
+ format(gen, &stream);
+ std.debug.print("\x1b[41m{} {}\x1b[K\x1b[0m\n", .{
+ options.chance.actions,
+ options.chance.durations,
+ });
+ options.chance.reset();
+
_ = try battle.update(move(1), move(1), &options);
format(gen, &stream);
std.debug.print("\x1b[41m{} {}\x1b[K\x1b[0m\n", .{
@@ -84,7 +93,7 @@ pub fn main() !void {
});
options.chance.reset();
- const stats = try pkmn.gen1.calc.transitions(battle, move(2), move(2), allocator, out, .{
+ const stats = try pkmn.gen1.calc.transitions(battle, move(1), move(2), allocator, out, .{
.durations = options.chance.durations,
.cap = true,
.seed = seed,
@scheibo
Copy link
Author

scheibo commented Sep 17, 2024

1900 [2024-09-17 15:30:12 -0700] npm run fuzz pkmn 1 1s 0x82996D821490959E
1901 [2024-09-17 15:32:10 -0700] npm run fuzz pkmn 1 1s 0xAF52B504F51A337C
1902 [2024-09-17 15:32:17 -0700] npm run fuzz pkmn 1 1s 0x20AE8FD80C60D930
1911 [2024-09-17 15:33:10 -0700] npm run fuzz pkmn 1 1s 0x20AE8FD80C60D930
1912 [2024-09-17 15:33:16 -0700] npm run fuzz pkmn 1 1s 0xAF52B504F51A337C
1915 [2024-09-17 15:33:26 -0700] npm run fuzz pkmn 1 1s 0xAF52B504F51A337C
1919 [2024-09-17 15:34:03 -0700] npm run fuzz pkmn 1 1s 0xAF52B504F51A337C
1933 [2024-09-17 15:41:46 -0700] npm run fuzz pkmn 1 1s 0x82996D821490959E

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment