@pai-forge/riichi-mahjong 0.3.4 → 0.3.6

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,9 @@
1
+ import { Result } from 'neverthrow';
2
+
3
+ declare const __tehai13Brand: unique symbol;
4
+
5
+ declare const __tehai14Brand: unique symbol;
6
+
1
7
  /**
2
8
  * 基本的な面子構造 (ジェネリック)
3
9
  *
@@ -40,8 +46,13 @@ export declare function calculateScoreForTehai(tehai: Tehai14, config: Readonly<
40
46
  * @param tehai 手牌
41
47
  * @returns シャンテン数
42
48
  */
43
- export declare function calculateShanten(tehai: Tehai13, useChiitoitsu?: boolean, useKokushi?: boolean): number;
49
+ export declare function calculateShanten(tehai: Tehai13, useChiitoitsu?: boolean, useKokushi?: boolean): Result<number, TehaiError>;
44
50
 
51
+ /**
52
+ * 七対子の和了構造 (ChiitoitsuHouraStructure)
53
+ *
54
+ * 7つの対子で和了した場合の構造。
55
+ */
45
56
  export declare interface ChiitoitsuHouraStructure {
46
57
  readonly type: "Chiitoitsu";
47
58
  readonly pairs: readonly [
@@ -96,10 +107,31 @@ export declare function countDora(tehai: Tehai, indicators: readonly HaiKindId[]
96
107
  * 手牌の構造役を検出する
97
108
  *
98
109
  * @param tehai 判定対象の手牌
99
- * @param agariHai 和了牌
110
+ * @param config 役判定コンフィグ(和了牌、場風、自風、ドラ表示牌など)
100
111
  * @returns 成立した役と翻数のリスト(最も高得点となる解釈の結果)
101
112
  */
102
- export declare function detectYaku(tehai: Tehai14, agariHai: HaiKindId, bakaze?: HaiKindId, jikaze?: HaiKindId, doraMarkers?: readonly HaiKindId[], uraDoraMarkers?: readonly HaiKindId[], isTsumo?: boolean): YakuResult;
113
+ export declare function detectYaku(tehai: Tehai14, config: DetectYakuConfig): YakuResult;
114
+
115
+ /**
116
+ * 役判定コンフィグ (DetectYakuConfig)
117
+ *
118
+ * detectYaku に渡す設定オブジェクト。
119
+ * 和了牌、場風、自風、ドラ表示牌などをまとめて指定する。
120
+ */
121
+ export declare interface DetectYakuConfig {
122
+ /** 和了牌 */
123
+ readonly agariHai: HaiKindId;
124
+ /** 場風牌 */
125
+ readonly bakaze?: Kazehai;
126
+ /** 自風牌 */
127
+ readonly jikaze?: Kazehai;
128
+ /** ドラ表示牌のリスト */
129
+ readonly doraMarkers?: readonly HaiKindId[];
130
+ /** 裏ドラ表示牌のリスト */
131
+ readonly uraDoraMarkers?: readonly HaiKindId[];
132
+ /** ツモ和了かどうか */
133
+ readonly isTsumo?: boolean;
134
+ }
103
135
 
104
136
  /**
105
137
  * 牌IDが重複している場合のエラー
@@ -355,6 +387,11 @@ export declare type HaiType = (typeof HaiType)[keyof typeof HaiType];
355
387
  */
356
388
  export declare type Hansu = 1 | 2 | 3 | 5 | 6 | 13 | 26;
357
389
 
390
+ /**
391
+ * 和了構造 (HouraStructure)
392
+ *
393
+ * 面子手、七対子、国士無双のいずれかの和了構造。
394
+ */
358
395
  export declare type HouraStructure = MentsuHouraStructure | ChiitoitsuHouraStructure | KokushiHouraStructure;
359
396
 
360
397
  /**
@@ -476,6 +513,11 @@ export declare type Kazehai = typeof HaiKind.Ton | typeof HaiKind.Nan | typeof H
476
513
  */
477
514
  export declare function kindIdToHaiType(kind: HaiKindId): HaiType;
478
515
 
516
+ /**
517
+ * 国士無双の和了構造 (KokushiHouraStructure)
518
+ *
519
+ * 13種の么九牌で和了した場合の構造。
520
+ */
479
521
  export declare interface KokushiHouraStructure {
480
522
  readonly type: "Kokushi";
481
523
  /** 13種類の么九牌(重複なし) */
@@ -486,7 +528,7 @@ export declare interface KokushiHouraStructure {
486
528
 
487
529
  /** 子のツモ和了時の支払い */
488
530
  export declare interface KoTsumo {
489
- type: "koTsumo";
531
+ readonly type: "koTsumo";
490
532
  /** [子の支払い, 親の支払い] */
491
533
  readonly amount: readonly [number, number];
492
534
  }
@@ -532,6 +574,11 @@ export declare class MahjongError extends Error {
532
574
  */
533
575
  export declare type Mentsu<T extends HaiKindId | HaiId = HaiKindId> = CompletedMentsu<T> | IncompletedMentsu<T>;
534
576
 
577
+ /**
578
+ * 面子手の和了構造 (MentsuHouraStructure)
579
+ *
580
+ * 4面子1雀頭の形で和了した場合の構造。
581
+ */
535
582
  export declare interface MentsuHouraStructure {
536
583
  readonly type: "Mentsu";
537
584
  readonly fourMentsu: readonly [
@@ -556,6 +603,18 @@ export declare const MentsuType: {
556
603
 
557
604
  export declare type MentsuType = (typeof MentsuType)[keyof typeof MentsuType];
558
605
 
606
+ /**
607
+ * MSPZ文字列の解析エラー
608
+ *
609
+ * MSPZ形式の文字列が不正な場合にスローされます。
610
+ */
611
+ export declare class MspzParseError extends MahjongError {
612
+ /**
613
+ *
614
+ */
615
+ constructor(message?: string);
616
+ }
617
+
559
618
  /**
560
619
  * 標準的なMSPZ形式の文字列(拡張記法を含まない)
561
620
  */
@@ -577,9 +636,9 @@ export declare class NoYakuError extends ChomboError {
577
636
 
578
637
  /** 親のツモ和了時の支払い */
579
638
  export declare interface OyaTsumo {
580
- type: "oyaTsumo";
639
+ readonly type: "oyaTsumo";
581
640
  /** 子全員が支払う点数(オール) */
582
- amount: number;
641
+ readonly amount: number;
583
642
  }
584
643
 
585
644
  /**
@@ -589,7 +648,7 @@ export declare interface OyaTsumo {
589
648
  * @param input 拡張MSPZ形式の文字列
590
649
  * @returns 手牌オブジェクト
591
650
  */
592
- export declare function parseExtendedMspz(input: string): Tehai;
651
+ export declare function parseExtendedMspz(input: string): Result<Tehai, MspzParseError>;
593
652
 
594
653
  /**
595
654
  * 標準的なMSPZ文字列(例: "123m456p...")を解析して手牌オブジェクトを生成します。
@@ -598,31 +657,31 @@ export declare function parseExtendedMspz(input: string): Tehai;
598
657
  * @param input MSPZ形式の文字列
599
658
  * @returns 手牌オブジェクト
600
659
  */
601
- export declare function parseMspz(input: string): Tehai;
660
+ export declare function parseMspz(input: string): Result<Tehai, MspzParseError>;
602
661
 
603
662
  /** 支払い情報 */
604
663
  export declare type Payment = Ron | KoTsumo | OyaTsumo;
605
664
 
606
665
  /** ロン和了時の支払い */
607
666
  export declare interface Ron {
608
- type: "ron";
667
+ readonly type: "ron";
609
668
  /** 振り込んだプレイヤーが支払う点数 */
610
- amount: number;
669
+ readonly amount: number;
611
670
  }
612
671
 
613
672
  export declare interface ScoreCalculationConfig {
614
673
  /** 和了牌 */
615
- agariHai: HaiKindId;
674
+ readonly agariHai: HaiKindId;
616
675
  /** ツモ和了かどうか (必須) */
617
- isTsumo: boolean;
676
+ readonly isTsumo: boolean;
618
677
  /** 自風 (必須) */
619
- jikaze: Kazehai;
678
+ readonly jikaze: Kazehai;
620
679
  /** 場風 (必須) */
621
- bakaze: Kazehai;
680
+ readonly bakaze: Kazehai;
622
681
  /** ドラ表示牌 (必須、なければ空配列) */
623
- doraMarkers: readonly HaiKindId[];
682
+ readonly doraMarkers: readonly HaiKindId[];
624
683
  /** 裏ドラ表示牌 (任意) */
625
- uraDoraMarkers?: readonly HaiKindId[];
684
+ readonly uraDoraMarkers?: readonly HaiKindId[];
626
685
  }
627
686
 
628
687
  /**
@@ -687,10 +746,10 @@ declare const ScoreLevel: {
687
746
  declare type ScoreLevel = (typeof ScoreLevel)[keyof typeof ScoreLevel];
688
747
 
689
748
  export declare interface ScoreResult {
690
- han: number;
691
- fu: Fu;
692
- scoreLevel: ScoreLevel;
693
- payment: Payment;
749
+ readonly han: number;
750
+ readonly fu: Fu;
751
+ readonly scoreLevel: ScoreLevel;
752
+ readonly payment: Payment;
694
753
  /**
695
754
  * ライブラリが最高得点として選択した構造解釈の詳細情報
696
755
  *
@@ -701,7 +760,7 @@ export declare interface ScoreResult {
701
760
  * 利用側で符の内訳や待ちの形を表示する際は、独自に構造解釈を行わず、
702
761
  * このフィールドの値をそのまま使用すること。
703
762
  */
704
- detail?: ScoreDetail;
763
+ readonly detail?: ScoreDetail;
705
764
  }
706
765
 
707
766
  /**
@@ -775,13 +834,25 @@ export declare interface Tehai<T extends HaiKindId | HaiId = HaiKindId> {
775
834
 
776
835
  /**
777
836
  * ツモる前の手牌 (13枚)
837
+ *
838
+ * Branded Type により Tehai14 と型レベルで区別される。
839
+ * 生成には createTehai13(テスト用)や assertTehai13 を使用する。
778
840
  */
779
- export declare type Tehai13<T extends HaiKindId | HaiId = HaiKindId> = Tehai<T>;
841
+ export declare interface Tehai13<T extends HaiKindId | HaiId = HaiKindId> extends Tehai<T> {
842
+ readonly [__tehai13Brand]: never;
843
+ }
780
844
 
781
845
  /**
782
846
  * ツモった後の手牌 (14枚)
847
+ *
848
+ * Branded Type により Tehai13 と型レベルで区別される。
849
+ * 生成には createTehai(テスト用)や assertTehai14 を使用する。
783
850
  */
784
- export declare type Tehai14<T extends HaiKindId | HaiId = HaiKindId> = Tehai<T>;
851
+ export declare interface Tehai14<T extends HaiKindId | HaiId = HaiKindId> extends Tehai<T> {
852
+ readonly [__tehai14Brand]: never;
853
+ }
854
+
855
+ declare type TehaiError = ShoushaiError | TahaiError | InvalidHaiQuantityError | DuplicatedHaiIdError;
785
856
 
786
857
  /**
787
858
  * 手牌役 (TehaiYaku)
@@ -801,15 +872,21 @@ declare type Toitsu<T extends HaiKindId | HaiId = HaiKindId> = BaseMentsu<T> & {
801
872
  };
802
873
 
803
874
  /**
804
- * 手牌がTehai13またはTehai14(有効枚数が13または14枚)であるか検証します。
805
- * シャンテン計算や待ち判定など、13枚/14枚の区別なく手牌として扱いたい場合に使用します。
806
875
  *
807
- * @throws {ShoushaiError} 枚数が不足している場合 (< 13)
808
- * @throws {TahaiError} 枚数が超過している場合 (> 14)
809
- * @throws {InvalidHaiQuantityError} 同一種の牌が5枚以上ある場合
810
- * @throws {DuplicatedHaiIdError} 物理牌モードでIDが重複している場合
811
876
  */
812
- export declare function validateTehai<T extends HaiKindId | HaiId>(tehai: Tehai<T>): void;
877
+ export declare function validateTehai<T extends HaiKindId | HaiId>(tehai: Tehai<T>): Result<Tehai<T>, TehaiError>;
878
+
879
+ /**
880
+ * 手牌がTehai13(有効枚数13枚)であるか検証し、スマートコンストラクタとして機能します。
881
+ * バリデーション成功後、Tehai13 型にナローイングされたオブジェクトをResultで返します。
882
+ */
883
+ export declare function validateTehai13<T extends HaiKindId | HaiId>(tehai: Tehai<T>): Result<Tehai13<T>, TehaiError>;
884
+
885
+ /**
886
+ * 手牌がTehai14(有効枚数14枚)であるか検証し、スマートコンストラクタとして機能します。
887
+ * バリデーション成功後、Tehai14 型にナローイングされたオブジェクトをResultで返します。
888
+ */
889
+ export declare function validateTehai14<T extends HaiKindId | HaiId>(tehai: Tehai<T>): Result<Tehai14<T>, TehaiError>;
813
890
 
814
891
  /**
815
892
  * 役牌 (Yakuhai)