diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..497dc9c --- /dev/null +++ b/biome.json @@ -0,0 +1,33 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", + "vcs": { + "enabled": false, + "clientKind": "git", + "useIgnoreFile": false + }, + "files": { + "ignoreUnknown": false, + "ignore": [] + }, + "formatter": { + "enabled": true, + "indentStyle": "space" + }, + "organizeImports": { + "enabled": true + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true, + "style": { + "noUselessElse": "off" + } + } + }, + "javascript": { + "formatter": { + "quoteStyle": "double" + } + } +} diff --git a/index.ts b/index.ts index a49066f..a846d53 100644 --- a/index.ts +++ b/index.ts @@ -1,12 +1,20 @@ -import { Calculate, Hand, HuAll, WinningStyle, YakuAll, YakuChitoitsu, YakuPinhu } from "./types"; -import { Position } from "./types/field"; +import type { + Calculate, + Hand, + HuAll, + WinningStyle, + YakuAll, + YakuChitoitsu, + YakuPinhu, +} from "./types"; +import type { Position } from "./types/field"; export type MahjongKun< HAND extends Hand, WINNING extends HAND[number], NAKI extends HAND[number][], STYLE extends WinningStyle, - POSITION extends Position + POSITION extends Position, > = Calculate< YakuAll, HuAll, @@ -15,8 +23,8 @@ export type MahjongKun< YakuChitoitsu extends [1, 1] ? "chitoitsu" : STYLE extends "tumo" - ? YakuPinhu extends [1] - ? "pin-tumo" + ? YakuPinhu extends [1] + ? "pin-tumo" + : null : null - : null >; diff --git a/package.json b/package.json index 82a7add..a631664 100644 --- a/package.json +++ b/package.json @@ -6,15 +6,11 @@ "license": "MIT", "scripts": { "test": "tsc --noEmit", - "build": "tsc --noEmit && esbuild index.ts --bundle --minify --outfile=dist/index.js" + "build": "tsc ./index.ts --declaration --outDir ./dist --emitDeclarationOnly" }, "devDependencies": { - "esbuild": "^0.14.11", - "eslint": "^8.10.0", - "prettier": "^2.5.1", - "typescript": "^4.5.4" - }, - "prettier": { - "printWidth": 120 + "@biomejs/biome": "^1.9.4", + "esbuild": "^0.24.0", + "typescript": "^5.6.3" } } diff --git a/tests/huAll.test.ts b/tests/huAll.test.ts index 16f038f..6789d43 100644 --- a/tests/huAll.test.ts +++ b/tests/huAll.test.ts @@ -4,32 +4,132 @@ import { Equal, HuAll } from "../types"; // 20 + 4 + 4 type Case1_1 = ExpectTrue< Equal< - HuAll<["o2", "o3", "o4", "I2", "I2", "I2", "C4", "C5", "C6", "I6", "I6", "I6", "o4", "o4"], "o2", [], "ron">, + HuAll< + [ + "o2", + "o3", + "o4", + "I2", + "I2", + "I2", + "C4", + "C5", + "C6", + "I6", + "I6", + "I6", + "o4", + "o4", + ], + "o2", + [], + "ron" + >, 40 > >; // 20 type Case2_1 = ExpectTrue< Equal< - HuAll<["o2", "o3", "o4", "I2", "I3", "I4", "C4", "C5", "C6", "I2", "I3", "I4", "o4", "o4"], "o2", [], "ron">, + HuAll< + [ + "o2", + "o3", + "o4", + "I2", + "I3", + "I4", + "C4", + "C5", + "C6", + "I2", + "I3", + "I4", + "o4", + "o4", + ], + "o2", + [], + "ron" + >, 30 > >; type Case2_2 = ExpectTrue< Equal< - HuAll<["o2", "o3", "o4", "I2", "I3", "I4", "C4", "C5", "C6", "I2", "I3", "I4", "o4", "o4"], "o2", [], "tumo">, + HuAll< + [ + "o2", + "o3", + "o4", + "I2", + "I3", + "I4", + "C4", + "C5", + "C6", + "I2", + "I3", + "I4", + "o4", + "o4", + ], + "o2", + [], + "tumo" + >, 30 > >; type Case2_3 = ExpectTrue< Equal< - HuAll<["o2", "o3", "o4", "I2", "I3", "I4", "C4", "C5", "C6", "I2", "I3", "I4", "o4", "o4"], "o2", ["I2"], "ron">, + HuAll< + [ + "o2", + "o3", + "o4", + "I2", + "I3", + "I4", + "C4", + "C5", + "C6", + "I2", + "I3", + "I4", + "o4", + "o4", + ], + "o2", + ["I2"], + "ron" + >, 20 > >; type Case2_4 = ExpectTrue< Equal< - HuAll<["o2", "o3", "o4", "I2", "I3", "I4", "C4", "C5", "C6", "I2", "I3", "I4", "o4", "o4"], "o2", ["I2"], "tumo">, + HuAll< + [ + "o2", + "o3", + "o4", + "I2", + "I3", + "I4", + "C4", + "C5", + "C6", + "I2", + "I3", + "I4", + "o4", + "o4", + ], + "o2", + ["I2"], + "tumo" + >, 30 > >; diff --git a/tests/mahjong.test.ts b/tests/mahjong.test.ts index ee54c66..0185972 100644 --- a/tests/mahjong.test.ts +++ b/tests/mahjong.test.ts @@ -2,39 +2,113 @@ import { MahjongKun } from "../index"; import { ExpectTrue } from "./testUtil"; import { Equal, Hand, HuAll } from "../types"; -export type RonChildCase = MahjongKun< - HAND, - WINNING, - NAKI, - "ron", - "child" ->; +export type RonChildCase< + HAND extends Hand, + WINNING extends HAND[number], + NAKI extends HAND[number][], +> = MahjongKun; // 1_1 タンヤオのみ・30, 40, 50符 type Case1_1_1 = ExpectTrue< Equal< - RonChildCase<["o2", "o3", "o4", "I2", "I2", "I2", "C4", "C5", "C6", "I6", "I6", "I6", "o4", "o4"], "o3", ["C6"]>, + RonChildCase< + [ + "o2", + "o3", + "o4", + "I2", + "I2", + "I2", + "C4", + "C5", + "C6", + "I6", + "I6", + "I6", + "o4", + "o4", + ], + "o3", + ["C6"] + >, "1000" > >; type Case1_1_2 = ExpectTrue< Equal< - RonChildCase<["o2", "o3", "o4", "I2", "I2", "I2", "C4", "C5", "C6", "I6", "I6", "I6", "o4", "o4"], "o3", []>, + RonChildCase< + [ + "o2", + "o3", + "o4", + "I2", + "I2", + "I2", + "C4", + "C5", + "C6", + "I6", + "I6", + "I6", + "o4", + "o4", + ], + "o3", + [] + >, "1300" > >; type Case1_1_3 = ExpectTrue< Equal< - RonChildCase<["o2", "o3", "o4", "I2", "I2", "I2", "C4", "C4", "C4", "I6", "I6", "I6", "o4", "o4"], "o3", []>, + RonChildCase< + [ + "o2", + "o3", + "o4", + "I2", + "I2", + "I2", + "C4", + "C4", + "C4", + "I6", + "I6", + "I6", + "o4", + "o4", + ], + "o3", + [] + >, "1600" > >; type Case1_1_4 = ExpectTrue< Equal< - RonChildCase<["o2", "o3", "o4", "I2", "I3", "I4", "C4", "C5", "C6", "I5", "I6", "I7", "o4", "o4"], "o3", []>, + RonChildCase< + [ + "o2", + "o3", + "o4", + "I2", + "I3", + "I4", + "C4", + "C5", + "C6", + "I5", + "I6", + "I7", + "o4", + "o4", + ], + "o3", + [] + >, "1300" > >; @@ -42,14 +116,52 @@ type Case1_1_4 = ExpectTrue< // 1_2 一盃口のみ type Case1_2_1 = ExpectTrue< Equal< - RonChildCase<["o2", "o3", "o4", "o2", "o3", "o4", "C9", "C9", "C9", "I5", "I6", "I7", "o4", "o4"], "o2", []>, + RonChildCase< + [ + "o2", + "o3", + "o4", + "o2", + "o3", + "o4", + "C9", + "C9", + "C9", + "I5", + "I6", + "I7", + "o4", + "o4", + ], + "o2", + [] + >, "1300" > >; type Case1_2_2 = ExpectTrue< Equal< - RonChildCase<["o2", "o3", "o4", "o2", "o3", "o4", "C7", "C8", "C9", "I5", "I6", "I7", "o4", "o4"], "o3", []>, + RonChildCase< + [ + "o2", + "o3", + "o4", + "o2", + "o3", + "o4", + "C7", + "C8", + "C9", + "I5", + "I6", + "I7", + "o4", + "o4", + ], + "o3", + [] + >, "1300" > >; @@ -57,7 +169,26 @@ type Case1_2_2 = ExpectTrue< // リャンメンで平和が付く type Case1_2_3 = ExpectTrue< Equal< - RonChildCase<["o2", "o3", "o4", "o2", "o3", "o4", "C7", "C8", "C9", "I5", "I6", "I7", "o4", "o4"], "o2", []>, + RonChildCase< + [ + "o2", + "o3", + "o4", + "o2", + "o3", + "o4", + "C7", + "C8", + "C9", + "I5", + "I6", + "I7", + "o4", + "o4", + ], + "o2", + [] + >, "2000" > >; diff --git a/tests/point.test.ts b/tests/point.test.ts index 2bf37e2..60a7b5c 100644 --- a/tests/point.test.ts +++ b/tests/point.test.ts @@ -1,16 +1,36 @@ import { Calculate, Equal } from "../types"; import { ExpectTrue } from "./testUtil"; -type RonChildCase1_1 = ExpectTrue, "1000">>; -type RonChildCase1_2 = ExpectTrue, "500,1000">>; -type RonChildCase1_3 = ExpectTrue, "700,1300">>; +type RonChildCase1_1 = ExpectTrue< + Equal, "1000"> +>; +type RonChildCase1_2 = ExpectTrue< + Equal, "500,1000"> +>; +type RonChildCase1_3 = ExpectTrue< + Equal, "700,1300"> +>; // ピンヅモは20符として計算 -type RonChildCase2_1 = ExpectTrue, "400,700">>; -type RonChildCase2_2 = ExpectTrue, "400,700">>; -type RonChildCase2_3 = ExpectTrue, "400,700">>; +type RonChildCase2_1 = ExpectTrue< + Equal, "400,700"> +>; +type RonChildCase2_2 = ExpectTrue< + Equal, "400,700"> +>; +type RonChildCase2_3 = ExpectTrue< + Equal, "400,700"> +>; // 七対子は25符として計算 -type RonChildCase3_1 = ExpectTrue, "800,1600">>; -type RonChildCase3_2 = ExpectTrue, "800,1600">>; +type RonChildCase3_1 = ExpectTrue< + Equal, "800,1600"> +>; +type RonChildCase3_2 = ExpectTrue< + Equal, "800,1600"> +>; // ピンヅモ以外で20符になった場合は30符で計算 -type RonChildCase4_1 = ExpectTrue, "300,500">>; -type RonChildCase4_2 = ExpectTrue, "1000">>; +type RonChildCase4_1 = ExpectTrue< + Equal, "300,500"> +>; +type RonChildCase4_2 = ExpectTrue< + Equal, "1000"> +>; diff --git a/tests/testUtil.ts b/tests/testUtil.ts index 5ac3cb0..a8151bc 100644 --- a/tests/testUtil.ts +++ b/tests/testUtil.ts @@ -1,3 +1,3 @@ // For Test -export type ExpectTrue = T -export type ExpectFalse = T +export type ExpectTrue = T; +export type ExpectFalse = T; diff --git a/tests/tileSet.test.ts b/tests/tileSet.test.ts index c12cdab..4ef047b 100644 --- a/tests/tileSet.test.ts +++ b/tests/tileSet.test.ts @@ -1,26 +1,25 @@ - // SameMark import { IsChow, IsClaimed, IsSameMark } from "../types"; import { ExpectFalse, ExpectTrue } from "./testUtil"; -type Case1 = ExpectFalse> -type Case2 = ExpectFalse> -type Case3 = ExpectFalse> -type Case4 = ExpectFalse> -type Case5 = ExpectFalse> -type Case6 = ExpectTrue> -type Case7 = ExpectTrue> -type Case8 = ExpectTrue> +type Case1 = ExpectFalse>; +type Case2 = ExpectFalse>; +type Case3 = ExpectFalse>; +type Case4 = ExpectFalse>; +type Case5 = ExpectFalse>; +type Case6 = ExpectTrue>; +type Case7 = ExpectTrue>; +type Case8 = ExpectTrue>; // IsChow -type IsChowCase1 = ExpectTrue> -type IsChowCase2 = ExpectTrue> -type IsChowCase3 = ExpectTrue> -type IsChowCase4 = ExpectFalse> -type IsChowCase5 = ExpectFalse> +type IsChowCase1 = ExpectTrue>; +type IsChowCase2 = ExpectTrue>; +type IsChowCase3 = ExpectTrue>; +type IsChowCase4 = ExpectFalse>; +type IsChowCase5 = ExpectFalse>; // IsClaimed -type IsClaimedCase1 = ExpectTrue> -type IsClaimedCase2 = ExpectTrue> -type IsClaimedCase3 = ExpectTrue> -type IsClaimedCase4 = ExpectFalse> +type IsClaimedCase1 = ExpectTrue>; +type IsClaimedCase2 = ExpectTrue>; +type IsClaimedCase3 = ExpectTrue>; +type IsClaimedCase4 = ExpectFalse>; diff --git a/tests/utilType.test.ts b/tests/utilType.test.ts index 3af94f4..1446645 100644 --- a/tests/utilType.test.ts +++ b/tests/utilType.test.ts @@ -1,4 +1,11 @@ -import { AndAll, ConcatAll, Contains, Equal, IsContinuousNumber, OrAll } from "../types"; +import { + AndAll, + ConcatAll, + Contains, + Equal, + IsContinuousNumber, + OrAll, +} from "../types"; import { ExpectFalse, ExpectTrue } from "./testUtil"; type IsContinuousNumberCase1 = ExpectTrue>; @@ -7,7 +14,9 @@ type IsContinuousNumberCase3 = ExpectTrue>; type IsContinuousNumberCase4 = ExpectFalse>; type IsContinuousNumberCase5 = ExpectFalse>; -type ConcatCase1 = ExpectTrue, [1, 2, 3, 4, 5, 6]>>; +type ConcatCase1 = ExpectTrue< + Equal, [1, 2, 3, 4, 5, 6]> +>; type AndAllCase1 = ExpectTrue>; type AndAllCase2 = ExpectFalse>; diff --git a/tests/winning.test.ts b/tests/winning.test.ts index 8a52696..a68cdff 100644 --- a/tests/winning.test.ts +++ b/tests/winning.test.ts @@ -1,15 +1,15 @@ import { IsPencyan, IsRyanmen } from "../types"; import { ExpectFalse, ExpectTrue } from "./testUtil"; -type RyanmenCase1 = ExpectTrue> -type RyanmenCase2 = ExpectTrue> -type RyanmenCase3 = ExpectFalse> -type RyanmenCase4 = ExpectFalse> -type RyanmenCase5 = ExpectFalse> +type RyanmenCase1 = ExpectTrue>; +type RyanmenCase2 = ExpectTrue>; +type RyanmenCase3 = ExpectFalse>; +type RyanmenCase4 = ExpectFalse>; +type RyanmenCase5 = ExpectFalse>; // Pencyan -type PencyanCase1 = ExpectTrue> -type PencyanCase2 = ExpectTrue> -type PencyanCase3 = ExpectFalse> -type PencyanCase4 = ExpectFalse> -type PencyanCase5 = ExpectFalse> \ No newline at end of file +type PencyanCase1 = ExpectTrue>; +type PencyanCase2 = ExpectTrue>; +type PencyanCase3 = ExpectFalse>; +type PencyanCase4 = ExpectFalse>; +type PencyanCase5 = ExpectFalse>; diff --git a/tests/yaku.test.ts b/tests/yaku.test.ts index e9d9ab5..467d13e 100644 --- a/tests/yaku.test.ts +++ b/tests/yaku.test.ts @@ -1,68 +1,409 @@ -import { Equal, Hand, YakuIpeko, YakuPinhu, YakuTanyao, YakuToiToi } from "../types"; +import { + Equal, + Hand, + YakuIpeko, + YakuPinhu, + YakuTanyao, + YakuToiToi, +} from "../types"; import { ExpectFalse, ExpectTrue } from "./testUtil"; -type IsPinhu = Equal< - YakuPinhu, - [1] ->; +type IsPinhu< + HAND extends Hand, + WINNING extends HAND[number], + NAKI extends HAND[number][] = [], +> = Equal, [1]>; type PinhuCase1 = ExpectTrue< - IsPinhu<["o1", "o2", "o3", "I1", "I2", "I3", "C4", "C5", "C6", "I6", "I7", "I8", "o4", "o4"], "I8"> + IsPinhu< + [ + "o1", + "o2", + "o3", + "I1", + "I2", + "I3", + "C4", + "C5", + "C6", + "I6", + "I7", + "I8", + "o4", + "o4", + ], + "I8" + > >; type PinhuCase2 = ExpectTrue< - IsPinhu<["o1", "o2", "o3", "I1", "I2", "I3", "C4", "C5", "C6", "I6", "I7", "I8", "o4", "o4"], "o1"> + IsPinhu< + [ + "o1", + "o2", + "o3", + "I1", + "I2", + "I3", + "C4", + "C5", + "C6", + "I6", + "I7", + "I8", + "o4", + "o4", + ], + "o1" + > >; type PinhuCase3 = ExpectTrue< - IsPinhu<["o2", "o3", "o4", "I1", "I2", "I3", "C4", "C5", "C6", "I6", "I7", "I8", "o4", "o4"], "o4"> + IsPinhu< + [ + "o2", + "o3", + "o4", + "I1", + "I2", + "I3", + "C4", + "C5", + "C6", + "I6", + "I7", + "I8", + "o4", + "o4", + ], + "o4" + > >; type PinhuCase4 = ExpectTrue< - IsPinhu<["o1", "o2", "o3", "I1", "I2", "I3", "C4", "C5", "C6", "I6", "I7", "I8", "west", "west"], "I8"> + IsPinhu< + [ + "o1", + "o2", + "o3", + "I1", + "I2", + "I3", + "C4", + "C5", + "C6", + "I6", + "I7", + "I8", + "west", + "west", + ], + "I8" + > >; type PinhuCase5 = ExpectFalse< - IsPinhu<["o1", "o2", "o3", "I1", "I2", "I3", "C4", "C5", "C6", "I6", "I7", "I8", "o4", "o4"], "I7"> + IsPinhu< + [ + "o1", + "o2", + "o3", + "I1", + "I2", + "I3", + "C4", + "C5", + "C6", + "I6", + "I7", + "I8", + "o4", + "o4", + ], + "I7" + > >; type PinhuCase6 = ExpectFalse< - IsPinhu<["o1", "o2", "o3", "I1", "I2", "I3", "C4", "C5", "C6", "I6", "I7", "I8", "o4", "o4"], "o3"> + IsPinhu< + [ + "o1", + "o2", + "o3", + "I1", + "I2", + "I3", + "C4", + "C5", + "C6", + "I6", + "I7", + "I8", + "o4", + "o4", + ], + "o3" + > >; type PinhuCase7 = ExpectFalse< - IsPinhu<["o1", "o2", "o3", "I1", "I2", "I3", "C4", "C5", "C6", "I6", "I7", "I8", "o4", "o4"], "o4"> + IsPinhu< + [ + "o1", + "o2", + "o3", + "I1", + "I2", + "I3", + "C4", + "C5", + "C6", + "I6", + "I7", + "I8", + "o4", + "o4", + ], + "o4" + > >; -type IsTanyao = Equal, [1]>; +type IsTanyao = Equal< + YakuTanyao, + [1] +>; type TanyaoCase1 = ExpectTrue< - IsTanyao<["o2", "o3", "o4", "I2", "I2", "I2", "C4", "C5", "C6", "I6", "I6", "I6", "o4", "o4"], "o3"> + IsTanyao< + [ + "o2", + "o3", + "o4", + "I2", + "I2", + "I2", + "C4", + "C5", + "C6", + "I6", + "I6", + "I6", + "o4", + "o4", + ], + "o3" + > >; type TanyaoCase2 = ExpectTrue< - IsTanyao<["o2", "o2", "o2", "I8", "I8", "I8", "C4", "C5", "C6", "I6", "I7", "I8", "o4", "o4"], "o4"> + IsTanyao< + [ + "o2", + "o2", + "o2", + "I8", + "I8", + "I8", + "C4", + "C5", + "C6", + "I6", + "I7", + "I8", + "o4", + "o4", + ], + "o4" + > >; type TanyaoCase3 = ExpectTrue< - IsTanyao<["o8", "o8", "o8", "I2", "I3", "I4", "C2", "C2", "C2", "I6", "I7", "I8", "C5", "C5"], "I8"> + IsTanyao< + [ + "o8", + "o8", + "o8", + "I2", + "I3", + "I4", + "C2", + "C2", + "C2", + "I6", + "I7", + "I8", + "C5", + "C5", + ], + "I8" + > >; type TanyaoCase4 = ExpectFalse< - IsTanyao<["o8", "o9", "o8", "I2", "I3", "I4", "C2", "C2", "C2", "I6", "I7", "I8", "C5", "C5"], "I8"> + IsTanyao< + [ + "o8", + "o9", + "o8", + "I2", + "I3", + "I4", + "C2", + "C2", + "C2", + "I6", + "I7", + "I8", + "C5", + "C5", + ], + "I8" + > >; type TanyaoCase5 = ExpectFalse< - IsTanyao<["o8", "o8", "o8", "I2", "I3", "I4", "C2", "C2", "C2", "I6", "I7", "I8", "east", "east"], "I8"> + IsTanyao< + [ + "o8", + "o8", + "o8", + "I2", + "I3", + "I4", + "C2", + "C2", + "C2", + "I6", + "I7", + "I8", + "east", + "east", + ], + "I8" + > >; type TanyaoCase6 = ExpectFalse< - IsTanyao<["o8", "o8", "o8", "I1", "I2", "I3", "C2", "C2", "C2", "I6", "I7", "I8", "C5", "C5"], "I8"> + IsTanyao< + [ + "o8", + "o8", + "o8", + "I1", + "I2", + "I3", + "C2", + "C2", + "C2", + "I6", + "I7", + "I8", + "C5", + "C5", + ], + "I8" + > >; -type IsToiToi = Equal, [1, 1]>; +type IsToiToi = Equal< + YakuToiToi, + [1, 1] +>; type ToiToiCase1 = ExpectTrue< - IsToiToi<["o2", "o2", "o2", "I2", "I2", "I2", "C5", "C5", "C5", "I6", "I6", "I6", "o4", "o4"], "o4"> + IsToiToi< + [ + "o2", + "o2", + "o2", + "I2", + "I2", + "I2", + "C5", + "C5", + "C5", + "I6", + "I6", + "I6", + "o4", + "o4", + ], + "o4" + > >; type ToiToiCase2 = ExpectTrue< - IsToiToi<["o2", "o2", "o2", "I2", "I2", "I2", "C5", "C5", "C5", "I6", "I6", "I6", "o4", "o4"], "I2"> + IsToiToi< + [ + "o2", + "o2", + "o2", + "I2", + "I2", + "I2", + "C5", + "C5", + "C5", + "I6", + "I6", + "I6", + "o4", + "o4", + ], + "I2" + > >; type ToiToiCase3 = ExpectFalse< - IsToiToi<["o2", "o2", "o2", "I2", "I2", "I2", "C5", "C5", "C5", "I5", "I6", "I7", "o4", "o4"], "I2"> + IsToiToi< + [ + "o2", + "o2", + "o2", + "I2", + "I2", + "I2", + "C5", + "C5", + "C5", + "I5", + "I6", + "I7", + "o4", + "o4", + ], + "I2" + > >; -type IsIpeko = Equal, [1]>; +type IsIpeko = Equal< + YakuIpeko, + [1] +>; type IpekoCase1 = ExpectTrue< - IsIpeko<["o2", "o3", "o4", "o2", "o3", "o4", "C5", "C5", "C5", "I6", "I6", "I6", "o4", "o4"], "o2"> + IsIpeko< + [ + "o2", + "o3", + "o4", + "o2", + "o3", + "o4", + "C5", + "C5", + "C5", + "I6", + "I6", + "I6", + "o4", + "o4", + ], + "o2" + > >; type IpekoCase2 = ExpectTrue< - IsIpeko<["o2", "o3", "o4", "I2", "I2", "I2", "o2", "o3", "o4", "C5", "C5", "C5", "o4", "o4"], "o2"> + IsIpeko< + [ + "o2", + "o3", + "o4", + "I2", + "I2", + "I2", + "o2", + "o3", + "o4", + "C5", + "C5", + "C5", + "o4", + "o4", + ], + "o2" + > >; diff --git a/tests/yakuAll.test.ts b/tests/yakuAll.test.ts index ac6eeea..351a1eb 100644 --- a/tests/yakuAll.test.ts +++ b/tests/yakuAll.test.ts @@ -2,9 +2,47 @@ import { Equal, YakuAll } from "../types"; import { ExpectTrue } from "./testUtil"; // ピンフ・タンヤオ・一盃口 -type Case1 = YakuAll<["o2", "o3", "o4", "I6", "I7", "I8", "C4", "C5", "C6", "I6", "I7", "I8", "o4", "o4"], "o4", []>; +type Case1 = YakuAll< + [ + "o2", + "o3", + "o4", + "I6", + "I7", + "I8", + "C4", + "C5", + "C6", + "I6", + "I7", + "I8", + "o4", + "o4", + ], + "o4", + [] +>; type ExpectYaku1 = ExpectTrue>; // タンヤオ・トイトイ -type Case2 = YakuAll<["o3", "o3", "o3", "I7", "I7", "I7", "C5", "C5", "C5", "I5", "I5", "I5", "o4", "o4"], "o4", []>; +type Case2 = YakuAll< + [ + "o3", + "o3", + "o3", + "I7", + "I7", + "I7", + "C5", + "C5", + "C5", + "I5", + "I5", + "I5", + "o4", + "o4", + ], + "o4", + [] +>; type ExpectYaku2 = ExpectTrue>; diff --git a/tsconfig.json b/tsconfig.json index 1170a6d..605b965 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,11 @@ { "compilerOptions": { - "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ - "module": "commonjs", /* Specify what module code is generated. */ - "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */ - "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ - "strict": true, /* Enable all strict type-checking options. */ - "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, + "module": "commonjs" /* Specify what module code is generated. */, + "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */, + "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, + "strict": true /* Enable all strict type-checking options. */, + "skipLibCheck": true /* Skip type checking all .d.ts files. */, "outDir": "dist" } } diff --git a/types/hand.ts b/types/hand.ts index ba08221..f0f8d0c 100644 --- a/types/hand.ts +++ b/types/hand.ts @@ -1,6 +1,21 @@ import { Tile } from "./tile"; -export type Hand = [Tile, Tile, Tile, Tile, Tile, Tile, Tile, Tile, Tile, Tile, Tile, Tile, Tile, Tile]; +export type Hand = [ + Tile, + Tile, + Tile, + Tile, + Tile, + Tile, + Tile, + Tile, + Tile, + Tile, + Tile, + Tile, + Tile, + Tile, +]; export type Chunk1 = [HAND[0], HAND[1], HAND[2]]; export type Chunk2 = [HAND[3], HAND[4], HAND[5]]; diff --git a/types/hu/huHandSet.ts b/types/hu/huHandSet.ts index 257f4e9..894dd49 100644 --- a/types/hu/huHandSet.ts +++ b/types/hu/huHandSet.ts @@ -1,10 +1,21 @@ -import { HuValue0, HuValue16, HuValue2, HuValue32, HuValue4, HuValue8 } from "../huValues"; +import { + HuValue0, + HuValue16, + HuValue2, + HuValue32, + HuValue4, + HuValue8, +} from "../huValues"; import { Chunk1, Chunk2, Chunk3, Chunk4, Hand } from "../hand"; import { IsYaochu, Tile, TileSet } from "../tile"; import { IsSet } from "../tileSet"; import { Equal, OrAll } from "../utilType"; -export type HuSet = HuHandSet< +export type HuSet< + HAND extends Hand, + WINNING extends HAND[number], + NAKI extends HAND[number][], +> = HuHandSet< Chunk1, Chunk2, Chunk3, @@ -30,21 +41,26 @@ type HuSetValues = { }; }; -type CheckSetKind = IsSet extends true +type CheckSetKind< + SET extends TileSet, + NAKI extends Tile[], +> = IsSet extends true ? OrAll< [ Equal, Equal, Equal, Equal, - Equal + Equal, ] > extends true ? "minko" : "anko" : "shuntu"; -type SetHuValue = IsYaochu extends true +type SetHuValue = IsYaochu< + SET[0] +> extends true ? HuSetValues["yao-chu"][CheckSetKind] : HuSetValues["chun-chan"][CheckSetKind]; @@ -54,10 +70,10 @@ type HuHandSet< C3 extends TileSet, C4 extends TileSet, WINNING extends Tile, - NAKI extends Tile[] + NAKI extends Tile[], > = [ SetHuValue, SetHuValue, SetHuValue, - SetHuValue + SetHuValue, ]; diff --git a/types/hu/huMachi.ts b/types/hu/huMachi.ts index 5282a0f..5df6a1b 100644 --- a/types/hu/huMachi.ts +++ b/types/hu/huMachi.ts @@ -9,7 +9,7 @@ export type HuMachi = OrAll< IsKanchan, WINNING>, IsKanchan, WINNING>, IsKanchan, WINNING>, - IsTanki, WINNING> + IsTanki, WINNING>, ] > extends true ? HuValue2 diff --git a/types/hu/huWinning.ts b/types/hu/huWinning.ts index d2e709f..fd36021 100644 --- a/types/hu/huWinning.ts +++ b/types/hu/huWinning.ts @@ -1,7 +1,10 @@ import { WinningStyle } from "../winning"; import { HuValue0, HuValue10, HuValue2 } from "../huValues"; -export type HuWinning