unocab 0.8.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.
Files changed (105) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +108 -0
  3. package/esm/_dnt.shims.d.ts +4 -0
  4. package/esm/_dnt.shims.js +62 -0
  5. package/esm/_dnt.test_shims.d.ts +7 -0
  6. package/esm/deps/deno.land/std@0.190.0/fmt/colors.d.ts +270 -0
  7. package/esm/deps/deno.land/std@0.190.0/testing/_diff.d.ts +26 -0
  8. package/esm/deps/deno.land/std@0.190.0/testing/_format.d.ts +1 -0
  9. package/esm/deps/deno.land/std@0.190.0/testing/asserts.d.ts +284 -0
  10. package/esm/deps/deno.land/x/zod@v3.21.4/ZodError.d.ts +163 -0
  11. package/esm/deps/deno.land/x/zod@v3.21.4/ZodError.js +148 -0
  12. package/esm/deps/deno.land/x/zod@v3.21.4/errors.d.ts +5 -0
  13. package/esm/deps/deno.land/x/zod@v3.21.4/errors.js +9 -0
  14. package/esm/deps/deno.land/x/zod@v3.21.4/external.d.ts +6 -0
  15. package/esm/deps/deno.land/x/zod@v3.21.4/external.js +6 -0
  16. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/enumUtil.d.ts +8 -0
  17. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/enumUtil.js +1 -0
  18. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/errorUtil.d.ts +9 -0
  19. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/errorUtil.js +5 -0
  20. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/parseUtil.d.ts +78 -0
  21. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/parseUtil.js +104 -0
  22. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/partialUtil.d.ts +8 -0
  23. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/partialUtil.js +1 -0
  24. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/typeAliases.d.ts +2 -0
  25. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/typeAliases.js +1 -0
  26. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/util.d.ts +68 -0
  27. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/util.js +138 -0
  28. package/esm/deps/deno.land/x/zod@v3.21.4/index.d.ts +4 -0
  29. package/esm/deps/deno.land/x/zod@v3.21.4/index.js +4 -0
  30. package/esm/deps/deno.land/x/zod@v3.21.4/locales/en.d.ts +3 -0
  31. package/esm/deps/deno.land/x/zod@v3.21.4/locales/en.js +127 -0
  32. package/esm/deps/deno.land/x/zod@v3.21.4/mod.d.ts +1 -0
  33. package/esm/deps/deno.land/x/zod@v3.21.4/mod.js +1 -0
  34. package/esm/deps/deno.land/x/zod@v3.21.4/types.d.ts +965 -0
  35. package/esm/deps/deno.land/x/zod@v3.21.4/types.js +3689 -0
  36. package/esm/errors.d.ts +72 -0
  37. package/esm/errors.js +39 -0
  38. package/esm/game.d.ts +868 -0
  39. package/esm/game.js +868 -0
  40. package/esm/mod.d.ts +3 -0
  41. package/esm/mod.js +3 -0
  42. package/esm/package.json +3 -0
  43. package/esm/tests/basic-tests.d.ts +8 -0
  44. package/esm/tests/draw-tests.d.ts +8 -0
  45. package/esm/tests/non-specific-tests.test.d.ts +1 -0
  46. package/esm/tests/rule-violation-tests.d.ts +8 -0
  47. package/esm/tests/specific-tests.test.d.ts +1 -0
  48. package/esm/tests/test-utils.d.ts +91 -0
  49. package/esm/tests/turn-tests.d.ts +8 -0
  50. package/esm/types.d.ts +2280 -0
  51. package/esm/types.js +152 -0
  52. package/esm/utils.d.ts +19 -0
  53. package/esm/utils.js +44 -0
  54. package/package.json +32 -0
  55. package/script/_dnt.shims.d.ts +4 -0
  56. package/script/_dnt.shims.js +66 -0
  57. package/script/_dnt.test_shims.d.ts +7 -0
  58. package/script/deps/deno.land/std@0.190.0/fmt/colors.d.ts +270 -0
  59. package/script/deps/deno.land/std@0.190.0/testing/_diff.d.ts +26 -0
  60. package/script/deps/deno.land/std@0.190.0/testing/_format.d.ts +1 -0
  61. package/script/deps/deno.land/std@0.190.0/testing/asserts.d.ts +284 -0
  62. package/script/deps/deno.land/x/zod@v3.21.4/ZodError.d.ts +163 -0
  63. package/script/deps/deno.land/x/zod@v3.21.4/ZodError.js +152 -0
  64. package/script/deps/deno.land/x/zod@v3.21.4/errors.d.ts +5 -0
  65. package/script/deps/deno.land/x/zod@v3.21.4/errors.js +17 -0
  66. package/script/deps/deno.land/x/zod@v3.21.4/external.d.ts +6 -0
  67. package/script/deps/deno.land/x/zod@v3.21.4/external.js +22 -0
  68. package/script/deps/deno.land/x/zod@v3.21.4/helpers/enumUtil.d.ts +8 -0
  69. package/script/deps/deno.land/x/zod@v3.21.4/helpers/enumUtil.js +2 -0
  70. package/script/deps/deno.land/x/zod@v3.21.4/helpers/errorUtil.d.ts +9 -0
  71. package/script/deps/deno.land/x/zod@v3.21.4/helpers/errorUtil.js +8 -0
  72. package/script/deps/deno.land/x/zod@v3.21.4/helpers/parseUtil.d.ts +78 -0
  73. package/script/deps/deno.land/x/zod@v3.21.4/helpers/parseUtil.js +119 -0
  74. package/script/deps/deno.land/x/zod@v3.21.4/helpers/partialUtil.d.ts +8 -0
  75. package/script/deps/deno.land/x/zod@v3.21.4/helpers/partialUtil.js +2 -0
  76. package/script/deps/deno.land/x/zod@v3.21.4/helpers/typeAliases.d.ts +2 -0
  77. package/script/deps/deno.land/x/zod@v3.21.4/helpers/typeAliases.js +2 -0
  78. package/script/deps/deno.land/x/zod@v3.21.4/helpers/util.d.ts +68 -0
  79. package/script/deps/deno.land/x/zod@v3.21.4/helpers/util.js +142 -0
  80. package/script/deps/deno.land/x/zod@v3.21.4/index.d.ts +4 -0
  81. package/script/deps/deno.land/x/zod@v3.21.4/index.js +33 -0
  82. package/script/deps/deno.land/x/zod@v3.21.4/locales/en.d.ts +3 -0
  83. package/script/deps/deno.land/x/zod@v3.21.4/locales/en.js +129 -0
  84. package/script/deps/deno.land/x/zod@v3.21.4/mod.d.ts +1 -0
  85. package/script/deps/deno.land/x/zod@v3.21.4/mod.js +17 -0
  86. package/script/deps/deno.land/x/zod@v3.21.4/types.d.ts +965 -0
  87. package/script/deps/deno.land/x/zod@v3.21.4/types.js +3739 -0
  88. package/script/errors.d.ts +72 -0
  89. package/script/errors.js +43 -0
  90. package/script/game.d.ts +868 -0
  91. package/script/game.js +895 -0
  92. package/script/mod.d.ts +3 -0
  93. package/script/mod.js +19 -0
  94. package/script/package.json +3 -0
  95. package/script/tests/basic-tests.d.ts +8 -0
  96. package/script/tests/draw-tests.d.ts +8 -0
  97. package/script/tests/non-specific-tests.test.d.ts +1 -0
  98. package/script/tests/rule-violation-tests.d.ts +8 -0
  99. package/script/tests/specific-tests.test.d.ts +1 -0
  100. package/script/tests/test-utils.d.ts +91 -0
  101. package/script/tests/turn-tests.d.ts +8 -0
  102. package/script/types.d.ts +2280 -0
  103. package/script/types.js +155 -0
  104. package/script/utils.d.ts +19 -0
  105. package/script/utils.js +50 -0
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gameState = exports.shorthandGameState = exports.fullGameState = exports.infoEvent = exports.gameEvent = exports.chooseColorEvent = exports.passEvent = exports.drawEvent = exports.bluffCalledEvent = exports.cardPlayedEvent = exports.playerId = exports.card = exports.cardColor = exports.allCards = exports.specialCards = exports.nonColorSwitchingScs = exports.colorSwitchingScs = exports.regularCards = void 0;
4
+ const mod_js_1 = require("./deps/deno.land/x/zod@v3.21.4/mod.js");
5
+ /*
6
+ * This file exports both Zod types and TS types for everything
7
+ * Zod types start with a lowercase character, while TS types
8
+ * start with an uppercase character.
9
+ */
10
+ // ─── Card Utils ──────────────────────────────────────────────────────────────
11
+ exports.regularCards = mod_js_1.z.enum([
12
+ "zero",
13
+ "one",
14
+ "two",
15
+ "three",
16
+ "four",
17
+ "five",
18
+ "six",
19
+ "seven",
20
+ "eight",
21
+ "nine",
22
+ ]);
23
+ // color-switching special cards
24
+ exports.colorSwitchingScs = mod_js_1.z.enum(["plus-four", "color-chooser"]);
25
+ // non color-switching special cards
26
+ exports.nonColorSwitchingScs = mod_js_1.z.enum(["plus-two", "reverse", "skip"]);
27
+ exports.specialCards = mod_js_1.z.enum([
28
+ ...exports.nonColorSwitchingScs.options,
29
+ ...exports.colorSwitchingScs.options,
30
+ ]);
31
+ // all cards = regular cards + special cards
32
+ exports.allCards = mod_js_1.z.enum([
33
+ ...exports.regularCards.options,
34
+ ...exports.specialCards.options,
35
+ ]);
36
+ exports.cardColor = mod_js_1.z.enum(["red", "blue", "green", "yellow"]);
37
+ exports.card = mod_js_1.z.union([
38
+ mod_js_1.z.object({
39
+ type: mod_js_1.z.union([exports.regularCards, exports.nonColorSwitchingScs]),
40
+ color: exports.cardColor,
41
+ }),
42
+ mod_js_1.z.object({
43
+ type: exports.colorSwitchingScs,
44
+ color: mod_js_1.z.undefined(),
45
+ }),
46
+ ]);
47
+ exports.playerId = mod_js_1.z.string();
48
+ // ─── Game Events ─────────────────────────────────────────────────────────────
49
+ exports.cardPlayedEvent = mod_js_1.z.object({
50
+ type: mod_js_1.z.literal("card_played"),
51
+ by: exports.playerId,
52
+ card: exports.card,
53
+ });
54
+ exports.bluffCalledEvent = mod_js_1.z.object({
55
+ type: mod_js_1.z.literal("bluff_called"),
56
+ by: exports.playerId,
57
+ });
58
+ exports.drawEvent = mod_js_1.z.object({
59
+ type: mod_js_1.z.literal("draw"),
60
+ by: exports.playerId,
61
+ });
62
+ exports.passEvent = mod_js_1.z.object({
63
+ type: mod_js_1.z.literal("pass"),
64
+ by: exports.playerId,
65
+ });
66
+ exports.chooseColorEvent = mod_js_1.z.object({
67
+ type: mod_js_1.z.literal("choose-color"),
68
+ by: exports.playerId,
69
+ color: exports.cardColor,
70
+ });
71
+ // the collective game event object
72
+ exports.gameEvent = mod_js_1.z.union([
73
+ exports.cardPlayedEvent,
74
+ exports.bluffCalledEvent,
75
+ exports.chooseColorEvent,
76
+ exports.drawEvent,
77
+ exports.passEvent,
78
+ ]);
79
+ // the game info event is added the engine
80
+ exports.infoEvent = mod_js_1.z.object({
81
+ type: mod_js_1.z.literal("game_info"),
82
+ info: mod_js_1.z.union([
83
+ mod_js_1.z.object({
84
+ type: mod_js_1.z.literal("bluff_called"),
85
+ by: exports.playerId,
86
+ }),
87
+ mod_js_1.z.object({
88
+ type: mod_js_1.z.literal("bluff_call_succeeded"),
89
+ by: exports.playerId,
90
+ of: exports.playerId,
91
+ }),
92
+ mod_js_1.z.object({
93
+ type: mod_js_1.z.literal("bluff_call_failed"),
94
+ by: exports.playerId,
95
+ of: exports.playerId,
96
+ }),
97
+ mod_js_1.z.object({
98
+ type: mod_js_1.z.literal("seed_changed"),
99
+ newSeed: mod_js_1.z.number(),
100
+ }),
101
+ mod_js_1.z.object({
102
+ type: mod_js_1.z.literal("player_won"),
103
+ id: exports.playerId,
104
+ }),
105
+ mod_js_1.z.object({
106
+ type: mod_js_1.z.literal("game_ended"),
107
+ loser: exports.playerId,
108
+ }),
109
+ mod_js_1.z.object({
110
+ type: mod_js_1.z.literal("player_joined"),
111
+ id: exports.playerId,
112
+ }),
113
+ mod_js_1.z.object({
114
+ type: mod_js_1.z.literal("player_left"),
115
+ id: exports.playerId,
116
+ }),
117
+ mod_js_1.z.object({
118
+ type: mod_js_1.z.literal("pile_to_deck"),
119
+ }),
120
+ ]),
121
+ });
122
+ // ─── Game Utils ──────────────────────────────────────────────────────────────
123
+ const commonGameState = {
124
+ // the index gets modulo'd with the player count to get the active player index
125
+ index: mod_js_1.z.number(),
126
+ initialSeed: mod_js_1.z.number(),
127
+ players: exports.playerId.array(),
128
+ // game options
129
+ stackPlusTwos: mod_js_1.z.boolean(),
130
+ // this is a cache, since all of the info here can be obtained from the
131
+ // events array; but since it's expensive to do that all the time, we
132
+ // can keep it here. note that re-obtaining this info in shorthand mode
133
+ // is not possible, since past events are not kept, so it acts as state.
134
+ cache: mod_js_1.z.object({
135
+ hands: mod_js_1.z.record(exports.playerId, exports.card.array()),
136
+ deck: exports.card.array(),
137
+ seed: mod_js_1.z.number(),
138
+ stackedPlusTwos: mod_js_1.z.number(),
139
+ turnStep: mod_js_1.z.union([mod_js_1.z.literal(1), mod_js_1.z.literal(-1)]),
140
+ ended: mod_js_1.z.boolean(),
141
+ pile: exports.card.array(),
142
+ last3CardPlayOrColorChanges: mod_js_1.z.union([exports.card, exports.cardColor]).array(),
143
+ }),
144
+ };
145
+ exports.fullGameState = mod_js_1.z.object({
146
+ shorthandMode: mod_js_1.z.literal(false),
147
+ ...commonGameState,
148
+ events: mod_js_1.z.union([exports.gameEvent, exports.infoEvent]).array(),
149
+ });
150
+ exports.shorthandGameState = mod_js_1.z.object({
151
+ shorthandMode: mod_js_1.z.literal(true),
152
+ ...commonGameState,
153
+ events: exports.gameEvent.array(),
154
+ });
155
+ exports.gameState = mod_js_1.z.union([exports.fullGameState, exports.shorthandGameState]);
@@ -0,0 +1,19 @@
1
+ export declare const ENGINE_ID = "ENGINE";
2
+ export declare const MAX_SHORTHAND_EVENTS = 5;
3
+ export declare const MIN_PLAYERS = 2;
4
+ export declare const MAX_PLAYERS = 10;
5
+ export declare const DECK: ({
6
+ type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
7
+ color: "red" | "blue" | "green" | "yellow";
8
+ } | {
9
+ type: "plus-four" | "color-chooser";
10
+ color?: undefined;
11
+ })[];
12
+ export declare function cyrb128(str: string): number;
13
+ export declare function includes<T>(arr: T[], v: unknown): v is T;
14
+ export declare function exhaustive(_: never): void;
15
+ type Without<T, U> = {
16
+ [P in Exclude<keyof T, keyof U>]?: never;
17
+ };
18
+ export type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
19
+ export {};
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exhaustive = exports.includes = exports.cyrb128 = exports.DECK = exports.MAX_PLAYERS = exports.MIN_PLAYERS = exports.MAX_SHORTHAND_EVENTS = exports.ENGINE_ID = void 0;
4
+ const types_js_1 = require("./types.js");
5
+ // 36 chars by default to match uuid length
6
+ exports.ENGINE_ID = "ENGINE";
7
+ // we need at least 5 events, since 3 events are taken
8
+ // up for +4, choose color, and call bluff, and the 4th
9
+ // last event is hence needed to check for bluff. The fifth
10
+ // last card is kept just in case it's needed for checkEvent.
11
+ exports.MAX_SHORTHAND_EVENTS = 5;
12
+ // the minimum and maximum number of players in a game
13
+ exports.MIN_PLAYERS = 2;
14
+ exports.MAX_PLAYERS = 10;
15
+ const [zero, ...nonZeroRegularTypes] = types_js_1.regularCards.options;
16
+ const twoCardTypes = [...nonZeroRegularTypes, ...types_js_1.nonColorSwitchingScs.options];
17
+ exports.DECK = [
18
+ // one zero of each color
19
+ ...types_js_1.cardColor.options.map((color) => ({
20
+ type: zero,
21
+ color,
22
+ })),
23
+ // two of one-nine, plus-two, reverse, and skip of each color
24
+ ...types_js_1.cardColor.options.flatMap((color) => twoCardTypes.flatMap((type) => Array(2).fill({ type, color }))),
25
+ // four of each of the color switching special cards
26
+ ...types_js_1.colorSwitchingScs.options.flatMap((type) => Array(4).fill({ type })),
27
+ ];
28
+ // stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript
29
+ function cyrb128(str) {
30
+ let h1 = 1779033703, h2 = 3144134277, h3 = 1013904242, h4 = 2773480762;
31
+ for (let i = 0, k; i < str.length; i++) {
32
+ k = str.charCodeAt(i);
33
+ h1 = h2 ^ Math.imul(h1 ^ k, 597399067);
34
+ h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);
35
+ h3 = h4 ^ Math.imul(h3 ^ k, 951274213);
36
+ h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);
37
+ }
38
+ h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067);
39
+ h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233);
40
+ h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213);
41
+ h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179);
42
+ return (h1 ^ h2 ^ h3 ^ h4) >>> 0;
43
+ }
44
+ exports.cyrb128 = cyrb128;
45
+ function includes(arr, v) {
46
+ return arr.includes(v);
47
+ }
48
+ exports.includes = includes;
49
+ function exhaustive(_) { }
50
+ exports.exhaustive = exhaustive;