@bilkobibitkov/threewinds-engine 0.0.0-stage → 0.1.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.
- package/README.md +31 -2
- package/dist/ai.d.ts +21 -0
- package/dist/ai.js +445 -0
- package/dist/game.d.ts +184 -0
- package/dist/game.js +432 -0
- package/dist/hand.d.ts +39 -0
- package/dist/hand.js +175 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/room.d.ts +106 -0
- package/dist/room.js +195 -0
- package/dist/scoring.d.ts +104 -0
- package/dist/scoring.js +239 -0
- package/dist/seed.d.ts +14 -0
- package/dist/seed.js +115 -0
- package/dist/tiles.d.ts +45 -0
- package/dist/tiles.js +70 -0
- package/dist/wall.d.ts +33 -0
- package/dist/wall.js +76 -0
- package/package.json +30 -3
package/dist/seed.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seeded randomness for staked deals. mulberry32 (wall.ts) has 32 bits of state, so anyone who sees
|
|
3
|
+
* their own tiles could brute-force every seed and rebuild the wall. Room deals instead run Fisher-Yates
|
|
4
|
+
* on a ChaCha20 keystream (RFC 8439 §2.3) keyed by the host's seed. Pure TS: no node:crypto, so the
|
|
5
|
+
* engine still runs in React Native and the browser.
|
|
6
|
+
*/
|
|
7
|
+
const SIGMA = [0x61707865, 0x3320646e, 0x79622d32, 0x6b206574];
|
|
8
|
+
const rotl = (x, n) => ((x << n) | (x >>> (32 - n))) >>> 0;
|
|
9
|
+
function quarter(s, a, b, c, d) {
|
|
10
|
+
s[a] = s[a] + s[b];
|
|
11
|
+
s[d] = rotl(s[d] ^ s[a], 16);
|
|
12
|
+
s[c] = s[c] + s[d];
|
|
13
|
+
s[b] = rotl(s[b] ^ s[c], 12);
|
|
14
|
+
s[a] = s[a] + s[b];
|
|
15
|
+
s[d] = rotl(s[d] ^ s[a], 8);
|
|
16
|
+
s[c] = s[c] + s[d];
|
|
17
|
+
s[b] = rotl(s[b] ^ s[c], 7);
|
|
18
|
+
}
|
|
19
|
+
/** One ChaCha20 block (RFC 8439 §2.3) as 16 little-endian words. `key` is 8 words, `nonce` 3. */
|
|
20
|
+
export function chacha20Block(key, counter, nonce) {
|
|
21
|
+
const init = new Uint32Array(16);
|
|
22
|
+
init.set(SIGMA, 0);
|
|
23
|
+
init.set(key, 4);
|
|
24
|
+
init[12] = counter >>> 0;
|
|
25
|
+
init.set(nonce, 13);
|
|
26
|
+
const s = init.slice();
|
|
27
|
+
for (let i = 0; i < 10; i++) {
|
|
28
|
+
quarter(s, 0, 4, 8, 12);
|
|
29
|
+
quarter(s, 1, 5, 9, 13);
|
|
30
|
+
quarter(s, 2, 6, 10, 14);
|
|
31
|
+
quarter(s, 3, 7, 11, 15);
|
|
32
|
+
quarter(s, 0, 5, 10, 15);
|
|
33
|
+
quarter(s, 1, 6, 11, 12);
|
|
34
|
+
quarter(s, 2, 7, 8, 13);
|
|
35
|
+
quarter(s, 3, 4, 9, 14);
|
|
36
|
+
}
|
|
37
|
+
for (let i = 0; i < 16; i++)
|
|
38
|
+
s[i] = s[i] + init[i];
|
|
39
|
+
return s;
|
|
40
|
+
}
|
|
41
|
+
/** UTF-8 bytes (no TextEncoder: the engine's lib is plain ES2022). */
|
|
42
|
+
function utf8(s) {
|
|
43
|
+
const out = [];
|
|
44
|
+
for (const ch of s) {
|
|
45
|
+
const c = ch.codePointAt(0);
|
|
46
|
+
if (c < 0x80)
|
|
47
|
+
out.push(c);
|
|
48
|
+
else if (c < 0x800)
|
|
49
|
+
out.push(0xc0 | (c >> 6), 0x80 | (c & 63));
|
|
50
|
+
else if (c < 0x10000)
|
|
51
|
+
out.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 63), 0x80 | (c & 63));
|
|
52
|
+
else
|
|
53
|
+
out.push(0xf0 | (c >> 18), 0x80 | ((c >> 12) & 63), 0x80 | ((c >> 6) & 63), 0x80 | (c & 63));
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
const HEX_SEED = /^(?:[0-9a-f]{32}|[0-9a-f]{64})$/i;
|
|
58
|
+
/**
|
|
59
|
+
* Key and nonce for a seed string. 16 or 32 bytes of hex (the host sends 16) are decoded; any other
|
|
60
|
+
* string is taken as its UTF-8 bytes (1-32). The nonce holds the byte count and the hex flag, so
|
|
61
|
+
* zero-padding can't make two different seeds collide.
|
|
62
|
+
*/
|
|
63
|
+
function seedMaterial(seed) {
|
|
64
|
+
const hex = HEX_SEED.test(seed);
|
|
65
|
+
const bytes = [];
|
|
66
|
+
if (!hex && seed.length > 32)
|
|
67
|
+
throw new RangeError('seed must be 16 or 32 bytes of hex, or 1-32 bytes of text');
|
|
68
|
+
if (hex)
|
|
69
|
+
for (let i = 0; i < seed.length; i += 2)
|
|
70
|
+
bytes.push(parseInt(seed.slice(i, i + 2), 16));
|
|
71
|
+
else
|
|
72
|
+
bytes.push(...utf8(seed));
|
|
73
|
+
if (bytes.length === 0 || bytes.length > 32) {
|
|
74
|
+
throw new RangeError('seed must be 16 or 32 bytes of hex, or 1-32 bytes of text');
|
|
75
|
+
}
|
|
76
|
+
const key = new Uint32Array(8);
|
|
77
|
+
for (let i = 0; i < bytes.length; i++)
|
|
78
|
+
key[i >> 2] = key[i >> 2] | (bytes[i] << (8 * (i & 3)));
|
|
79
|
+
return { key, nonce: Uint32Array.of(bytes.length, hex ? 1 : 0, 0) };
|
|
80
|
+
}
|
|
81
|
+
/** A stream of uniform 32-bit integers from the ChaCha20 keystream for `seed`. */
|
|
82
|
+
export function seedStream(seed) {
|
|
83
|
+
const { key, nonce } = seedMaterial(seed);
|
|
84
|
+
let counter = 0;
|
|
85
|
+
let block = new Uint32Array(0);
|
|
86
|
+
let i = 0;
|
|
87
|
+
return () => {
|
|
88
|
+
if (i >= block.length) {
|
|
89
|
+
block = chacha20Block(key, counter++, nonce);
|
|
90
|
+
i = 0;
|
|
91
|
+
}
|
|
92
|
+
return block[i++];
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const TWO_32 = 0x100000000;
|
|
96
|
+
/** A uniform integer in [0, n) from a 32-bit stream, with rejection sampling so there is no bias. */
|
|
97
|
+
export function randomBelow(next, n) {
|
|
98
|
+
if (!Number.isInteger(n) || n < 1 || n > TWO_32)
|
|
99
|
+
throw new RangeError(`randomBelow: bad bound ${n}`);
|
|
100
|
+
const limit = TWO_32 - (TWO_32 % n);
|
|
101
|
+
for (;;) {
|
|
102
|
+
const x = next();
|
|
103
|
+
if (x < limit)
|
|
104
|
+
return x % n;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** Unbiased Fisher-Yates over a 32-bit stream; returns a new array, the input is not mutated. */
|
|
108
|
+
export function shuffleWith(items, next) {
|
|
109
|
+
const out = [...items];
|
|
110
|
+
for (let i = out.length - 1; i > 0; i--) {
|
|
111
|
+
const j = randomBelow(next, i + 1);
|
|
112
|
+
[out[i], out[j]] = [out[j], out[i]];
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
package/dist/tiles.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tile vocabulary for Three Winds (docs/RULES.md §1). Pure data + helpers; no DOM, no deps.
|
|
3
|
+
*/
|
|
4
|
+
declare const DOT_KINDS: readonly ["d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9"];
|
|
5
|
+
declare const WIND_KINDS: readonly ["we", "ws", "ww", "wn"];
|
|
6
|
+
declare const DRAGON_KINDS: readonly ["dr", "dg", "dw"];
|
|
7
|
+
declare const FLOWER_KINDS: readonly ["f1", "f2", "f3", "f4"];
|
|
8
|
+
declare const SEASON_KINDS: readonly ["s1", "s2", "s3", "s4"];
|
|
9
|
+
declare const FACE_KINDS: readonly ["x1", "x2", "x3", "x4"];
|
|
10
|
+
declare const ANIMAL_KINDS: readonly ["acat", "arat", "arooster", "acentipede"];
|
|
11
|
+
declare const FLY_KIND: "fly";
|
|
12
|
+
export type DotKind = (typeof DOT_KINDS)[number];
|
|
13
|
+
export type WindKind = (typeof WIND_KINDS)[number];
|
|
14
|
+
export type DragonKind = (typeof DRAGON_KINDS)[number];
|
|
15
|
+
export type BonusKind = (typeof FLOWER_KINDS)[number] | (typeof SEASON_KINDS)[number] | (typeof FACE_KINDS)[number] | (typeof ANIMAL_KINDS)[number];
|
|
16
|
+
/** One of the 33 kind codes in RULES.md §1.1. */
|
|
17
|
+
export type TileKind = DotKind | WindKind | DragonKind | BonusKind | typeof FLY_KIND;
|
|
18
|
+
export interface Tile {
|
|
19
|
+
id: number;
|
|
20
|
+
kind: TileKind;
|
|
21
|
+
}
|
|
22
|
+
/** All 33 kinds, in design sort order (R1.4, then bonus tiles). */
|
|
23
|
+
export declare const ALL_KINDS: readonly TileKind[];
|
|
24
|
+
export declare const isDot: (k: TileKind) => k is DotKind;
|
|
25
|
+
export declare const isWind: (k: TileKind) => k is WindKind;
|
|
26
|
+
export declare const isDragon: (k: TileKind) => k is DragonKind;
|
|
27
|
+
/** Honours = winds + dragons (R1.3). */
|
|
28
|
+
export declare const isHonour: (k: TileKind) => k is WindKind | DragonKind;
|
|
29
|
+
/** Bonus = flowers, seasons, faces, animals. The Fly is NOT a bonus tile (R1.3). */
|
|
30
|
+
export declare const isBonus: (k: TileKind) => k is BonusKind;
|
|
31
|
+
export declare const isFly: (k: TileKind) => k is typeof FLY_KIND;
|
|
32
|
+
/** Face value 1-9 of a dot tile, or null for any other kind. */
|
|
33
|
+
export declare function dotValue(k: TileKind): number | null;
|
|
34
|
+
/** The full 84-tile set with unique ids 0-83. Returns a fresh array each call. */
|
|
35
|
+
export declare function fullSet(): Tile[];
|
|
36
|
+
/** Design order: fly, d1..d9, E S W N, Red Green White, then bonus tiles. */
|
|
37
|
+
export declare function sortKey(k: TileKind): number;
|
|
38
|
+
/** Returns a new array sorted by sortKey (ties broken by id); the input is not mutated. */
|
|
39
|
+
export declare function sortTiles(tiles: Tile[]): Tile[];
|
|
40
|
+
/**
|
|
41
|
+
* Own flower/season number for a seat wind (R2.2, F7): East 1, South 2, West 3.
|
|
42
|
+
* `seat` is the seat-wind index relative to the dealer: 0 East (dealer), 1 South, 2 West.
|
|
43
|
+
*/
|
|
44
|
+
export declare function ownBonusNumber(seat: 0 | 1 | 2): 1 | 2 | 3;
|
|
45
|
+
export {};
|
package/dist/tiles.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tile vocabulary for Three Winds (docs/RULES.md §1). Pure data + helpers; no DOM, no deps.
|
|
3
|
+
*/
|
|
4
|
+
const DOT_KINDS = ['d1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9'];
|
|
5
|
+
const WIND_KINDS = ['we', 'ws', 'ww', 'wn'];
|
|
6
|
+
const DRAGON_KINDS = ['dr', 'dg', 'dw'];
|
|
7
|
+
const FLOWER_KINDS = ['f1', 'f2', 'f3', 'f4'];
|
|
8
|
+
const SEASON_KINDS = ['s1', 's2', 's3', 's4'];
|
|
9
|
+
const FACE_KINDS = ['x1', 'x2', 'x3', 'x4'];
|
|
10
|
+
const ANIMAL_KINDS = ['acat', 'arat', 'arooster', 'acentipede'];
|
|
11
|
+
const FLY_KIND = 'fly';
|
|
12
|
+
const BONUS_KINDS = [
|
|
13
|
+
...FLOWER_KINDS,
|
|
14
|
+
...SEASON_KINDS,
|
|
15
|
+
...FACE_KINDS,
|
|
16
|
+
...ANIMAL_KINDS,
|
|
17
|
+
];
|
|
18
|
+
/** All 33 kinds, in design sort order (R1.4, then bonus tiles). */
|
|
19
|
+
export const ALL_KINDS = Object.freeze([
|
|
20
|
+
FLY_KIND,
|
|
21
|
+
...DOT_KINDS,
|
|
22
|
+
...WIND_KINDS,
|
|
23
|
+
...DRAGON_KINDS,
|
|
24
|
+
...BONUS_KINDS,
|
|
25
|
+
]);
|
|
26
|
+
const DOT_SET = new Set(DOT_KINDS);
|
|
27
|
+
const WIND_SET = new Set(WIND_KINDS);
|
|
28
|
+
const DRAGON_SET = new Set(DRAGON_KINDS);
|
|
29
|
+
const BONUS_SET = new Set(BONUS_KINDS);
|
|
30
|
+
const SORT_KEY = new Map(ALL_KINDS.map((k, i) => [k, i]));
|
|
31
|
+
export const isDot = (k) => DOT_SET.has(k);
|
|
32
|
+
export const isWind = (k) => WIND_SET.has(k);
|
|
33
|
+
export const isDragon = (k) => DRAGON_SET.has(k);
|
|
34
|
+
/** Honours = winds + dragons (R1.3). */
|
|
35
|
+
export const isHonour = (k) => isWind(k) || isDragon(k);
|
|
36
|
+
/** Bonus = flowers, seasons, faces, animals. The Fly is NOT a bonus tile (R1.3). */
|
|
37
|
+
export const isBonus = (k) => BONUS_SET.has(k);
|
|
38
|
+
export const isFly = (k) => k === FLY_KIND;
|
|
39
|
+
/** Face value 1-9 of a dot tile, or null for any other kind. */
|
|
40
|
+
export function dotValue(k) {
|
|
41
|
+
return isDot(k) ? Number(k.slice(1)) : null;
|
|
42
|
+
}
|
|
43
|
+
/** Copies per kind (R1.2): 4 for dots, honours and the Fly; 1 for bonus tiles. */
|
|
44
|
+
function copiesOf(k) {
|
|
45
|
+
return isBonus(k) ? 1 : 4;
|
|
46
|
+
}
|
|
47
|
+
/** The full 84-tile set with unique ids 0-83. Returns a fresh array each call. */
|
|
48
|
+
export function fullSet() {
|
|
49
|
+
const tiles = [];
|
|
50
|
+
for (const kind of ALL_KINDS) {
|
|
51
|
+
for (let c = 0; c < copiesOf(kind); c++)
|
|
52
|
+
tiles.push({ id: tiles.length, kind });
|
|
53
|
+
}
|
|
54
|
+
return tiles;
|
|
55
|
+
}
|
|
56
|
+
/** Design order: fly, d1..d9, E S W N, Red Green White, then bonus tiles. */
|
|
57
|
+
export function sortKey(k) {
|
|
58
|
+
return SORT_KEY.get(k);
|
|
59
|
+
}
|
|
60
|
+
/** Returns a new array sorted by sortKey (ties broken by id); the input is not mutated. */
|
|
61
|
+
export function sortTiles(tiles) {
|
|
62
|
+
return [...tiles].sort((a, b) => sortKey(a.kind) - sortKey(b.kind) || a.id - b.id);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Own flower/season number for a seat wind (R2.2, F7): East 1, South 2, West 3.
|
|
66
|
+
* `seat` is the seat-wind index relative to the dealer: 0 East (dealer), 1 South, 2 West.
|
|
67
|
+
*/
|
|
68
|
+
export function ownBonusNumber(seat) {
|
|
69
|
+
return (seat + 1);
|
|
70
|
+
}
|
package/dist/wall.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Tile } from './tiles.js';
|
|
2
|
+
export type Seat = 0 | 1 | 2;
|
|
3
|
+
export interface DealResult {
|
|
4
|
+
wall: Tile[];
|
|
5
|
+
hands: [Tile[], Tile[], Tile[]];
|
|
6
|
+
bonus: [Tile[], Tile[], Tile[]];
|
|
7
|
+
}
|
|
8
|
+
export interface DrawResult {
|
|
9
|
+
tile: Tile | undefined;
|
|
10
|
+
wall: Tile[];
|
|
11
|
+
}
|
|
12
|
+
/** Mulberry32 PRNG: returns a function yielding floats in [0, 1). */
|
|
13
|
+
export declare function mulberry32(seed: number): () => number;
|
|
14
|
+
/** Fisher-Yates shuffle; returns a new array, the input is not mutated. */
|
|
15
|
+
export declare function shuffle<T>(items: readonly T[], rng: () => number): T[];
|
|
16
|
+
/** Draw from the front of the wall (normal draw). */
|
|
17
|
+
export declare function drawFront(wall: readonly Tile[]): DrawResult;
|
|
18
|
+
/** Draw from the back of the wall (bonus / kong replacement). */
|
|
19
|
+
export declare function drawBack(wall: readonly Tile[]): DrawResult;
|
|
20
|
+
/**
|
|
21
|
+
* Deal from a given wall order (internal; exported for tests and scripted deals).
|
|
22
|
+
* Dealer takes 14 from the front, then the next two seats in turn order take 13 each (R2.5).
|
|
23
|
+
* Then, from the dealer in turn order, each bonus tile is set aside and replaced from the
|
|
24
|
+
* back, repeating while the replacement is also a bonus tile (R2.6).
|
|
25
|
+
*/
|
|
26
|
+
export declare function dealFromOrder(order: readonly Tile[], dealer: Seat): DealResult;
|
|
27
|
+
/** Shuffle the 84-tile set with mulberry32(seed) and deal it (R2.4–R2.6). */
|
|
28
|
+
export declare function deal(seed: number, dealer: Seat): DealResult;
|
|
29
|
+
/**
|
|
30
|
+
* Shuffle with the ChaCha20 stream for a string seed and deal it (R2.4–R2.6). Used for staked room
|
|
31
|
+
* hands, where the 32-bit mulberry32 seed of `deal` could be brute-forced from one seat's tiles.
|
|
32
|
+
*/
|
|
33
|
+
export declare function dealFromSeed(seed: string, dealer: Seat): DealResult;
|
package/dist/wall.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wall + opening deal (docs/RULES.md §2, R2.4–R2.6). Deterministic from a seed.
|
|
3
|
+
* One live wall: normal draws from the front, replacement draws from the back.
|
|
4
|
+
*/
|
|
5
|
+
import { seedStream, shuffleWith } from './seed.js';
|
|
6
|
+
import { fullSet, isBonus } from './tiles.js';
|
|
7
|
+
/** Mulberry32 PRNG: returns a function yielding floats in [0, 1). */
|
|
8
|
+
export function mulberry32(seed) {
|
|
9
|
+
let a = seed >>> 0;
|
|
10
|
+
return () => {
|
|
11
|
+
a = (a + 0x6d2b79f5) >>> 0;
|
|
12
|
+
let t = a;
|
|
13
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
14
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
15
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** Fisher-Yates shuffle; returns a new array, the input is not mutated. */
|
|
19
|
+
export function shuffle(items, rng) {
|
|
20
|
+
const out = [...items];
|
|
21
|
+
for (let i = out.length - 1; i > 0; i--) {
|
|
22
|
+
const j = Math.floor(rng() * (i + 1));
|
|
23
|
+
[out[i], out[j]] = [out[j], out[i]];
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
/** Draw from the front of the wall (normal draw). */
|
|
28
|
+
export function drawFront(wall) {
|
|
29
|
+
return { tile: wall[0], wall: wall.slice(1) };
|
|
30
|
+
}
|
|
31
|
+
/** Draw from the back of the wall (bonus / kong replacement). */
|
|
32
|
+
export function drawBack(wall) {
|
|
33
|
+
return { tile: wall[wall.length - 1], wall: wall.slice(0, -1) };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Deal from a given wall order (internal; exported for tests and scripted deals).
|
|
37
|
+
* Dealer takes 14 from the front, then the next two seats in turn order take 13 each (R2.5).
|
|
38
|
+
* Then, from the dealer in turn order, each bonus tile is set aside and replaced from the
|
|
39
|
+
* back, repeating while the replacement is also a bonus tile (R2.6).
|
|
40
|
+
*/
|
|
41
|
+
export function dealFromOrder(order, dealer) {
|
|
42
|
+
let wall = [...order];
|
|
43
|
+
const hands = [[], [], []];
|
|
44
|
+
const bonus = [[], [], []];
|
|
45
|
+
const turnOrder = [0, 1, 2].map((k) => ((dealer + k) % 3));
|
|
46
|
+
for (const seat of turnOrder) {
|
|
47
|
+
const n = seat === dealer ? 14 : 13;
|
|
48
|
+
hands[seat] = wall.slice(0, n);
|
|
49
|
+
wall = wall.slice(n);
|
|
50
|
+
}
|
|
51
|
+
for (const seat of turnOrder) {
|
|
52
|
+
const hand = hands[seat];
|
|
53
|
+
for (let i = 0; i < hand.length; i++) {
|
|
54
|
+
while (isBonus(hand[i].kind)) {
|
|
55
|
+
const r = drawBack(wall);
|
|
56
|
+
if (!r.tile)
|
|
57
|
+
throw new Error('wall exhausted during bonus replacement');
|
|
58
|
+
bonus[seat].push(hand[i]);
|
|
59
|
+
hand[i] = r.tile;
|
|
60
|
+
wall = r.wall;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return { wall, hands, bonus };
|
|
65
|
+
}
|
|
66
|
+
/** Shuffle the 84-tile set with mulberry32(seed) and deal it (R2.4–R2.6). */
|
|
67
|
+
export function deal(seed, dealer) {
|
|
68
|
+
return dealFromOrder(shuffle(fullSet(), mulberry32(seed)), dealer);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Shuffle with the ChaCha20 stream for a string seed and deal it (R2.4–R2.6). Used for staked room
|
|
72
|
+
* hands, where the 32-bit mulberry32 seed of `deal` could be brute-forced from one seat's tiles.
|
|
73
|
+
*/
|
|
74
|
+
export function dealFromSeed(seed, dealer) {
|
|
75
|
+
return dealFromOrder(shuffleWith(fullSet(), seedStream(seed)), dealer);
|
|
76
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bilkobibitkov/threewinds-engine",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Rules engine for Three Winds, Malaysian 3-player mahjong, plus its Bilko authoritative-room module (threeWindsRoomModule). Imported as @threewinds/engine via an alias.",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5.9.3",
|
|
19
|
+
"vitest": "^4.0.0"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "node scripts/build.mjs",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"typecheck": "tsc --noEmit"
|
|
25
|
+
},
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
}
|
|
6
33
|
}
|