@pai-forge/riichi-mahjong 0.3.4 → 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,6 +64,11 @@ 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
 
67
+ /**
68
+ * 七対子の和了構造 (ChiitoitsuHouraStructure)
69
+ *
70
+ * 7つの対子で和了した場合の構造。
71
+ */
45
72
  export declare interface ChiitoitsuHouraStructure {
46
73
  readonly type: "Chiitoitsu";
47
74
  readonly pairs: readonly [
@@ -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が重複している場合のエラー
@@ -355,6 +403,11 @@ export declare type HaiType = (typeof HaiType)[keyof typeof HaiType];
355
403
  */
356
404
  export declare type Hansu = 1 | 2 | 3 | 5 | 6 | 13 | 26;
357
405
 
406
+ /**
407
+ * 和了構造 (HouraStructure)
408
+ *
409
+ * 面子手、七対子、国士無双のいずれかの和了構造。
410
+ */
358
411
  export declare type HouraStructure = MentsuHouraStructure | ChiitoitsuHouraStructure | KokushiHouraStructure;
359
412
 
360
413
  /**
@@ -476,6 +529,11 @@ export declare type Kazehai = typeof HaiKind.Ton | typeof HaiKind.Nan | typeof H
476
529
  */
477
530
  export declare function kindIdToHaiType(kind: HaiKindId): HaiType;
478
531
 
532
+ /**
533
+ * 国士無双の和了構造 (KokushiHouraStructure)
534
+ *
535
+ * 13種の么九牌で和了した場合の構造。
536
+ */
479
537
  export declare interface KokushiHouraStructure {
480
538
  readonly type: "Kokushi";
481
539
  /** 13種類の么九牌(重複なし) */
@@ -486,7 +544,7 @@ export declare interface KokushiHouraStructure {
486
544
 
487
545
  /** 子のツモ和了時の支払い */
488
546
  export declare interface KoTsumo {
489
- type: "koTsumo";
547
+ readonly type: "koTsumo";
490
548
  /** [子の支払い, 親の支払い] */
491
549
  readonly amount: readonly [number, number];
492
550
  }
@@ -532,6 +590,11 @@ export declare class MahjongError extends Error {
532
590
  */
533
591
  export declare type Mentsu<T extends HaiKindId | HaiId = HaiKindId> = CompletedMentsu<T> | IncompletedMentsu<T>;
534
592
 
593
+ /**
594
+ * 面子手の和了構造 (MentsuHouraStructure)
595
+ *
596
+ * 4面子1雀頭の形で和了した場合の構造。
597
+ */
535
598
  export declare interface MentsuHouraStructure {
536
599
  readonly type: "Mentsu";
537
600
  readonly fourMentsu: readonly [
@@ -556,6 +619,18 @@ export declare const MentsuType: {
556
619
 
557
620
  export declare type MentsuType = (typeof MentsuType)[keyof typeof MentsuType];
558
621
 
622
+ /**
623
+ * MSPZ文字列の解析エラー
624
+ *
625
+ * MSPZ形式の文字列が不正な場合にスローされます。
626
+ */
627
+ export declare class MspzParseError extends MahjongError {
628
+ /**
629
+ *
630
+ */
631
+ constructor(message?: string);
632
+ }
633
+
559
634
  /**
560
635
  * 標準的なMSPZ形式の文字列(拡張記法を含まない)
561
636
  */
@@ -577,9 +652,9 @@ export declare class NoYakuError extends ChomboError {
577
652
 
578
653
  /** 親のツモ和了時の支払い */
579
654
  export declare interface OyaTsumo {
580
- type: "oyaTsumo";
655
+ readonly type: "oyaTsumo";
581
656
  /** 子全員が支払う点数(オール) */
582
- amount: number;
657
+ readonly amount: number;
583
658
  }
584
659
 
585
660
  /**
@@ -605,24 +680,24 @@ export declare type Payment = Ron | KoTsumo | OyaTsumo;
605
680
 
606
681
  /** ロン和了時の支払い */
607
682
  export declare interface Ron {
608
- type: "ron";
683
+ readonly type: "ron";
609
684
  /** 振り込んだプレイヤーが支払う点数 */
610
- amount: number;
685
+ readonly amount: number;
611
686
  }
612
687
 
613
688
  export declare interface ScoreCalculationConfig {
614
689
  /** 和了牌 */
615
- agariHai: HaiKindId;
690
+ readonly agariHai: HaiKindId;
616
691
  /** ツモ和了かどうか (必須) */
617
- isTsumo: boolean;
692
+ readonly isTsumo: boolean;
618
693
  /** 自風 (必須) */
619
- jikaze: Kazehai;
694
+ readonly jikaze: Kazehai;
620
695
  /** 場風 (必須) */
621
- bakaze: Kazehai;
696
+ readonly bakaze: Kazehai;
622
697
  /** ドラ表示牌 (必須、なければ空配列) */
623
- doraMarkers: readonly HaiKindId[];
698
+ readonly doraMarkers: readonly HaiKindId[];
624
699
  /** 裏ドラ表示牌 (任意) */
625
- uraDoraMarkers?: readonly HaiKindId[];
700
+ readonly uraDoraMarkers?: readonly HaiKindId[];
626
701
  }
627
702
 
628
703
  /**
@@ -687,10 +762,10 @@ declare const ScoreLevel: {
687
762
  declare type ScoreLevel = (typeof ScoreLevel)[keyof typeof ScoreLevel];
688
763
 
689
764
  export declare interface ScoreResult {
690
- han: number;
691
- fu: Fu;
692
- scoreLevel: ScoreLevel;
693
- payment: Payment;
765
+ readonly han: number;
766
+ readonly fu: Fu;
767
+ readonly scoreLevel: ScoreLevel;
768
+ readonly payment: Payment;
694
769
  /**
695
770
  * ライブラリが最高得点として選択した構造解釈の詳細情報
696
771
  *
@@ -701,7 +776,7 @@ export declare interface ScoreResult {
701
776
  * 利用側で符の内訳や待ちの形を表示する際は、独自に構造解釈を行わず、
702
777
  * このフィールドの値をそのまま使用すること。
703
778
  */
704
- detail?: ScoreDetail;
779
+ readonly detail?: ScoreDetail;
705
780
  }
706
781
 
707
782
  /**
@@ -775,13 +850,23 @@ export declare interface Tehai<T extends HaiKindId | HaiId = HaiKindId> {
775
850
 
776
851
  /**
777
852
  * ツモる前の手牌 (13枚)
853
+ *
854
+ * Branded Type により Tehai14 と型レベルで区別される。
855
+ * 生成には createTehai13(テスト用)や assertTehai13 を使用する。
778
856
  */
779
- 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
+ }
780
860
 
781
861
  /**
782
862
  * ツモった後の手牌 (14枚)
863
+ *
864
+ * Branded Type により Tehai13 と型レベルで区別される。
865
+ * 生成には createTehai(テスト用)や assertTehai14 を使用する。
783
866
  */
784
- 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
+ }
785
870
 
786
871
  /**
787
872
  * 手牌役 (TehaiYaku)