@pkmn/engine 0.1.0-dev.83de29ee → 0.1.0-dev.886adbe3

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 (61) hide show
  1. package/LICENSE +1 -3
  2. package/README.md +97 -59
  3. package/build/pkg/addon.js +9 -9
  4. package/build/pkg/addon.js.map +1 -1
  5. package/build/pkg/data/ids.json +12 -12
  6. package/build/pkg/data/layout.json +26 -4
  7. package/build/pkg/data/protocol.json +69 -12
  8. package/build/pkg/data.d.ts +4 -4
  9. package/build/pkg/data.js.map +1 -1
  10. package/build/pkg/gen1.js +23 -18
  11. package/build/pkg/gen1.js.map +1 -1
  12. package/build/pkg/index.d.ts +5 -8
  13. package/build/pkg/index.js +2 -5
  14. package/build/pkg/index.js.map +1 -1
  15. package/build/pkg/protocol.d.ts +4 -2
  16. package/build/pkg/protocol.js +65 -44
  17. package/build/pkg/protocol.js.map +1 -1
  18. package/build/test/display.js +10 -6
  19. package/build/test/display.js.map +1 -1
  20. package/build/tools/debug.js +5 -4
  21. package/build/tools/debug.js.map +1 -1
  22. package/build.zig +286 -131
  23. package/package.json +56 -24
  24. package/src/bin/install-pkmn-engine +39 -24
  25. package/src/lib/common/array.zig +77 -0
  26. package/src/lib/common/battle.zig +17 -0
  27. package/src/lib/common/data.zig +19 -31
  28. package/src/lib/common/debug.zig +22 -13
  29. package/src/lib/common/js.zig +120 -0
  30. package/src/lib/common/optional.zig +71 -0
  31. package/src/lib/common/options.zig +11 -0
  32. package/src/lib/common/protocol.zig +911 -367
  33. package/src/lib/common/rational.zig +447 -0
  34. package/src/lib/common/rng.zig +31 -22
  35. package/src/lib/common/util.zig +61 -0
  36. package/src/lib/gen1/calc.zig +804 -0
  37. package/src/lib/gen1/chance.zig +1167 -0
  38. package/src/lib/gen1/data/moves.zig +202 -190
  39. package/src/lib/gen1/data/species.zig +5 -5
  40. package/src/lib/gen1/data/types.zig +10 -10
  41. package/src/lib/gen1/data.zig +94 -81
  42. package/src/lib/gen1/helpers.zig +143 -39
  43. package/src/lib/gen1/mechanics.zig +1134 -786
  44. package/src/lib/gen2/calc.zig +161 -0
  45. package/src/lib/gen2/chance.zig +902 -0
  46. package/src/lib/gen2/data/items.zig +14 -20
  47. package/src/lib/gen2/data/moves.zig +664 -570
  48. package/src/lib/gen2/data/species.zig +2 -2
  49. package/src/lib/gen2/data/types.zig +137 -34
  50. package/src/lib/gen2/data.zig +125 -86
  51. package/src/lib/gen2/generated.zig +806 -0
  52. package/src/lib/gen2/helpers.zig +54 -32
  53. package/src/lib/gen2/mechanics.zig +3564 -15
  54. package/src/lib/node.zig +131 -0
  55. package/src/lib/pkmn.zig +81 -5
  56. package/src/lib/wasm.zig +13 -0
  57. package/src/test/display/pkmn.html.tmpl +5 -5
  58. package/src/lib/binding/node.zig +0 -229
  59. package/src/lib/binding/wasm.zig +0 -10
  60. package/src/lib/gen1/README.md +0 -808
  61. package/src/lib/gen2/README.md +0 -309
@@ -0,0 +1,71 @@
1
+ const std = @import("std");
2
+
3
+ const expect = std.testing.expect;
4
+ const assert = std.debug.assert;
5
+
6
+ const Bool = if (@hasField(std.builtin.Type, "bool")) .bool else .Bool;
7
+
8
+ // TODO: ziglang/zig#104
9
+ pub fn Optional(comptime T: type) type {
10
+ const fields = std.meta.fields(switch (@typeInfo(T)) {
11
+ Bool => enum { false, true },
12
+ else => T,
13
+ });
14
+
15
+ var enumFields: [fields.len + 1]std.builtin.Type.EnumField = undefined;
16
+ var decls = [_]std.builtin.Type.Declaration{};
17
+
18
+ enumFields[0] = .{ .name = "None", .value = 0 };
19
+
20
+ inline for (fields, 1..) |field, i| {
21
+ assert(!std.mem.eql(u8, field.name, "None"));
22
+ enumFields[i] = .{
23
+ .name = field.name,
24
+ .value = i,
25
+ };
26
+ }
27
+
28
+ const options = .{
29
+ .tag_type = std.math.IntFittingRange(0, fields.len),
30
+ .fields = &enumFields,
31
+ .decls = &decls,
32
+ .is_exhaustive = true,
33
+ };
34
+ return @Type(if (@hasField(std.builtin.Type, "enum"))
35
+ .{ .@"enum" = options }
36
+ else
37
+ .{ .Enum = options });
38
+ }
39
+
40
+ test Optional {
41
+ try expect(@bitSizeOf(Optional(bool)) == 2);
42
+
43
+ const a: Optional(bool) = .true;
44
+ try expect(a != .None);
45
+ try expect(a == .true);
46
+ try expect(a != .false);
47
+
48
+ const b: Optional(bool) = .None;
49
+ try expect(b == .None);
50
+ try expect(b != .true);
51
+ try expect(b != .false);
52
+
53
+ const Player = @import("data.zig").Player;
54
+ try expect(@bitSizeOf(Optional(Player)) == 2);
55
+
56
+ const p: Optional(Player) = .P2;
57
+ try expect(p != .None);
58
+ try expect(p != .P1);
59
+ try expect(p == .P2);
60
+
61
+ const q: Optional(Player) = .None;
62
+ try expect(q == .None);
63
+ try expect(q != .P1);
64
+ try expect(q != .P2);
65
+
66
+ const Three = enum(u2) { A, B, C };
67
+ try expect(@bitSizeOf(Optional(Three)) == 2);
68
+
69
+ const Four = enum(u2) { A, B, C, D };
70
+ try expect(@bitSizeOf(Optional(Four)) == 3);
71
+ }
@@ -1,11 +1,16 @@
1
1
  const build_options = @import("build_options");
2
2
  const root = @import("root");
3
3
 
4
+ /// Configures the behavior of the pkmn package.
4
5
  pub const Options = struct {
5
6
  showdown: ?bool = null,
6
7
  log: ?bool = null,
8
+ chance: ?bool = null,
9
+ calc: ?bool = null,
7
10
  advance: ?bool = null,
8
11
  ebc: ?bool = null,
12
+ key: ?bool = null,
13
+ miss: ?bool = null,
9
14
  internal: ?bool = null,
10
15
  };
11
16
 
@@ -13,9 +18,15 @@ pub const Options = struct {
13
18
  pub const showdown = get("showdown", false);
14
19
  /// Whether or not protocol message logging is enabled.
15
20
  pub const log = get("log", false);
21
+ /// Whether or not update probability tracking is enabled.
22
+ pub const chance = get("chance", false);
23
+ /// Whether or not damage calculator support is enabled.
24
+ pub const calc = get("calc", false);
16
25
 
17
26
  pub const advance = get("advance", true);
18
27
  pub const ebc = get("ebc", true);
28
+ pub const key = get("key", false);
29
+ pub const miss = get("miss", true);
19
30
  pub const internal = get("internal", false);
20
31
 
21
32
  fn get(comptime name: []const u8, default: bool) bool {