Skip to content

Commit

Permalink
迁移至v0.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ssttkkl committed Jul 8, 2023
1 parent fea9611 commit 2fa69e7
Show file tree
Hide file tree
Showing 13 changed files with 492 additions and 139 deletions.
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"antd": "^5.1.7",
"mahjong-utils": "^0.3.0",
"mahjong-utils": "^0.6.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
Expand Down
25 changes: 16 additions & 9 deletions demo/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4902,6 +4902,11 @@ form-data@^3.0.0:
combined-stream "^1.0.8"
mime-types "^2.1.12"

format-util@^1.0.5:
version "1.0.5"
resolved "http://localhost:4873/format-util/-/format-util-1.0.5.tgz#1ffb450c8a03e7bccffe40643180918cc297d271"
integrity sha512-varLbTj0e0yVyRpqQhuWV+8hlePAgaoFRhNFj50BNjEIrw1/DphHSObtqwskVCPWNgzwPoQrZAbfa/SBiicNeg==

[email protected]:
version "0.2.0"
resolved "https://registry.npmmirror.com/forwarded/-/forwarded-0.2.0.tgz#2269936428aad4c15c7ebe9779a84bf0b2a81811"
Expand Down Expand Up @@ -6562,17 +6567,19 @@ magic-string@^0.25.0, magic-string@^0.25.7:
dependencies:
sourcemap-codec "^1.4.8"

mahjong-utils-entry@^0.2.5:
version "0.2.5"
resolved "http://localhost:4873/mahjong-utils-entry/-/mahjong-utils-entry-0.2.5.tgz#3a87b2fad2c20902c6466bc9bd8449193131b682"
integrity sha512-VNBlqDhjQtl8dogIxviCM3HwhlRrUmqNI1mfPDXkwtn/D4r/YNGwlVHXpFaZCpSpV+FtZ8VQQmdUgGIo+1HYMw==
mahjong-utils-entry@^0.6.0:
version "0.6.0"
resolved "http://localhost:4873/mahjong-utils-entry/-/mahjong-utils-entry-0.6.0.tgz#29fe1a9e6191f10d181157a6e829953b7bb69b7f"
integrity sha512-V5u9mUkkc6C96PRR9FesxOrvN4DiUmWAywNy9JhBVh7gxW2HsRIVpNDw7767qdodId2/Y0cvNO6ktw2S4fmB0A==
dependencies:
format-util "^1.0.5"

mahjong-utils@^0.3.0:
version "0.3.0"
resolved "http://localhost:4873/mahjong-utils/-/mahjong-utils-0.3.0.tgz#501643a22c31cfb27d1dd1d70d2bc63d6f0256fe"
integrity sha512-tBKBz2rMiiTSJbkKfiwITB58S9gXkFKOgTfxum046hILBfeDnK1P+2uBK3Z3eG4G6YWyQLfgAqxycU5JVGKpKw==
mahjong-utils@^0.6.0:
version "0.6.0"
resolved "http://localhost:4873/mahjong-utils/-/mahjong-utils-0.6.0.tgz#ed0747754d68889865d5a09ccb1bda3677b9c0f9"
integrity sha512-IuIRErrCYRkNQhu7TiRGuNfzDZSVa43ScGsq+aNX+7MIk85rTBisNmIgEx9H63HEopcLmwgz5+6xRr5pCqelAA==
dependencies:
mahjong-utils-entry "^0.2.5"
mahjong-utils-entry "^0.6.0"

make-dir@^3.0.0, make-dir@^3.0.2, make-dir@^3.1.0:
version "3.1.0"
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"name": "ssttkkl",
"email": "[email protected]"
},
"version": "0.4.0",
"version": "0.5.2",
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"build": "rimraf ./dist && tsc",
"test": "jest",
"lint": "eslint src/**/*.ts --fix"
},
Expand All @@ -22,6 +22,7 @@
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-promise": "^6.0.0",
"jest": "^29.4.1",
"rimraf": "^5.0.1",
"ts-jest": "^29.0.5",
"ts-loader": "^9.4.2",
"typescript": "*"
Expand All @@ -30,6 +31,6 @@
"dist/**/*"
],
"dependencies": {
"mahjong-utils-entry": "^0.4.0"
"mahjong-utils-entry": "^0.5.2"
}
}
6 changes: 3 additions & 3 deletions src/coder/hora/hora.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { type AbstractHoraHandPattern, type Hora } from 'hora'
import { decodeHoraHandPattern } from './hora-hand-pattern'

export function decodeHora<T extends AbstractHoraHandPattern['type']>(
export function decodeHora<T extends AbstractHoraHandPattern['type']> (
raw: any,
patternType: T
): Hora<AbstractHoraHandPattern & { type: T }>

export function decodeHora(raw: any): Hora
export function decodeHora (raw: any): Hora

export function decodeHora(
export function decodeHora (
raw: any,
patternType?: AbstractHoraHandPattern['type']
): Hora {
Expand Down
69 changes: 57 additions & 12 deletions src/coder/shanten/shanten-info.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type Decoder, type Encoder } from '../../models/types'
import {
type Improvement,
type AbstractCommonShantenInfo,
type AbstractShantenInfo,
type ShantenWithFuroChance,
Expand All @@ -11,23 +12,67 @@ import { InvalidTypeException } from '../errors'
import { decodeTatsu, encodeTatsu } from '../models/tatsu'
import { decodeTile, encodeTile } from '../models/tile'

export const decodeImprovement: Decoder<Improvement> = (raw) => {
return {
discard: decodeTile(raw.discard),
advance: raw.advance.map(decodeTile),
advanceNum: raw.advanceNum
}
}

export const encodeImprovement: Encoder<Improvement> = (data) => {
return {
discard: encodeTile(data.discard),
advance: data.advance.map(encodeTile),
advanceNum: data.advanceNum
}
}

export const decodeShantenWithoutGot: Decoder<ShantenWithoutGot> = (raw) => {
return {
shantenNum: raw.shantenNum,
advance: raw.advance.map(decodeTile),
advanceNum: raw.advanceNum ?? undefined,
goodShapeAdvance: raw.goodShapeAdvance?.map(decodeTile),
goodShapeAdvanceNum: raw.goodShapeAdvanceNum ?? undefined
advanceNum: raw.advanceNum,
goodShapeAdvance: raw.goodShapeAdvance?.map(decodeTile) ?? null,
goodShapeAdvanceNum: raw.goodShapeAdvanceNum,
improvement: raw.improvement !== null
? objToMap(raw.improvement, {
keyMapper: decodeTile,
valueMapper: (rawImprovementArray) => rawImprovementArray.map(decodeImprovement)
})
: null,
improvementNum: raw.improvementNum,
goodShapeImprovement: raw.goodShapeImprovement !== null
? objToMap(raw.goodShapeImprovement, {
keyMapper: decodeTile,
valueMapper: (rawImprovementArray) => rawImprovementArray.map(decodeImprovement)
})
: null,
goodShapeImprovementNum: raw.goodShapeImprovementNum
}
}

export const encodeShantenWithoutGot: Encoder<ShantenWithoutGot> = (data) => {
return {
shantenNum: data.shantenNum,
advance: data.advance.map(encodeTile),
advanceNum: data.advanceNum ?? null,
goodShapeAdvance: data.goodShapeAdvance?.map(encodeTile) ?? null,
goodShapeAdvanceNum: data.goodShapeAdvanceNum ?? null
advanceNum: data.advanceNum,
goodShapeAdvance: data.goodShapeAdvance?.map(encodeTile),
goodShapeAdvanceNum: data.goodShapeAdvanceNum,
improvement: data.improvement !== null
? mapToObj(data.improvement, {
keyMapper: encodeTile,
valueMapper: (improvementArray) => improvementArray.map(encodeImprovement)
})
: null,
improvementNum: data.improvementNum,
goodShapeImprovement: data.goodShapeImprovement !== null
? mapToObj(data.goodShapeImprovement, {
keyMapper: encodeTile,
valueMapper: (improvementArray) => improvementArray.map(encodeImprovement)
})
: null,
goodShapeImprovementNum: data.goodShapeImprovementNum
}
}

Expand Down Expand Up @@ -94,20 +139,20 @@ export const encodeCommonShantenInfo: Encoder<AbstractCommonShantenInfo> = (data
export const decodeShantenWithFuroChance: Decoder<ShantenWithFuroChance> = (raw) => {
return {
shantenNum: raw.shantenNum,
pass: raw.pass !== null ? decodeShantenWithoutGot(raw.pass) : undefined,
pass: raw.pass !== null ? decodeShantenWithoutGot(raw.pass) : null,
chi: Object.entries(raw.chi).map(([key, value]) => [decodeTatsu(key), decodeShantenWithGot(value)]),
pon: raw.pon !== null ? decodeShantenWithGot(raw.pon) : undefined,
minkan: raw.minkan !== null ? decodeShantenWithoutGot(raw.minkan) : undefined
pon: raw.pon !== null ? decodeShantenWithGot(raw.pon) : null,
minkan: raw.minkan !== null ? decodeShantenWithoutGot(raw.minkan) : null
}
}

export const encodeShantenWithFuroChance: Encoder<ShantenWithFuroChance> = (data) => {
return {
shantenNum: data.shantenNum,
pass: data.pass !== undefined ? encodeShantenWithoutGot(data.pass) : null,
pass: data.pass !== null ? encodeShantenWithoutGot(data.pass) : null,
chi: Object.fromEntries(data.chi.map(([tatsu, shanten]) => [encodeTatsu(tatsu), encodeShantenWithGot(shanten)])),
pon: data.pon !== undefined ? encodeShantenWithGot(data.pon) : null,
minkan: data.minkan !== undefined ? encodeShantenWithoutGot(data.minkan) : null
pon: data.pon !== null ? encodeShantenWithGot(data.pon) : null,
minkan: data.minkan !== null ? encodeShantenWithoutGot(data.minkan) : null
}
}

Expand Down
1 change: 1 addition & 0 deletions src/entry.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-expect-error 无法找到模块“mahjong-utils-entry”的声明文件
import { mahjongutils } from 'mahjong-utils-entry'

export const { ENTRY } = mahjongutils
Expand Down
2 changes: 1 addition & 1 deletion src/hora/models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChildPoint, ParentPoint } from 'point-by-han-hu/models'
import { type ChildPoint, type ParentPoint } from 'point-by-han-hu/models'
import { type RegularHandPattern, type Tile, type Wind } from '../models'
import { type ExtraYaku, type Yaku } from './yaku'

Expand Down
16 changes: 8 additions & 8 deletions src/models/Tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export enum TileType {
Z
}

const _pool: Array<Tile | undefined> = []

export class Tile {
private constructor (readonly type: TileType, readonly num: number) {
}
Expand Down Expand Up @@ -49,27 +51,25 @@ export class Tile {
return `${this.num}${TileType[this.type]}`
}

private static readonly pool: Array<Tile | undefined> = []

static {
for (let i = 0; i <= 9; i++) {
Tile.pool.push(new Tile(TileType.M, i))
_pool.push(new Tile(TileType.M, i))
}
for (let i = 0; i <= 9; i++) {
Tile.pool.push(new Tile(TileType.P, i))
_pool.push(new Tile(TileType.P, i))
}
for (let i = 0; i <= 9; i++) {
Tile.pool.push(new Tile(TileType.S, i))
_pool.push(new Tile(TileType.S, i))
}
Tile.pool.push(undefined)
_pool.push(undefined)
for (let i = 1; i <= 7; i++) {
Tile.pool.push(new Tile(TileType.Z, i))
_pool.push(new Tile(TileType.Z, i))
}
}

static byTypeAndNum (type: TileType, num: number): Tile | undefined {
const code = type * 10 + num
const tile = Tile.pool[code]
const tile = _pool[code]
if (num < 0 || num > 9) {
return undefined
}
Expand Down
2 changes: 1 addition & 1 deletion src/point-by-han-hu/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENTRY, handleResult } from '../entry'
import { ChildPoint, ParentPoint } from './models'
import { type ChildPoint, type ParentPoint } from './models'

export function getParentPointByHanHu (han: number, hu: number): ParentPoint {
const result = ENTRY.call('getParentPointByHanHu', { han, hu })
Expand Down
12 changes: 6 additions & 6 deletions src/point-by-han-hu/models.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export interface ParentPoint {
ron: number
tsumo: number
ron: number
tsumo: number
}

export interface ChildPoint {
ron: number
tsumoParent: number
tsumoChild: number
}
ron: number
tsumoParent: number
tsumoChild: number
}
Loading

0 comments on commit 2fa69e7

Please sign in to comment.