@konoui/mjimage 0.5.1 → 0.6.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/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Actor } from 'xstate';
2
2
  import { AnyActorRef } from 'xstate';
3
3
  import { EventObject } from 'xstate';
4
- import { incrementalIDGenerator as incrementalIDGenerator_2 } from './state-machine';
5
4
  import { InferOutput } from 'valibot';
6
5
  import { MaxValueAction } from 'valibot';
7
6
  import { MetaObject } from 'xstate';
@@ -17,7 +16,6 @@ import { StateMachine } from 'xstate';
17
16
  import { StateValue } from 'xstate';
18
17
  import { StrictObjectSchema } from 'valibot';
19
18
  import { StringSchema } from 'valibot';
20
- import { Wind as Wind_2 } from '../..';
21
19
 
22
20
  export declare class ActorHand extends Hand {
23
21
  isBackHand(): boolean;
@@ -61,7 +59,7 @@ declare class BaseHelper {
61
59
  readonly scale: number;
62
60
  readonly svgSprite: boolean;
63
61
  constructor(props?: ImageHelperConfig);
64
- protected getDiffTileHeightWidth(t: Tile): number;
62
+ protected getHorizontalTileYOffset(t: Tile): number;
65
63
  private image;
66
64
  createImage(tile: Tile, x: number, y: number): Image_2 | Use;
67
65
  createTextImage(tile: Tile, x: number, y: number, t: string): G;
@@ -117,6 +115,7 @@ export declare abstract class Block {
117
115
 
118
116
  export declare class BlockAnKan extends Block {
119
117
  constructor(tiles: readonly Tile[]);
118
+ get tiles(): readonly Tile[];
120
119
  get tilesWithBack(): Tile[];
121
120
  static from(s: string): BlockAnKan;
122
121
  toString(): string;
@@ -126,15 +125,17 @@ export declare class BlockCalculator {
126
125
  hand: Hand;
127
126
  constructor(hand: Hand);
128
127
  calc(lastTile: Tile): readonly Block[][];
129
- markDrawn(hands: readonly Block[][], lastTile: Tile): readonly Block[][];
128
+ markedHands(hands: readonly Block[][], lastTile: Tile): readonly Block[][];
129
+ markedHand(hand: readonly Block[], lastTile: Tile): readonly Block[][];
130
130
  sevenPairs(): readonly Block[][];
131
131
  thirteenOrphans(): readonly Block[][];
132
132
  nineGates(): readonly Block[][];
133
- fourSetsOnePair(): readonly Block[][];
134
- private patternAll;
133
+ standardType(): readonly Block[][];
134
+ private calcAllBlockCombinations;
135
135
  private handleBack;
136
136
  private handleZ;
137
137
  private addRedPattern;
138
+ private addRedPatterns;
138
139
  private handleNumType;
139
140
  }
140
141
 
@@ -216,17 +217,15 @@ export declare interface BoardContext {
216
217
  finalWallWin?: boolean;
217
218
  finalDiscardWin?: boolean;
218
219
  oneShotWin?: boolean;
219
- enableRoundUp8000?: boolean;
220
- disableCountable32000?: boolean;
221
- disableDouble32000?: boolean;
220
+ enableRoundUpMangan?: boolean;
221
+ disableCountableYakuman?: boolean;
222
+ disableDoubleYakuman?: boolean;
222
223
  }
223
224
 
224
225
  declare type BoardRound = (typeof ROUND_MAP)[keyof typeof ROUND_MAP];
225
226
 
226
227
  declare type BoardWind = (typeof WIND_MAP)[keyof typeof WIND_MAP];
227
228
 
228
- export declare const callBlockIndex: (caller: Wind, discardedBy: Wind, type: typeof BLOCK.PON | typeof BLOCK.DAI_KAN) => 0 | 1 | 2 | 3;
229
-
230
229
  export declare interface CallEvent {
231
230
  id: string;
232
231
  type: Extract<ChoiceEvent, "PON" | "CHI" | "AN_KAN" | "SHO_KAN" | "DAI_KAN">;
@@ -235,12 +234,6 @@ export declare interface CallEvent {
235
234
  block: SerializedBlock;
236
235
  }
237
236
 
238
- export declare interface Candidate {
239
- tile: Tile;
240
- candidates: readonly Tile[];
241
- shanten: number;
242
- }
243
-
244
237
  export declare interface ChoiceAfterCalled {
245
238
  id: string;
246
239
  type: Extract<Event_2, "CHOICE_AFTER_CALLED">;
@@ -294,6 +287,8 @@ export declare interface ChoiceForReachAcceptance {
294
287
  choices: Pick<DiscardedChoice, "RON">;
295
288
  }
296
289
 
290
+ export declare const compareTiles: (i: Tile, j: Tile) => number;
291
+
297
292
  export declare class Controller {
298
293
  wall: IWall;
299
294
  playerIDs: string[];
@@ -302,7 +297,7 @@ export declare class Controller {
302
297
  oneShotMap: { [key in Wind]: boolean; };
303
298
  missingMap: { [key in Wind]: boolean; };
304
299
  controller: Controller;
305
- genEventID: ReturnType<incrementalIDGenerator_2>;
300
+ genEventID: ReturnType<incrementalIDGenerator>;
306
301
  }, {
307
302
  type: "";
308
303
  } | {
@@ -366,9 +361,9 @@ export declare class Controller {
366
361
  mailBox: {
367
362
  [id: string]: PlayerEvent[];
368
363
  };
369
- histories: History_2[];
364
+ histories: GameHistory[];
370
365
  debugMode: boolean;
371
- constructor(players: PlayerConnection[], params?: {
366
+ constructor(players: PlayerSession[], params?: {
372
367
  debug?: boolean;
373
368
  shuffle?: boolean;
374
369
  });
@@ -381,8 +376,8 @@ export declare class Controller {
381
376
  emit(e: PlayerEvent): void;
382
377
  enqueue(event: PlayerEvent): void;
383
378
  pollReplies(eventID: string, wind: Wind[]): void;
384
- export(): History_2[];
385
- static load(h: History_2): Controller;
379
+ export(): GameHistory[];
380
+ static load(h: GameHistory): Controller;
386
381
  start(): void;
387
382
  startGame(): void;
388
383
  finalResult(ret: WinResult, iam: Wind): WinResult;
@@ -396,7 +391,7 @@ export declare class Controller {
396
391
  doPon(w: Wind, discardedBy: Wind, t?: Tile): BlockPon[] | false;
397
392
  doChi(w: Wind, discardedBy: Wind, t?: Tile): BlockChi[] | false;
398
393
  redPattern(blocks: BlockChi[]): BlockChi[];
399
- doReach(w: Wind): Candidate[] | false;
394
+ doReach(w: Wind): TileAnalysis[] | false;
400
395
  doDiscard(w: Wind, called?: BlockChi | BlockPon): Tile[];
401
396
  cannotDiscardTile(b: BlockChi): Tile[];
402
397
  doAnKan(w: Wind): BlockAnKan[] | false;
@@ -432,7 +427,7 @@ export declare const convertInput: (i: TableInput) => {
432
427
  export declare class Counter {
433
428
  disable: boolean;
434
429
  private c;
435
- safeMap: {
430
+ safeTileMap: {
436
431
  "1z": {
437
432
  [name: string]: boolean;
438
433
  };
@@ -617,7 +612,7 @@ export declare interface DrawEvent {
617
612
 
618
613
  declare interface DrawnChoice {
619
614
  TSUMO: false | SerializedWinResult;
620
- REACH: false | SerializedCandidate[];
615
+ REACH: false | SerializedTileAnalysis[];
621
616
  AN_KAN: false | SerializedBlock[];
622
617
  SHO_KAN: false | SerializedBlock[];
623
618
  DISCARD: false | string[];
@@ -634,16 +629,16 @@ export declare const drawTable: (svg: Svg, tableInput: string, config: ImageHelp
634
629
  }) => void;
635
630
 
636
631
  export declare class Efficiency {
637
- static calcCandidates(hand: Hand, choices: Tile[], options?: {
632
+ static calcEffectiveTiles(hand: Hand, choices: Tile[], options?: {
638
633
  arrangeRed?: boolean;
639
- fourSetsOnePair?: boolean;
640
- }): Candidate[];
641
- static candidateTiles(hand: Hand, options?: {
642
- fourSetsOnePair?: boolean;
634
+ standardTypeOnly?: boolean;
635
+ }): TileAnalysis[];
636
+ static getEffectiveTiles(hand: Hand, options?: {
637
+ standardTypeOnly?: boolean;
643
638
  typeFilter?: Type[];
644
639
  }): {
645
640
  shanten: number;
646
- candidates: Tile[];
641
+ effectiveTiles: Tile[];
647
642
  };
648
643
  }
649
644
 
@@ -708,6 +703,36 @@ export declare class G extends Mark {
708
703
  each(block: (idx: number, children: Mark[]) => void, deep: boolean): void;
709
704
  }
710
705
 
706
+ export declare interface GameHistory {
707
+ round: Round;
708
+ scores: {
709
+ [wind in string]: number;
710
+ };
711
+ players: {
712
+ [id in string]: Wind;
713
+ };
714
+ sticks: {
715
+ reach: number;
716
+ dead: number;
717
+ };
718
+ wall: WallProps;
719
+ choiceEvents: {
720
+ [id: string]: PlayerEvent[];
721
+ };
722
+ }
723
+
724
+ export declare const getCallBlockIndex: (caller: Wind, discardedBy: Wind, type: typeof BLOCK.PON | typeof BLOCK.DAI_KAN) => 0 | 1 | 3 | 2;
725
+
726
+ export declare function getPointDescription(params: {
727
+ base: number;
728
+ fu: number;
729
+ han: number;
730
+ isTsumo: boolean;
731
+ isParent: boolean;
732
+ isYakuman?: boolean;
733
+ isCountableYakuman?: boolean;
734
+ }): string;
735
+
711
736
  export declare class Hand {
712
737
  protected data: HandData;
713
738
  constructor(input: string | Block[], allowBackBlock?: boolean);
@@ -748,25 +773,6 @@ export declare interface HandsInput {
748
773
  left: Block[];
749
774
  }
750
775
 
751
- declare interface History_2 {
752
- round: Round;
753
- scores: {
754
- [key in string]: number;
755
- };
756
- players: {
757
- [key in string]: Wind;
758
- };
759
- sticks: {
760
- reach: number;
761
- dead: number;
762
- };
763
- wall: WallProps;
764
- choiceEvents: {
765
- [id: string]: PlayerEvent[];
766
- };
767
- }
768
- export { History_2 as History }
769
-
770
776
  declare class Image_2 extends Mark {
771
777
  attrs: Attrs & {
772
778
  href?: string;
@@ -809,7 +815,7 @@ export declare interface IRiver {
809
815
  cannotContinue(): boolean;
810
816
  }
811
817
 
812
- export declare function isNum5(t: Tile): boolean;
818
+ export declare function is5Tile(t: Tile): boolean;
813
819
 
814
820
  export declare interface IWall {
815
821
  kan(): Tile;
@@ -905,7 +911,7 @@ export declare const OP: {
905
911
  readonly COLOR_GRAYSCALE: "^";
906
912
  };
907
913
 
908
- declare type Operator = (typeof OP)[keyof typeof OP];
914
+ export declare type Operator = (typeof OP)[keyof typeof OP];
909
915
 
910
916
  export declare const optimizeSVG: (draw: Svg) => void;
911
917
 
@@ -923,7 +929,7 @@ export declare class Parser {
923
929
  tiles(): readonly Tile[];
924
930
  tileSeparators(): readonly (Tile | Separator)[];
925
931
  private makeBlocks;
926
- validate(input: string): void;
932
+ private validate;
927
933
  }
928
934
 
929
935
  export declare const parseTableInput: (s: string) => {
@@ -959,8 +965,8 @@ export declare const parseTableInput: (s: string) => {
959
965
  };
960
966
 
961
967
  export declare class PlaceManager {
962
- private pToW;
963
- private wToP;
968
+ private playerToWind;
969
+ private windToPlayer;
964
970
  round: Round;
965
971
  sticks: {
966
972
  reach: number;
@@ -985,7 +991,7 @@ export declare class PlaceManager {
985
991
  wind(id: string): Wind;
986
992
  playerID(w: Wind): string;
987
993
  get playerMap(): {
988
- [key: string]: Wind;
994
+ [id: string]: Wind;
989
995
  };
990
996
  }
991
997
 
@@ -993,40 +999,40 @@ export declare class Player extends BaseActor {
993
999
  river: River;
994
1000
  doras: Tile[];
995
1001
  constructor(playerID: string, eventHandler: EventHandler);
996
- get myWind(): Wind_2;
1002
+ get myWind(): Wind;
997
1003
  setHands(e: DistributeEvent): void;
998
1004
  handleDiscard(tiles: Tile[]): Tile;
999
1005
  handleEvent(e: PlayerEvent): void;
1000
1006
  }
1001
1007
 
1002
- export declare interface PlayerCandidate {
1003
- tile: Tile;
1004
- sum: number;
1005
- candidates: {
1006
- tile: Tile;
1007
- n: number;
1008
- }[];
1009
- shanten: number;
1008
+ export declare class PlayerEfficiency {
1009
+ static analyzePlayerEfficiency(counter: Counter, analyses: TileAnalysis[]): PlayerTileAnalysis[];
1010
+ static selectMinPriority(c: Counter, playerAnalyses: PlayerTileAnalysis[], doras: Tile[]): PlayerTileAnalysis;
1011
+ private static calcPriority;
1010
1012
  }
1011
1013
 
1012
- export declare interface PlayerConnection {
1014
+ export declare type PlayerEvent = DistributeEvent | EndEvent | CallEvent | RonEvent | TsumoEvent | DiscardEvent | DrawEvent | ReachEvent | ReachAcceptedEvent | NewDoraEvent | ChoiceAfterDrawnEvent | ChoiceAfterDiscardedEvent | ChoiceAfterCalled | ChoiceForReachAcceptance | ChoiceForChanKan;
1015
+
1016
+ export declare interface PlayerSession {
1013
1017
  id: string;
1014
1018
  handler: EventHandler;
1015
1019
  }
1016
1020
 
1017
- export declare class PlayerEfficiency {
1018
- static calcPlayerCandidates(counter: Counter, candidates: Candidate[]): PlayerCandidate[];
1019
- static selectMinPriority(c: Counter, playerCandidates: PlayerCandidate[], doras: Tile[]): PlayerCandidate;
1020
- private static calcPriority;
1021
+ export declare interface PlayerTileAnalysis {
1022
+ tile: Tile;
1023
+ sum: number;
1024
+ effectiveTiles: {
1025
+ tile: Tile;
1026
+ count: number;
1027
+ }[];
1028
+ shanten: number;
1021
1029
  }
1022
1030
 
1023
- export declare type PlayerEvent = DistributeEvent | EndEvent | CallEvent | RonEvent | TsumoEvent | DiscardEvent | DrawEvent | ReachEvent | ReachAcceptedEvent | NewDoraEvent | ChoiceAfterDrawnEvent | ChoiceAfterDiscardedEvent | ChoiceAfterCalled | ChoiceForReachAcceptance | ChoiceForChanKan;
1024
-
1025
1031
  export declare class PointCalculator {
1026
1032
  hand: Hand;
1027
1033
  cfg: {
1028
1034
  doras: readonly Tile[];
1029
- blindDoras: readonly Tile[];
1035
+ hiddenDoras: readonly Tile[];
1030
1036
  roundWind: Tile;
1031
1037
  myWind: Tile;
1032
1038
  reached: 0 | 1 | 2;
@@ -1039,19 +1045,26 @@ export declare class PointCalculator {
1039
1045
  finalWallWin: boolean;
1040
1046
  finalDiscardWin: boolean;
1041
1047
  oneShotWin: boolean;
1042
- enableRoundUp8000: boolean;
1043
- disableCountable32000: boolean;
1044
- disableDouble32000: boolean;
1048
+ enableRoundUpMangan: boolean;
1049
+ disableCountableYakuman: boolean;
1050
+ disableDoubleYakuman: boolean;
1045
1051
  orig: BoardContext;
1046
1052
  };
1047
1053
  constructor(hand: Hand, params: BoardContext);
1048
1054
  calc(...hands: readonly Block[][]): WinResult | false;
1049
- calcPatterns(hands: readonly Block[][]): {
1050
- yakus: Yaku[];
1051
- fu: number;
1052
- hand: Block[];
1053
- is32000?: boolean;
1054
- }[];
1055
+ getWinningHands(hands: readonly Block[][]): WinningHand[];
1056
+ private selectBestHand;
1057
+ private calculateScore;
1058
+ private hasYakuman;
1059
+ private isRoundUpMangan;
1060
+ private isTsumoWin;
1061
+ private calculateDeltas;
1062
+ private calculateRonDeltas;
1063
+ private calculateTsumoDeltas;
1064
+ private calculateParentTsumoDeltas;
1065
+ private calculateChildTsumoDeltas;
1066
+ private addStickPoints;
1067
+ private getBasePoints;
1055
1068
  private minus;
1056
1069
  dA1(h: readonly Block[]): Yaku[];
1057
1070
  dB1(h: readonly Block[]): Yaku[];
@@ -1137,7 +1150,7 @@ export declare class Rect extends Mark {
1137
1150
 
1138
1151
  export declare class Replayer {
1139
1152
  index: number;
1140
- histories: History_2[];
1153
+ histories: GameHistory[];
1141
1154
  constructor(v: string);
1142
1155
  next(): void;
1143
1156
  prev(): void;
@@ -1161,7 +1174,11 @@ export declare class River {
1161
1174
  t: Tile;
1162
1175
  callMarker?: boolean;
1163
1176
  }[];
1164
- get lastTile(): any;
1177
+ get lastTile(): {
1178
+ w: Wind;
1179
+ t: Tile;
1180
+ callMarker?: boolean;
1181
+ };
1165
1182
  markCalled(): void;
1166
1183
  cannotContinue(): boolean;
1167
1184
  }
@@ -1260,9 +1277,9 @@ declare type SerializedBoardContext = Omit<BoardContext, "doraIndicators" | "hid
1260
1277
  hiddenDoraIndicators?: readonly string[];
1261
1278
  };
1262
1279
 
1263
- export declare interface SerializedCandidate {
1280
+ export declare interface SerializedTileAnalysis {
1264
1281
  tile: string;
1265
- candidates: readonly string[];
1282
+ effectiveTiles: readonly string[];
1266
1283
  shanten: number;
1267
1284
  }
1268
1285
 
@@ -1279,10 +1296,10 @@ export declare class ShantenCalculator {
1279
1296
  calc(): number;
1280
1297
  sevenPairs(): number;
1281
1298
  thirteenOrphans(): number;
1282
- fourSetsOnePair(): number;
1283
- private patternNumType;
1299
+ standardType(): number;
1300
+ private calcNumberTilePatterns;
1284
1301
  private groupRemainingTiles;
1285
- private calcCommon;
1302
+ private calcStandardType;
1286
1303
  }
1287
1304
 
1288
1305
  export declare function shuffle<T>(array: T[]): T[];
@@ -1432,7 +1449,11 @@ export declare const TILE_CONTEXT: {
1432
1449
  readonly BLOCK_MARGIN_SCALE: 0.3;
1433
1450
  };
1434
1451
 
1435
- export declare const tileSortFunc: (i: Tile, j: Tile) => number;
1452
+ export declare interface TileAnalysis {
1453
+ tile: Tile;
1454
+ effectiveTiles: readonly Tile[];
1455
+ shanten: number;
1456
+ }
1436
1457
 
1437
1458
  export declare const toDora: (doraIndicator: Tile) => Tile;
1438
1459
 
@@ -1513,16 +1534,20 @@ export declare const WIND_MAP: {
1513
1534
  readonly "4z": "北";
1514
1535
  };
1515
1536
 
1516
- export declare interface WinResult {
1537
+ declare interface WinningHand {
1538
+ hand: Block[];
1539
+ fu: number;
1540
+ yakus: readonly Yaku[];
1541
+ han: number;
1542
+ isYakuman?: boolean;
1543
+ }
1544
+
1545
+ export declare interface WinResult extends WinningHand {
1517
1546
  deltas: {
1518
1547
  readonly [w in Wind]: number;
1519
1548
  };
1520
- han: number;
1521
- fu: number;
1522
- yakus: readonly Yaku[];
1523
1549
  points: number;
1524
- rawPoints: number;
1525
- hand: Block[];
1550
+ basePoints: number;
1526
1551
  boardContext: BoardContext;
1527
1552
  description: string;
1528
1553
  }
@@ -1530,7 +1555,7 @@ export declare interface WinResult {
1530
1555
  export declare interface Yaku {
1531
1556
  name: string;
1532
1557
  han: number;
1533
- is32000?: boolean;
1558
+ isYakuman?: boolean;
1534
1559
  }
1535
1560
 
1536
1561
  export { }