unocab 0.8.0 → 0.9.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 (108) hide show
  1. package/README.md +24 -4
  2. package/{script → dist}/errors.d.ts +13 -3
  3. package/dist/game.d.ts +459 -0
  4. package/dist/index.d.ts +3 -0
  5. package/dist/index.js +786 -0
  6. package/dist/types.d.ts +1106 -0
  7. package/{esm → dist}/utils.d.ts +4 -3
  8. package/package.json +17 -11
  9. package/esm/_dnt.shims.d.ts +0 -4
  10. package/esm/_dnt.shims.js +0 -62
  11. package/esm/_dnt.test_shims.d.ts +0 -7
  12. package/esm/deps/deno.land/std@0.190.0/fmt/colors.d.ts +0 -270
  13. package/esm/deps/deno.land/std@0.190.0/testing/_diff.d.ts +0 -26
  14. package/esm/deps/deno.land/std@0.190.0/testing/_format.d.ts +0 -1
  15. package/esm/deps/deno.land/std@0.190.0/testing/asserts.d.ts +0 -284
  16. package/esm/deps/deno.land/x/zod@v3.21.4/ZodError.d.ts +0 -163
  17. package/esm/deps/deno.land/x/zod@v3.21.4/ZodError.js +0 -148
  18. package/esm/deps/deno.land/x/zod@v3.21.4/errors.d.ts +0 -5
  19. package/esm/deps/deno.land/x/zod@v3.21.4/errors.js +0 -9
  20. package/esm/deps/deno.land/x/zod@v3.21.4/external.d.ts +0 -6
  21. package/esm/deps/deno.land/x/zod@v3.21.4/external.js +0 -6
  22. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/enumUtil.d.ts +0 -8
  23. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/enumUtil.js +0 -1
  24. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/errorUtil.d.ts +0 -9
  25. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/errorUtil.js +0 -5
  26. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/parseUtil.d.ts +0 -78
  27. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/parseUtil.js +0 -104
  28. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/partialUtil.d.ts +0 -8
  29. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/partialUtil.js +0 -1
  30. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/typeAliases.d.ts +0 -2
  31. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/typeAliases.js +0 -1
  32. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/util.d.ts +0 -68
  33. package/esm/deps/deno.land/x/zod@v3.21.4/helpers/util.js +0 -138
  34. package/esm/deps/deno.land/x/zod@v3.21.4/index.d.ts +0 -4
  35. package/esm/deps/deno.land/x/zod@v3.21.4/index.js +0 -4
  36. package/esm/deps/deno.land/x/zod@v3.21.4/locales/en.d.ts +0 -3
  37. package/esm/deps/deno.land/x/zod@v3.21.4/locales/en.js +0 -127
  38. package/esm/deps/deno.land/x/zod@v3.21.4/mod.d.ts +0 -1
  39. package/esm/deps/deno.land/x/zod@v3.21.4/mod.js +0 -1
  40. package/esm/deps/deno.land/x/zod@v3.21.4/types.d.ts +0 -965
  41. package/esm/deps/deno.land/x/zod@v3.21.4/types.js +0 -3689
  42. package/esm/errors.d.ts +0 -72
  43. package/esm/errors.js +0 -39
  44. package/esm/game.d.ts +0 -868
  45. package/esm/game.js +0 -868
  46. package/esm/mod.d.ts +0 -3
  47. package/esm/mod.js +0 -3
  48. package/esm/package.json +0 -3
  49. package/esm/tests/basic-tests.d.ts +0 -8
  50. package/esm/tests/draw-tests.d.ts +0 -8
  51. package/esm/tests/non-specific-tests.test.d.ts +0 -1
  52. package/esm/tests/rule-violation-tests.d.ts +0 -8
  53. package/esm/tests/specific-tests.test.d.ts +0 -1
  54. package/esm/tests/test-utils.d.ts +0 -91
  55. package/esm/tests/turn-tests.d.ts +0 -8
  56. package/esm/types.d.ts +0 -2280
  57. package/esm/types.js +0 -152
  58. package/esm/utils.js +0 -44
  59. package/script/_dnt.shims.d.ts +0 -4
  60. package/script/_dnt.shims.js +0 -66
  61. package/script/_dnt.test_shims.d.ts +0 -7
  62. package/script/deps/deno.land/std@0.190.0/fmt/colors.d.ts +0 -270
  63. package/script/deps/deno.land/std@0.190.0/testing/_diff.d.ts +0 -26
  64. package/script/deps/deno.land/std@0.190.0/testing/_format.d.ts +0 -1
  65. package/script/deps/deno.land/std@0.190.0/testing/asserts.d.ts +0 -284
  66. package/script/deps/deno.land/x/zod@v3.21.4/ZodError.d.ts +0 -163
  67. package/script/deps/deno.land/x/zod@v3.21.4/ZodError.js +0 -152
  68. package/script/deps/deno.land/x/zod@v3.21.4/errors.d.ts +0 -5
  69. package/script/deps/deno.land/x/zod@v3.21.4/errors.js +0 -17
  70. package/script/deps/deno.land/x/zod@v3.21.4/external.d.ts +0 -6
  71. package/script/deps/deno.land/x/zod@v3.21.4/external.js +0 -22
  72. package/script/deps/deno.land/x/zod@v3.21.4/helpers/enumUtil.d.ts +0 -8
  73. package/script/deps/deno.land/x/zod@v3.21.4/helpers/enumUtil.js +0 -2
  74. package/script/deps/deno.land/x/zod@v3.21.4/helpers/errorUtil.d.ts +0 -9
  75. package/script/deps/deno.land/x/zod@v3.21.4/helpers/errorUtil.js +0 -8
  76. package/script/deps/deno.land/x/zod@v3.21.4/helpers/parseUtil.d.ts +0 -78
  77. package/script/deps/deno.land/x/zod@v3.21.4/helpers/parseUtil.js +0 -119
  78. package/script/deps/deno.land/x/zod@v3.21.4/helpers/partialUtil.d.ts +0 -8
  79. package/script/deps/deno.land/x/zod@v3.21.4/helpers/partialUtil.js +0 -2
  80. package/script/deps/deno.land/x/zod@v3.21.4/helpers/typeAliases.d.ts +0 -2
  81. package/script/deps/deno.land/x/zod@v3.21.4/helpers/typeAliases.js +0 -2
  82. package/script/deps/deno.land/x/zod@v3.21.4/helpers/util.d.ts +0 -68
  83. package/script/deps/deno.land/x/zod@v3.21.4/helpers/util.js +0 -142
  84. package/script/deps/deno.land/x/zod@v3.21.4/index.d.ts +0 -4
  85. package/script/deps/deno.land/x/zod@v3.21.4/index.js +0 -33
  86. package/script/deps/deno.land/x/zod@v3.21.4/locales/en.d.ts +0 -3
  87. package/script/deps/deno.land/x/zod@v3.21.4/locales/en.js +0 -129
  88. package/script/deps/deno.land/x/zod@v3.21.4/mod.d.ts +0 -1
  89. package/script/deps/deno.land/x/zod@v3.21.4/mod.js +0 -17
  90. package/script/deps/deno.land/x/zod@v3.21.4/types.d.ts +0 -965
  91. package/script/deps/deno.land/x/zod@v3.21.4/types.js +0 -3739
  92. package/script/errors.js +0 -43
  93. package/script/game.d.ts +0 -868
  94. package/script/game.js +0 -895
  95. package/script/mod.d.ts +0 -3
  96. package/script/mod.js +0 -19
  97. package/script/package.json +0 -3
  98. package/script/tests/basic-tests.d.ts +0 -8
  99. package/script/tests/draw-tests.d.ts +0 -8
  100. package/script/tests/non-specific-tests.test.d.ts +0 -1
  101. package/script/tests/rule-violation-tests.d.ts +0 -8
  102. package/script/tests/specific-tests.test.d.ts +0 -1
  103. package/script/tests/test-utils.d.ts +0 -91
  104. package/script/tests/turn-tests.d.ts +0 -8
  105. package/script/types.d.ts +0 -2280
  106. package/script/types.js +0 -155
  107. package/script/utils.d.ts +0 -19
  108. package/script/utils.js +0 -50
package/esm/game.d.ts DELETED
@@ -1,868 +0,0 @@
1
- import { UECode, UnocabError } from "./errors.js";
2
- import { Card, CardColor, FullGameState, GameEvent, GameState, InfoEvent, PlayerId, ProcessEventResult, ShorthandGameState } from "./types.js";
3
- import { XOR } from "./utils.js";
4
- export declare class Game<Shorthand extends boolean = false> {
5
- protected _state: boolean extends Shorthand ? GameState : true extends Shorthand ? ShorthandGameState : FullGameState;
6
- get state(): boolean extends Shorthand ? {
7
- shorthandMode: false;
8
- events: ({
9
- type: "card_played";
10
- by: string;
11
- card: {
12
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
13
- color: "red" | "blue" | "green" | "yellow";
14
- } | {
15
- type: "plus-four" | "color-chooser";
16
- color?: undefined;
17
- };
18
- } | {
19
- type: "bluff_called";
20
- by: string;
21
- } | {
22
- type: "draw";
23
- by: string;
24
- } | {
25
- type: "pass";
26
- by: string;
27
- } | {
28
- type: "choose-color";
29
- color: "red" | "blue" | "green" | "yellow";
30
- by: string;
31
- } | {
32
- type: "game_info";
33
- info: {
34
- type: "bluff_called";
35
- by: string;
36
- } | {
37
- type: "bluff_call_succeeded";
38
- by: string;
39
- of: string;
40
- } | {
41
- type: "bluff_call_failed";
42
- by: string;
43
- of: string;
44
- } | {
45
- type: "seed_changed";
46
- newSeed: number;
47
- } | {
48
- type: "player_won";
49
- id: string;
50
- } | {
51
- type: "game_ended";
52
- loser: string;
53
- } | {
54
- type: "player_joined";
55
- id: string;
56
- } | {
57
- type: "player_left";
58
- id: string;
59
- } | {
60
- type: "pile_to_deck";
61
- };
62
- })[];
63
- index: number;
64
- initialSeed: number;
65
- players: string[];
66
- stackPlusTwos: boolean;
67
- cache: {
68
- hands: Record<string, ({
69
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
70
- color: "red" | "blue" | "green" | "yellow";
71
- } | {
72
- type: "plus-four" | "color-chooser";
73
- color?: undefined;
74
- })[]>;
75
- deck: ({
76
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
77
- color: "red" | "blue" | "green" | "yellow";
78
- } | {
79
- type: "plus-four" | "color-chooser";
80
- color?: undefined;
81
- })[];
82
- seed: number;
83
- stackedPlusTwos: number;
84
- turnStep: 1 | -1;
85
- ended: boolean;
86
- pile: ({
87
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
88
- color: "red" | "blue" | "green" | "yellow";
89
- } | {
90
- type: "plus-four" | "color-chooser";
91
- color?: undefined;
92
- })[];
93
- last3CardPlayOrColorChanges: ("red" | "blue" | "green" | "yellow" | {
94
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
95
- color: "red" | "blue" | "green" | "yellow";
96
- } | {
97
- type: "plus-four" | "color-chooser";
98
- color?: undefined;
99
- })[];
100
- };
101
- } | {
102
- shorthandMode: true;
103
- events: ({
104
- type: "card_played";
105
- by: string;
106
- card: {
107
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
108
- color: "red" | "blue" | "green" | "yellow";
109
- } | {
110
- type: "plus-four" | "color-chooser";
111
- color?: undefined;
112
- };
113
- } | {
114
- type: "bluff_called";
115
- by: string;
116
- } | {
117
- type: "draw";
118
- by: string;
119
- } | {
120
- type: "pass";
121
- by: string;
122
- } | {
123
- type: "choose-color";
124
- color: "red" | "blue" | "green" | "yellow";
125
- by: string;
126
- })[];
127
- index: number;
128
- initialSeed: number;
129
- players: string[];
130
- stackPlusTwos: boolean;
131
- cache: {
132
- hands: Record<string, ({
133
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
134
- color: "red" | "blue" | "green" | "yellow";
135
- } | {
136
- type: "plus-four" | "color-chooser";
137
- color?: undefined;
138
- })[]>;
139
- deck: ({
140
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
141
- color: "red" | "blue" | "green" | "yellow";
142
- } | {
143
- type: "plus-four" | "color-chooser";
144
- color?: undefined;
145
- })[];
146
- seed: number;
147
- stackedPlusTwos: number;
148
- turnStep: 1 | -1;
149
- ended: boolean;
150
- pile: ({
151
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
152
- color: "red" | "blue" | "green" | "yellow";
153
- } | {
154
- type: "plus-four" | "color-chooser";
155
- color?: undefined;
156
- })[];
157
- last3CardPlayOrColorChanges: ("red" | "blue" | "green" | "yellow" | {
158
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
159
- color: "red" | "blue" | "green" | "yellow";
160
- } | {
161
- type: "plus-four" | "color-chooser";
162
- color?: undefined;
163
- })[];
164
- };
165
- } : true extends Shorthand ? {
166
- shorthandMode: true;
167
- events: ({
168
- type: "card_played";
169
- by: string;
170
- card: {
171
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
172
- color: "red" | "blue" | "green" | "yellow";
173
- } | {
174
- type: "plus-four" | "color-chooser";
175
- color?: undefined;
176
- };
177
- } | {
178
- type: "bluff_called";
179
- by: string;
180
- } | {
181
- type: "draw";
182
- by: string;
183
- } | {
184
- type: "pass";
185
- by: string;
186
- } | {
187
- type: "choose-color";
188
- color: "red" | "blue" | "green" | "yellow";
189
- by: string;
190
- })[];
191
- index: number;
192
- initialSeed: number;
193
- players: string[];
194
- stackPlusTwos: boolean;
195
- cache: {
196
- hands: Record<string, ({
197
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
198
- color: "red" | "blue" | "green" | "yellow";
199
- } | {
200
- type: "plus-four" | "color-chooser";
201
- color?: undefined;
202
- })[]>;
203
- deck: ({
204
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
205
- color: "red" | "blue" | "green" | "yellow";
206
- } | {
207
- type: "plus-four" | "color-chooser";
208
- color?: undefined;
209
- })[];
210
- seed: number;
211
- stackedPlusTwos: number;
212
- turnStep: 1 | -1;
213
- ended: boolean;
214
- pile: ({
215
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
216
- color: "red" | "blue" | "green" | "yellow";
217
- } | {
218
- type: "plus-four" | "color-chooser";
219
- color?: undefined;
220
- })[];
221
- last3CardPlayOrColorChanges: ("red" | "blue" | "green" | "yellow" | {
222
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
223
- color: "red" | "blue" | "green" | "yellow";
224
- } | {
225
- type: "plus-four" | "color-chooser";
226
- color?: undefined;
227
- })[];
228
- };
229
- } : {
230
- shorthandMode: false;
231
- events: ({
232
- type: "card_played";
233
- by: string;
234
- card: {
235
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
236
- color: "red" | "blue" | "green" | "yellow";
237
- } | {
238
- type: "plus-four" | "color-chooser";
239
- color?: undefined;
240
- };
241
- } | {
242
- type: "bluff_called";
243
- by: string;
244
- } | {
245
- type: "draw";
246
- by: string;
247
- } | {
248
- type: "pass";
249
- by: string;
250
- } | {
251
- type: "choose-color";
252
- color: "red" | "blue" | "green" | "yellow";
253
- by: string;
254
- } | {
255
- type: "game_info";
256
- info: {
257
- type: "bluff_called";
258
- by: string;
259
- } | {
260
- type: "bluff_call_succeeded";
261
- by: string;
262
- of: string;
263
- } | {
264
- type: "bluff_call_failed";
265
- by: string;
266
- of: string;
267
- } | {
268
- type: "seed_changed";
269
- newSeed: number;
270
- } | {
271
- type: "player_won";
272
- id: string;
273
- } | {
274
- type: "game_ended";
275
- loser: string;
276
- } | {
277
- type: "player_joined";
278
- id: string;
279
- } | {
280
- type: "player_left";
281
- id: string;
282
- } | {
283
- type: "pile_to_deck";
284
- };
285
- })[];
286
- index: number;
287
- initialSeed: number;
288
- players: string[];
289
- stackPlusTwos: boolean;
290
- cache: {
291
- hands: Record<string, ({
292
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
293
- color: "red" | "blue" | "green" | "yellow";
294
- } | {
295
- type: "plus-four" | "color-chooser";
296
- color?: undefined;
297
- })[]>;
298
- deck: ({
299
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
300
- color: "red" | "blue" | "green" | "yellow";
301
- } | {
302
- type: "plus-four" | "color-chooser";
303
- color?: undefined;
304
- })[];
305
- seed: number;
306
- stackedPlusTwos: number;
307
- turnStep: 1 | -1;
308
- ended: boolean;
309
- pile: ({
310
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
311
- color: "red" | "blue" | "green" | "yellow";
312
- } | {
313
- type: "plus-four" | "color-chooser";
314
- color?: undefined;
315
- })[];
316
- last3CardPlayOrColorChanges: ("red" | "blue" | "green" | "yellow" | {
317
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
318
- color: "red" | "blue" | "green" | "yellow";
319
- } | {
320
- type: "plus-four" | "color-chooser";
321
- color?: undefined;
322
- })[];
323
- };
324
- };
325
- constructor(props?: XOR<{
326
- serialisedState?: string;
327
- }, {
328
- shorthandMode?: Shorthand;
329
- stackPlusTwos?: boolean;
330
- initialSeed?: string | number;
331
- noInit?: boolean;
332
- }>);
333
- protected random(): number;
334
- protected shuffleDeck(): void;
335
- protected nonInfoEvents(): ({
336
- type: "card_played";
337
- by: string;
338
- card: {
339
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
340
- color: "red" | "blue" | "green" | "yellow";
341
- } | {
342
- type: "plus-four" | "color-chooser";
343
- color?: undefined;
344
- };
345
- } | {
346
- type: "bluff_called";
347
- by: string;
348
- } | {
349
- type: "draw";
350
- by: string;
351
- } | {
352
- type: "pass";
353
- by: string;
354
- } | {
355
- type: "choose-color";
356
- color: "red" | "blue" | "green" | "yellow";
357
- by: string;
358
- } | {
359
- type: "game_info";
360
- info: {
361
- type: "bluff_called";
362
- by: string;
363
- } | {
364
- type: "bluff_call_succeeded";
365
- by: string;
366
- of: string;
367
- } | {
368
- type: "bluff_call_failed";
369
- by: string;
370
- of: string;
371
- } | {
372
- type: "seed_changed";
373
- newSeed: number;
374
- } | {
375
- type: "player_won";
376
- id: string;
377
- } | {
378
- type: "game_ended";
379
- loser: string;
380
- } | {
381
- type: "player_joined";
382
- id: string;
383
- } | {
384
- type: "player_left";
385
- id: string;
386
- } | {
387
- type: "pile_to_deck";
388
- };
389
- })[];
390
- protected init(customDeckTopCard?: Card): void;
391
- protected recordEvent(event: GameEvent | InfoEvent): void;
392
- protected deckTopCard(): {
393
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
394
- color: "red" | "blue" | "green" | "yellow";
395
- } | {
396
- type: "plus-four" | "color-chooser";
397
- color?: undefined;
398
- };
399
- /**
400
- * Returns the last two events that don't have the type "game_info".
401
- * @param ignoredEvents - the number of non-info events to ignore from
402
- * the end. This param is useful, say, when checking during a bluff call,
403
- * where you might need to ignore the last 3 events.
404
- */
405
- lastTwoNonInfoEvents(ignoredEvents?: number): [{
406
- type: "card_played";
407
- by: string;
408
- card: {
409
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
410
- color: "red" | "blue" | "green" | "yellow";
411
- } | {
412
- type: "plus-four" | "color-chooser";
413
- color?: undefined;
414
- };
415
- } | {
416
- type: "bluff_called";
417
- by: string;
418
- } | {
419
- type: "draw";
420
- by: string;
421
- } | {
422
- type: "pass";
423
- by: string;
424
- } | {
425
- type: "choose-color";
426
- color: "red" | "blue" | "green" | "yellow";
427
- by: string;
428
- }] | [{
429
- type: "card_played";
430
- by: string;
431
- card: {
432
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
433
- color: "red" | "blue" | "green" | "yellow";
434
- } | {
435
- type: "plus-four" | "color-chooser";
436
- color?: undefined;
437
- };
438
- } | {
439
- type: "bluff_called";
440
- by: string;
441
- } | {
442
- type: "draw";
443
- by: string;
444
- } | {
445
- type: "pass";
446
- by: string;
447
- } | {
448
- type: "choose-color";
449
- color: "red" | "blue" | "green" | "yellow";
450
- by: string;
451
- }, {
452
- type: "card_played";
453
- by: string;
454
- card: {
455
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
456
- color: "red" | "blue" | "green" | "yellow";
457
- } | {
458
- type: "plus-four" | "color-chooser";
459
- color?: undefined;
460
- };
461
- } | {
462
- type: "bluff_called";
463
- by: string;
464
- } | {
465
- type: "draw";
466
- by: string;
467
- } | {
468
- type: "pass";
469
- by: string;
470
- } | {
471
- type: "choose-color";
472
- color: "red" | "blue" | "green" | "yellow";
473
- by: string;
474
- }];
475
- /**
476
- * Returns the playing pile. This is where the first card is
477
- * played, and where all the subsequent cards played by players
478
- * are put. It is guaranteed to have one card at the start.
479
- *
480
- * ```typescript
481
- * const game = new Game();
482
- * game.play(p1, { type: "one", color: "red" });
483
- * game.play(p2, { type: "one", color: "green" });
484
- *
485
- * assertEquals(game.getPile(), [
486
- * { type: "six", color: "red" }, // randomly chosen by engine
487
- * { type: "one", color: "red" },
488
- * { type: "one", color: "green" },
489
- * ]);
490
- * ```
491
- */
492
- getPile(): Card[];
493
- /**
494
- * @param bluffSiteCheck - if set to true, the last 3 events will be ignored.
495
- *
496
- * Check whether the given event is valid at the current
497
- * state of the game.
498
- *
499
- * ```typescript
500
- * const game = new Game();
501
- * game.draw(p1);
502
- *
503
- * // false, since you cannot call bluff after drawing
504
- * game.checkEvent({ type: "bluff_called", by: p1 });
505
- *
506
- * // true, since you can pass after drawing
507
- * game.checkEvent({ type: "pass", by: p1 }); // true
508
- *
509
- * game.pass(p1);
510
- *
511
- * // false, since you cannot pass without drawing
512
- * game.checkEvent({ type: "draw", by: p2 }); // false
513
- * ```
514
- */
515
- checkEvent(event: GameEvent, bluffSiteCheck?: boolean): UnocabError<UECode.TooFewPlayers> | UnocabError<UECode.NotPlayersTurn> | UnocabError<UECode.GameEnded> | UnocabError<UECode.MustPickColor> | UnocabError<UECode.MustDrawOrPlusTwo> | UnocabError<UECode.MustDrawOrCallBluff> | UnocabError<UECode.MustNotPlayLastCardColorChanging> | UnocabError<UECode.MustPlayExpectedCard> | UnocabError<UECode.MustNotDrawTwice> | UnocabError<UECode.MustNotPassWithoutDraw> | UnocabError<UECode.CannotCallBluff> | UnocabError<UECode.CannotSwitchColors> | undefined;
516
- /**
517
- * This function can be used as an alternative to the user-friendly
518
- * methods like {@link Game.draw} or {@link Game.pass}, where you are
519
- * allowed to directly pass in a {@link GameEvent}.
520
- *
521
- * ```typescript
522
- * const game = new Game();
523
- *
524
- * // regular way
525
- * game.draw(p1);
526
- *
527
- * // processNewEvent way
528
- * game.processNewEvent({ type: "draw", by: p1 });
529
- * ```
530
- */
531
- processNewEvent(event: GameEvent): ProcessEventResult;
532
- /**
533
- * Have player(s) denoted by an ID join the game.
534
- *
535
- * ```typescript
536
- * const game = new Game();
537
- * const p1 = uuidv4();
538
- * const p2 = uuidv4();
539
- * game.join(p1, p2);
540
- * ```
541
- */
542
- join(...playerIds: PlayerId[]): void;
543
- /**
544
- * Have player(s) denoted by an ID join the game.
545
- *
546
- * ```typescript
547
- * const game = new Game();
548
- * const p1 = uuidv4();
549
- * const p2 = uuidv4();
550
- * game.join(p1, p2);
551
- *
552
- * game.leave(p1, p2);
553
- * ```
554
- */
555
- leave(...playerIds: PlayerId[]): void;
556
- /**
557
- * Have a player denoted by an ID play a card. Throws
558
- * an {@link UnocabError} in case the player does not
559
- * have the given card, or if playing it is an invalid move.
560
- *
561
- * ```typescript
562
- * const game = new Game();
563
- * game.play(p1, { type: "one", color: "red" });
564
- * ```
565
- */
566
- play(by: PlayerId, card: Card): ProcessEventResult;
567
- /**
568
- * Have a player denoted by an ID draw a card. Throws
569
- * an {@link UnocabError} in case it's invalid to draw.
570
- *
571
- * ```typescript
572
- * const game = new Game();
573
- * game.draw(p1);
574
- * ```
575
- */
576
- draw(by: PlayerId): ProcessEventResult;
577
- /**
578
- * Have a player denoted by an ID draw a card. Throws
579
- * an {@link UnocabError} in case it's invalid to pass.
580
- *
581
- * ```typescript
582
- * const game = new Game();
583
- * game.draw(p1);
584
- * game.pass(p1);
585
- * ```
586
- */
587
- pass(by: PlayerId): ProcessEventResult;
588
- /**
589
- * Have a player denoted by an ID call bluff. Throws
590
- * an {@link UnocabError} in case a +4 was not played
591
- * as the previous event, or if it is an invalid move.
592
- *
593
- * ```typescript
594
- * const game = new Game();
595
- * game.play(p1, { type: "plus-four" });
596
- * game.switchColor(p1, "red");
597
- * game.callBluff(p2);
598
- * ```
599
- */
600
- callBluff(by: PlayerId): ProcessEventResult;
601
- /**
602
- * Have a player denoted by an ID switch color. Throws
603
- * an {@link UnocabError} in case a color switching card
604
- * was not played as the previous event, or if it is an invalid move.
605
- *
606
- * ```typescript
607
- * const game = new Game();
608
- * game.play(p1, { type: "plus-four" });
609
- * game.switchColor(p1, "red");
610
- * ```
611
- */
612
- chooseColor(by: PlayerId, color: CardColor): ProcessEventResult;
613
- /**
614
- * Fetches the hand of a player denoted by an ID.
615
- * Throws an {@link UnocabError} if the player is
616
- * not present in the game.
617
- */
618
- handOf(playerId: PlayerId): Card[];
619
- /**
620
- * Serialises the game state into a JSON. This can then
621
- * be passed to the constructor when creating a new game
622
- * in order to recreate the game.
623
- *
624
- * ```typescript
625
- * const game = new Game({ shorthandMode: true });
626
- *
627
- * const json = game.serialise();
628
- *
629
- * const recreatedGame = new Game<true>({ serialisedState: json });
630
- * ```
631
- */
632
- serialise(): string;
633
- /**
634
- * Clones this game to create another game with the exact
635
- * same state and set of players.
636
- */
637
- clone(): Game<Shorthand>;
638
- /**
639
- * Fetches events of the given type from the game.
640
- *
641
- * ```typescript
642
- * const game = new Game();
643
- * game.draw(p1);
644
- * game.pass(p1);
645
- * game.draw(p2);
646
- *
647
- * assertEquals(game.eventsOfType("draw"), [
648
- * { type: "draw", by: p1 },
649
- * { type: "draw", by: p2 }
650
- * ]);
651
- * ```
652
- */
653
- eventsOfType<T extends GameState["events"][number]["type"]>(type: T): (Extract<{
654
- type: "card_played";
655
- by: string;
656
- card: {
657
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
658
- color: "red" | "blue" | "green" | "yellow";
659
- } | {
660
- type: "plus-four" | "color-chooser";
661
- color?: undefined;
662
- };
663
- }, {
664
- type: T;
665
- }> | Extract<{
666
- type: "bluff_called";
667
- by: string;
668
- }, {
669
- type: T;
670
- }> | Extract<{
671
- type: "draw";
672
- by: string;
673
- }, {
674
- type: T;
675
- }> | Extract<{
676
- type: "pass";
677
- by: string;
678
- }, {
679
- type: T;
680
- }> | Extract<{
681
- type: "choose-color";
682
- color: "red" | "blue" | "green" | "yellow";
683
- by: string;
684
- }, {
685
- type: T;
686
- }> | Extract<{
687
- type: "game_info";
688
- info: {
689
- type: "bluff_called";
690
- by: string;
691
- } | {
692
- type: "bluff_call_succeeded";
693
- by: string;
694
- of: string;
695
- } | {
696
- type: "bluff_call_failed";
697
- by: string;
698
- of: string;
699
- } | {
700
- type: "seed_changed";
701
- newSeed: number;
702
- } | {
703
- type: "player_won";
704
- id: string;
705
- } | {
706
- type: "game_ended";
707
- loser: string;
708
- } | {
709
- type: "player_joined";
710
- id: string;
711
- } | {
712
- type: "player_left";
713
- id: string;
714
- } | {
715
- type: "pile_to_deck";
716
- };
717
- }, {
718
- type: T;
719
- }>)[];
720
- /**
721
- * Get the player ID of the active player who is expected to play.
722
- *
723
- * ```typescript
724
- * const game = new Game();
725
- *
726
- * assertEquals(game.activePlayer(), p1);
727
- *
728
- * game.draw(p1);
729
- * game.pass(p1);
730
- *
731
- * assertEquals(game.activePlayer(), p2);
732
- * ```
733
- */
734
- activePlayer(): PlayerId;
735
- /**
736
- * Checks whether this game has ended. If it has, returns an
737
- * object containing the player ID of the losing player.
738
- */
739
- hasEnded(): false | {
740
- loser: string;
741
- };
742
- /**
743
- * @param bluffSiteCheck - if set to true, the last 3 events will be ignored.
744
- *
745
- * Gets the expected card type and color that, if playing a card is
746
- * possible in the current state, would be valid. Please note that this
747
- * does not mean actually playing that card is okay. It just denotes the
748
- * current "pile status", so to speak. To check if playing a card is valid
749
- * in the current situation, use {@link Game.checkEvent}. Also, in case any
750
- * of `expectedType` or `expectedColor` is undefined, it becomes a non
751
- * condition. This means any type/color is allowed.
752
- */
753
- expectedCard(bluffSiteCheck?: boolean): {
754
- expectedType?: Card["type"];
755
- expectedColor: Card["color"];
756
- };
757
- /**
758
- * Resets the game to a previous index of the events array.
759
- * This can be used to replay a game from the start, or to
760
- * undo a previous move. Cannot be used in shorthand mode.
761
- * Returns the events that will be "removed".
762
- *
763
- * ```typescript
764
- * const game = new Game();
765
- *
766
- * game.play(p1, { type: "seven", color: "blue" });
767
- *
768
- * // jump to the second last index, where the above
769
- * // move does not exist, effectively undo-ing it.
770
- * game.jumpToEventIndex(-2);
771
- *
772
- * game.play(p1, { type: "six", color: "blue" });
773
- * ```
774
- */
775
- jumpToEventIndex(index: number): ({
776
- type: "card_played";
777
- by: string;
778
- card: {
779
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
780
- color: "red" | "blue" | "green" | "yellow";
781
- } | {
782
- type: "plus-four" | "color-chooser";
783
- color?: undefined;
784
- };
785
- } | {
786
- type: "bluff_called";
787
- by: string;
788
- } | {
789
- type: "draw";
790
- by: string;
791
- } | {
792
- type: "pass";
793
- by: string;
794
- } | {
795
- type: "choose-color";
796
- color: "red" | "blue" | "green" | "yellow";
797
- by: string;
798
- } | {
799
- type: "game_info";
800
- info: {
801
- type: "bluff_called";
802
- by: string;
803
- } | {
804
- type: "bluff_call_succeeded";
805
- by: string;
806
- of: string;
807
- } | {
808
- type: "bluff_call_failed";
809
- by: string;
810
- of: string;
811
- } | {
812
- type: "seed_changed";
813
- newSeed: number;
814
- } | {
815
- type: "player_won";
816
- id: string;
817
- } | {
818
- type: "game_ended";
819
- loser: string;
820
- } | {
821
- type: "player_joined";
822
- id: string;
823
- } | {
824
- type: "player_left";
825
- id: string;
826
- } | {
827
- type: "pile_to_deck";
828
- };
829
- })[];
830
- /**
831
- * Get a set of {@link GameEvent} that are valid in the current state of
832
- * the game. For example, after a draw, only a pass is a valid move, so
833
- * this function will return that. The returned events can also be directly
834
- * passed to {@link Game.processNewEvent}.
835
- *
836
- * ```typescript
837
- * const game = new Game();
838
- * game.draw(p1);
839
- * assertEquals(game.validEvents(), [
840
- * { type: "pass", by: p1 }
841
- * ]);
842
- * ```
843
- */
844
- validEvents(playerId: PlayerId): ({
845
- type: "card_played";
846
- by: string;
847
- card: {
848
- type: "reverse" | "zero" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "plus-two" | "skip";
849
- color: "red" | "blue" | "green" | "yellow";
850
- } | {
851
- type: "plus-four" | "color-chooser";
852
- color?: undefined;
853
- };
854
- } | {
855
- type: "bluff_called";
856
- by: string;
857
- } | {
858
- type: "draw";
859
- by: string;
860
- } | {
861
- type: "pass";
862
- by: string;
863
- } | {
864
- type: "choose-color";
865
- color: "red" | "blue" | "green" | "yellow";
866
- by: string;
867
- })[];
868
- }