@pai-forge/riichi-mahjong 0.3.3 → 0.3.5

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/dist/index.d.ts CHANGED
@@ -1,3 +1,25 @@
1
+ declare const __tehai13Brand: unique symbol;
2
+
3
+ declare const __tehai14Brand: unique symbol;
4
+
5
+ /**
6
+ * 手牌がTehai13(有効枚数13枚)であることを表明します。
7
+ * バリデーション成功後、引数を Tehai13 型にナローイングします。
8
+ * @throws {ShoushaiError} 枚数が不足している場合
9
+ * @throws {TahaiError} 枚数が超過している場合
10
+ */
11
+ export declare function assertTehai13<T extends HaiKindId | HaiId>(tehai: Tehai<T>): asserts tehai is Tehai13<T>;
12
+
13
+ /**
14
+ * 手牌がTehai14(有効枚数14枚)であることを表明します。
15
+ * バリデーション成功後、引数を Tehai14 型にナローイングします。
16
+ * @throws {ShoushaiError} 枚数が不足している場合
17
+ * @throws {TahaiError} 枚数が超過している場合
18
+ * @throws {InvalidHaiQuantityError} 同一種の牌が5枚以上ある場合
19
+ * @throws {DuplicatedHaiIdError} 物理牌モードでIDが重複している場合
20
+ */
21
+ export declare function assertTehai14<T extends HaiKindId | HaiId>(tehai: Tehai<T>): asserts tehai is Tehai14<T>;
22
+
1
23
  /**
2
24
  * 基本的な面子構造 (ジェネリック)
3
25
  *
@@ -42,7 +64,12 @@ export declare function calculateScoreForTehai(tehai: Tehai14, config: Readonly<
42
64
  */
43
65
  export declare function calculateShanten(tehai: Tehai13, useChiitoitsu?: boolean, useKokushi?: boolean): number;
44
66
 
45
- declare interface ChiitoitsuHouraStructure {
67
+ /**
68
+ * 七対子の和了構造 (ChiitoitsuHouraStructure)
69
+ *
70
+ * 7つの対子で和了した場合の構造。
71
+ */
72
+ export declare interface ChiitoitsuHouraStructure {
46
73
  readonly type: "Chiitoitsu";
47
74
  readonly pairs: readonly [
48
75
  Toitsu,
@@ -96,10 +123,31 @@ export declare function countDora(tehai: Tehai, indicators: readonly HaiKindId[]
96
123
  * 手牌の構造役を検出する
97
124
  *
98
125
  * @param tehai 判定対象の手牌
99
- * @param agariHai 和了牌
126
+ * @param config 役判定コンフィグ(和了牌、場風、自風、ドラ表示牌など)
100
127
  * @returns 成立した役と翻数のリスト(最も高得点となる解釈の結果)
101
128
  */
102
- export declare function detectYaku(tehai: Tehai14, agariHai: HaiKindId, bakaze?: HaiKindId, jikaze?: HaiKindId, doraMarkers?: readonly HaiKindId[], uraDoraMarkers?: readonly HaiKindId[], isTsumo?: boolean): YakuResult;
129
+ export declare function detectYaku(tehai: Tehai14, config: DetectYakuConfig): YakuResult;
130
+
131
+ /**
132
+ * 役判定コンフィグ (DetectYakuConfig)
133
+ *
134
+ * detectYaku に渡す設定オブジェクト。
135
+ * 和了牌、場風、自風、ドラ表示牌などをまとめて指定する。
136
+ */
137
+ export declare interface DetectYakuConfig {
138
+ /** 和了牌 */
139
+ readonly agariHai: HaiKindId;
140
+ /** 場風牌 */
141
+ readonly bakaze?: Kazehai;
142
+ /** 自風牌 */
143
+ readonly jikaze?: Kazehai;
144
+ /** ドラ表示牌のリスト */
145
+ readonly doraMarkers?: readonly HaiKindId[];
146
+ /** 裏ドラ表示牌のリスト */
147
+ readonly uraDoraMarkers?: readonly HaiKindId[];
148
+ /** ツモ和了かどうか */
149
+ readonly isTsumo?: boolean;
150
+ }
103
151
 
104
152
  /**
105
153
  * 牌IDが重複している場合のエラー
@@ -131,6 +179,63 @@ declare type ExtendedMspzString = string & {
131
179
  */
132
180
  export declare type Fu = 20 | 25 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 100 | 110;
133
181
 
182
+ /**
183
+ * 符の構成要素 (FuDetails)
184
+ *
185
+ * 符計算の内訳を保持するインターフェース。
186
+ */
187
+ export declare interface FuDetails {
188
+ /**
189
+ * 符底 (FuTei)
190
+ *
191
+ * 一般的な和了形: 20符
192
+ * 七対子: 25符
193
+ */
194
+ readonly base: 20 | 25;
195
+ /**
196
+ * 面子符の合計 (MentsuFu)
197
+ *
198
+ * 刻子・槓子による加算符。順子は0符。
199
+ */
200
+ readonly mentsu: number;
201
+ /**
202
+ * 雀頭符 (JantouFu)
203
+ *
204
+ * 役牌の対子による加算符。
205
+ */
206
+ readonly jantou: number;
207
+ /**
208
+ * 待ち符 (MachiFu)
209
+ *
210
+ * 単騎・嵌張・辺張待ちによる加算符(2符)。
211
+ */
212
+ readonly machi: number;
213
+ /**
214
+ * 和了符 (AgariFu)
215
+ *
216
+ * ツモ和了: 2符
217
+ * 門前ロン: 10符
218
+ */
219
+ readonly agari: number;
220
+ }
221
+
222
+ /**
223
+ * 符計算結果 (FuResult)
224
+ */
225
+ export declare interface FuResult {
226
+ /**
227
+ * 最終的な符数 (Total)
228
+ *
229
+ * 内訳の合計を10符単位で切り上げたもの。
230
+ * (例: 22符 -> 30符)
231
+ */
232
+ readonly total: Fu;
233
+ /**
234
+ * 計算の内訳
235
+ */
236
+ readonly details: FuDetails;
237
+ }
238
+
134
239
  /**
135
240
  * 副露 (Furo)
136
241
  *
@@ -298,7 +403,12 @@ export declare type HaiType = (typeof HaiType)[keyof typeof HaiType];
298
403
  */
299
404
  export declare type Hansu = 1 | 2 | 3 | 5 | 6 | 13 | 26;
300
405
 
301
- declare type HouraStructure = MentsuHouraStructure | ChiitoitsuHouraStructure | KokushiHouraStructure;
406
+ /**
407
+ * 和了構造 (HouraStructure)
408
+ *
409
+ * 面子手、七対子、国士無双のいずれかの和了構造。
410
+ */
411
+ export declare type HouraStructure = MentsuHouraStructure | ChiitoitsuHouraStructure | KokushiHouraStructure;
302
412
 
303
413
  /**
304
414
  * 未完成面子 (IncompletedMentsu)
@@ -419,7 +529,12 @@ export declare type Kazehai = typeof HaiKind.Ton | typeof HaiKind.Nan | typeof H
419
529
  */
420
530
  export declare function kindIdToHaiType(kind: HaiKindId): HaiType;
421
531
 
422
- declare interface KokushiHouraStructure {
532
+ /**
533
+ * 国士無双の和了構造 (KokushiHouraStructure)
534
+ *
535
+ * 13種の么九牌で和了した場合の構造。
536
+ */
537
+ export declare interface KokushiHouraStructure {
423
538
  readonly type: "Kokushi";
424
539
  /** 13種類の么九牌(重複なし) */
425
540
  readonly yaochu: readonly HaiKindId[];
@@ -429,7 +544,7 @@ declare interface KokushiHouraStructure {
429
544
 
430
545
  /** 子のツモ和了時の支払い */
431
546
  export declare interface KoTsumo {
432
- type: "koTsumo";
547
+ readonly type: "koTsumo";
433
548
  /** [子の支払い, 親の支払い] */
434
549
  readonly amount: readonly [number, number];
435
550
  }
@@ -475,7 +590,12 @@ export declare class MahjongError extends Error {
475
590
  */
476
591
  export declare type Mentsu<T extends HaiKindId | HaiId = HaiKindId> = CompletedMentsu<T> | IncompletedMentsu<T>;
477
592
 
478
- declare interface MentsuHouraStructure {
593
+ /**
594
+ * 面子手の和了構造 (MentsuHouraStructure)
595
+ *
596
+ * 4面子1雀頭の形で和了した場合の構造。
597
+ */
598
+ export declare interface MentsuHouraStructure {
479
599
  readonly type: "Mentsu";
480
600
  readonly fourMentsu: readonly [
481
601
  CompletedMentsu,
@@ -499,6 +619,18 @@ export declare const MentsuType: {
499
619
 
500
620
  export declare type MentsuType = (typeof MentsuType)[keyof typeof MentsuType];
501
621
 
622
+ /**
623
+ * MSPZ文字列の解析エラー
624
+ *
625
+ * MSPZ形式の文字列が不正な場合にスローされます。
626
+ */
627
+ export declare class MspzParseError extends MahjongError {
628
+ /**
629
+ *
630
+ */
631
+ constructor(message?: string);
632
+ }
633
+
502
634
  /**
503
635
  * 標準的なMSPZ形式の文字列(拡張記法を含まない)
504
636
  */
@@ -520,9 +652,9 @@ export declare class NoYakuError extends ChomboError {
520
652
 
521
653
  /** 親のツモ和了時の支払い */
522
654
  export declare interface OyaTsumo {
523
- type: "oyaTsumo";
655
+ readonly type: "oyaTsumo";
524
656
  /** 子全員が支払う点数(オール) */
525
- amount: number;
657
+ readonly amount: number;
526
658
  }
527
659
 
528
660
  /**
@@ -548,24 +680,60 @@ export declare type Payment = Ron | KoTsumo | OyaTsumo;
548
680
 
549
681
  /** ロン和了時の支払い */
550
682
  export declare interface Ron {
551
- type: "ron";
683
+ readonly type: "ron";
552
684
  /** 振り込んだプレイヤーが支払う点数 */
553
- amount: number;
685
+ readonly amount: number;
554
686
  }
555
687
 
556
688
  export declare interface ScoreCalculationConfig {
557
689
  /** 和了牌 */
558
- agariHai: HaiKindId;
690
+ readonly agariHai: HaiKindId;
559
691
  /** ツモ和了かどうか (必須) */
560
- isTsumo: boolean;
692
+ readonly isTsumo: boolean;
561
693
  /** 自風 (必須) */
562
- jikaze: Kazehai;
694
+ readonly jikaze: Kazehai;
563
695
  /** 場風 (必須) */
564
- bakaze: Kazehai;
696
+ readonly bakaze: Kazehai;
565
697
  /** ドラ表示牌 (必須、なければ空配列) */
566
- doraMarkers: readonly HaiKindId[];
698
+ readonly doraMarkers: readonly HaiKindId[];
567
699
  /** 裏ドラ表示牌 (任意) */
568
- uraDoraMarkers?: readonly HaiKindId[];
700
+ readonly uraDoraMarkers?: readonly HaiKindId[];
701
+ }
702
+
703
+ /**
704
+ * 点数計算で選択された構造解釈の詳細情報 (ScoreDetail)
705
+ *
706
+ * calculateScoreForTehai が最高得点として選択した構造解釈に紐づく情報。
707
+ *
708
+ * 同一手牌でも面子分解(構造解釈)によって待ちの形が変わり、
709
+ * 結果として符・得点が異なる場合がある。
710
+ * ライブラリは内部で最高得点の構造を選択するが、その選択結果を
711
+ * 利用側に公開しないと、利用側が独自に構造を解釈した際にライブラリと
712
+ * 異なる符の内訳を表示してしまうバグが発生する。
713
+ *
714
+ * このインターフェースにより、利用側はライブラリが採用した構造解釈と
715
+ * 完全に一致する符の内訳を表示できる。
716
+ */
717
+ export declare interface ScoreDetail {
718
+ /** ライブラリが最高得点として選択した和了構造(面子分解) */
719
+ readonly structure: HouraStructure;
720
+ /**
721
+ * 選択された構造における待ちの形
722
+ *
723
+ * 面子手の場合のみ判定される。七対子・国士無双の場合は undefined。
724
+ * 同じアガリ牌が順子と雀頭の両方に含まれる場合、符が高くなる
725
+ * 待ち形(例: 両面より単騎)が採用される。
726
+ */
727
+ readonly machiType: MachiType | undefined;
728
+ /**
729
+ * 選択された構造に基づく符計算の内訳
730
+ *
731
+ * total は最終的な符数(10符単位切り上げ)、details は各構成要素の符。
732
+ * 利用側で符の内訳を表示する際は、この値をそのまま使用すること。
733
+ */
734
+ readonly fuResult: FuResult;
735
+ /** 成立した役と翻数のリスト(ドラを含まない) */
736
+ readonly yakuResult: YakuResult;
569
737
  }
570
738
 
571
739
  /**
@@ -594,10 +762,21 @@ declare const ScoreLevel: {
594
762
  declare type ScoreLevel = (typeof ScoreLevel)[keyof typeof ScoreLevel];
595
763
 
596
764
  export declare interface ScoreResult {
597
- han: number;
598
- fu: Fu;
599
- scoreLevel: ScoreLevel;
600
- payment: Payment;
765
+ readonly han: number;
766
+ readonly fu: Fu;
767
+ readonly scoreLevel: ScoreLevel;
768
+ readonly payment: Payment;
769
+ /**
770
+ * ライブラリが最高得点として選択した構造解釈の詳細情報
771
+ *
772
+ * 手牌には複数の面子分解が存在しうるが、ライブラリ内部で最高得点の
773
+ * 構造が選択される。この選択結果を外部に公開しないと、利用側で
774
+ * 符の内訳を正確に表示できないため追加された。
775
+ *
776
+ * 利用側で符の内訳や待ちの形を表示する際は、独自に構造解釈を行わず、
777
+ * このフィールドの値をそのまま使用すること。
778
+ */
779
+ readonly detail?: ScoreDetail;
601
780
  }
602
781
 
603
782
  /**
@@ -671,13 +850,23 @@ export declare interface Tehai<T extends HaiKindId | HaiId = HaiKindId> {
671
850
 
672
851
  /**
673
852
  * ツモる前の手牌 (13枚)
853
+ *
854
+ * Branded Type により Tehai14 と型レベルで区別される。
855
+ * 生成には createTehai13(テスト用)や assertTehai13 を使用する。
674
856
  */
675
- export declare type Tehai13<T extends HaiKindId | HaiId = HaiKindId> = Tehai<T>;
857
+ export declare interface Tehai13<T extends HaiKindId | HaiId = HaiKindId> extends Tehai<T> {
858
+ readonly [__tehai13Brand]: never;
859
+ }
676
860
 
677
861
  /**
678
862
  * ツモった後の手牌 (14枚)
863
+ *
864
+ * Branded Type により Tehai13 と型レベルで区別される。
865
+ * 生成には createTehai(テスト用)や assertTehai14 を使用する。
679
866
  */
680
- export declare type Tehai14<T extends HaiKindId | HaiId = HaiKindId> = Tehai<T>;
867
+ export declare interface Tehai14<T extends HaiKindId | HaiId = HaiKindId> extends Tehai<T> {
868
+ readonly [__tehai14Brand]: never;
869
+ }
681
870
 
682
871
  /**
683
872
  * 手牌役 (TehaiYaku)