Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

riichi-ts

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

riichi-ts - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

109

dist/agari.js

@@ -0,1 +1,2 @@

"use strict";
// Inspired by and partially taken from https://github.com/takayama-lily/agari

@@ -38,4 +39,6 @@ var __read = (this && this.__read) || function (o, n) {

};
import { digest, KOKUSHI_IDX, sliceBySuit, SUIT, sum, sumArr, VAL } from './interfaces';
export var check7 = function (haipai) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.findAllAgariPatterns = exports.calc = exports.findJanto = exports.findShuntsu = exports.findKotsu = exports.checkAll = exports.check = exports.check13 = exports.check7 = void 0;
var interfaces_1 = require("./interfaces");
var check7 = function (haipai) {
var s = 0;

@@ -50,10 +53,12 @@ for (var i = 0; i < haipai.length; i++) {

};
export var check13 = function (haipai) {
var arr = KOKUSHI_IDX.map(function (i) { return haipai[i]; });
return !arr.includes(0) && sumArr(arr) == 14;
exports.check7 = check7;
var check13 = function (haipai) {
var arr = interfaces_1.KOKUSHI_IDX.map(function (i) { return haipai[i]; });
return !arr.includes(0) && (0, interfaces_1.sumArr)(arr) == 14;
};
exports.check13 = check13;
var _check = function (haipai, isJihai) {
if (isJihai === void 0) { isJihai = false; }
haipai = haipai.slice(); // clone
var s = sum(haipai);
var s = (0, interfaces_1.sum)(haipai);
if (s === 0) {

@@ -103,7 +108,7 @@ return true;

};
export var check = function (haipai) {
var check = function (haipai) {
var j = 0;
for (var i = 0; i < 4; i++) {
// Summing by suit
var sliceSum = sum(haipai.slice(i * 9, (i + 1) * 9));
var sliceSum = (0, interfaces_1.sum)(haipai.slice(i * 9, (i + 1) * 9));
if (sliceSum % 3 === 1) {

@@ -114,16 +119,18 @@ return false;

}
var slices = sliceBySuit(haipai);
var slices = (0, interfaces_1.sliceBySuit)(haipai);
return (j === 1 &&
_check(slices[SUIT.HONOR], true) &&
_check(slices[SUIT.MAN]) &&
_check(slices[SUIT.PIN]) &&
_check(slices[SUIT.SOU]));
_check(slices[interfaces_1.SUIT.HONOR], true) &&
_check(slices[interfaces_1.SUIT.MAN]) &&
_check(slices[interfaces_1.SUIT.PIN]) &&
_check(slices[interfaces_1.SUIT.SOU]));
};
export var checkAll = function (haipai) {
return check7(haipai) || check13(haipai) || check(haipai);
exports.check = check;
var checkAll = function (haipai) {
return (0, exports.check7)(haipai) || (0, exports.check13)(haipai) || (0, exports.check)(haipai);
};
exports.checkAll = checkAll;
// Finds indices in hand where kotsu is detected
// Doesn't find kantsu.
// Mutates original array!
export var findKotsu = function (haipai) {
var findKotsu = function (haipai) {
var res = [];

@@ -133,3 +140,3 @@ for (var i = 0; i < haipai.length; i++) {

haipai[i] -= 3;
if (check(haipai)) {
if ((0, exports.check)(haipai)) {
res.push([i, i, i]);

@@ -144,5 +151,6 @@ }

};
exports.findKotsu = findKotsu;
// Finds arrays of indices in hand where shuntsu is detected
// Mutates original array!
export var findShuntsu = function (haipai) {
var findShuntsu = function (haipai) {
var res = [];

@@ -152,8 +160,8 @@ // Don't consider honors (last 7).

// Also skip last two suit tiles, because there can't be any shuntsu starting from 8 or 9.
if (i === SUIT.MAN * 9 + VAL.N8 ||
i === SUIT.MAN * 9 + VAL.N9 ||
i === SUIT.PIN * 9 + VAL.N8 ||
i === SUIT.PIN * 9 + VAL.N9 ||
i === SUIT.SOU * 9 + VAL.N8 ||
i === SUIT.SOU * 9 + VAL.N9) {
if (i === interfaces_1.SUIT.MAN * 9 + interfaces_1.VAL.N8 ||
i === interfaces_1.SUIT.MAN * 9 + interfaces_1.VAL.N9 ||
i === interfaces_1.SUIT.PIN * 9 + interfaces_1.VAL.N8 ||
i === interfaces_1.SUIT.PIN * 9 + interfaces_1.VAL.N9 ||
i === interfaces_1.SUIT.SOU * 9 + interfaces_1.VAL.N8 ||
i === interfaces_1.SUIT.SOU * 9 + interfaces_1.VAL.N9) {
continue;

@@ -165,3 +173,3 @@ }

haipai[i + 2]--;
if (check(haipai)) {
if ((0, exports.check)(haipai)) {
res.push([i, i + 1, i + 2]);

@@ -179,5 +187,6 @@ }

};
exports.findShuntsu = findShuntsu;
// Finds index of first set of repeated tiles or -1 otherwise
// Skip excluded index - it's used below as fake pair
export var findJanto = function (haipai, exclude) {
var findJanto = function (haipai, exclude) {
if (exclude === void 0) { exclude = -1; }

@@ -191,5 +200,6 @@ for (var i = 0; i < haipai.length; i++) {

};
exports.findJanto = findJanto;
// Find hand split variant
// Skip excluded index - it's used below as fake pair
export var calc = function (haipai, exclude, realPair) {
var calc = function (haipai, exclude, realPair) {
if (exclude === void 0) { exclude = -1; }

@@ -200,11 +210,11 @@ if (realPair === void 0) { realPair = -1; }

var clone = haipai.slice();
var kotsu = findKotsu(clone);
if (sum(clone) === 2) {
var kotsu = (0, exports.findKotsu)(clone);
if ((0, interfaces_1.sum)(clone) === 2) {
// toitoi-like
var janto = realPair !== -1 ? realPair : findJanto(clone, exclude);
var janto = realPair !== -1 ? realPair : (0, exports.findJanto)(clone, exclude);
res.push(__spreadArray(__spreadArray([], __read(kotsu), false), [[janto, janto]], false));
}
else if (kotsu.length > 0) {
var shuntsu_1 = findShuntsu(clone);
var janto = realPair !== -1 ? realPair : findJanto(clone, exclude);
var shuntsu_1 = (0, exports.findShuntsu)(clone);
var janto = realPair !== -1 ? realPair : (0, exports.findJanto)(clone, exclude);
res.push(__spreadArray(__spreadArray(__spreadArray([], __read(kotsu), false), __read(shuntsu_1), false), [[janto, janto]], false));

@@ -214,5 +224,5 @@ }

clone = haipai.slice();
var shuntsu = findShuntsu(clone);
if (sum(clone) === 2) {
var janto = realPair !== -1 ? realPair : findJanto(clone, exclude);
var shuntsu = (0, exports.findShuntsu)(clone);
if ((0, interfaces_1.sum)(clone) === 2) {
var janto = realPair !== -1 ? realPair : (0, exports.findJanto)(clone, exclude);
// pinfu-like

@@ -222,4 +232,4 @@ res.push(__spreadArray(__spreadArray([], __read(shuntsu), false), [[janto, janto]], false));

else {
var kotsu_1 = findKotsu(clone);
var janto = realPair !== -1 ? realPair : findJanto(clone, exclude);
var kotsu_1 = (0, exports.findKotsu)(clone);
var janto = realPair !== -1 ? realPair : (0, exports.findJanto)(clone, exclude);
res.push(__spreadArray(__spreadArray(__spreadArray([], __read(shuntsu), false), __read(kotsu_1), false), [[janto, janto]], false));

@@ -229,9 +239,10 @@ }

};
export var findAllAgariPatterns = function (haipai) {
exports.calc = calc;
var findAllAgariPatterns = function (haipai) {
var e_1, _a, e_2, _b;
var res = [];
haipai = haipai.slice(); // clone
var canBeKokushi = check13(haipai);
var canBeChiitoitsu = check7(haipai);
var canBeBasicForm = check(haipai);
var canBeKokushi = (0, exports.check13)(haipai);
var canBeChiitoitsu = (0, exports.check7)(haipai);
var canBeBasicForm = (0, exports.check)(haipai);
if (!canBeKokushi && !canBeChiitoitsu && !canBeBasicForm) {

@@ -241,4 +252,4 @@ return res;

// only a pair left in closed part -> try to detect and return it
if (sum(haipai) === 2) {
var found = findJanto(haipai);
if ((0, interfaces_1.sum)(haipai) === 2) {
var found = (0, exports.findJanto)(haipai);
if (found !== -1) {

@@ -265,3 +276,3 @@ res.push([[found, found]]);

var fakePairIndex = -1;
for (var i = SUIT.HONOR * 9; i < 34; i++) {
for (var i = interfaces_1.SUIT.HONOR * 9; i < 34; i++) {
if (haipai[i] === 0) {

@@ -284,4 +295,4 @@ // found first honor tile that is absent in hand

haipai[i] -= 2;
if (check(haipai)) {
res = res.concat(calc(haipai, fakePairIndex, i));
if ((0, exports.check)(haipai)) {
res = res.concat((0, exports.calc)(haipai, fakePairIndex, i));
}

@@ -306,7 +317,7 @@ haipai[i] += 2;

var is_duplicate = false;
var vDigest = digest(v);
var vDigest = (0, interfaces_1.digest)(v);
try {
for (var finalRes_1 = (e_2 = void 0, __values(finalRes)), finalRes_1_1 = finalRes_1.next(); !finalRes_1_1.done; finalRes_1_1 = finalRes_1.next()) {
var vv = finalRes_1_1.value;
if (vDigest === digest(vv)) {
if (vDigest === (0, interfaces_1.digest)(vv)) {
is_duplicate = true;

@@ -337,2 +348,2 @@ }

};
//# sourceMappingURL=../agari.js.map
exports.findAllAgariPatterns = findAllAgariPatterns;

@@ -1,2 +0,5 @@

export { Riichi } from './riichi';
//# sourceMappingURL=../index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Riichi = void 0;
var riichi_1 = require("./riichi");
Object.defineProperty(exports, "Riichi", { enumerable: true, get: function () { return riichi_1.Riichi; } });

@@ -0,4 +1,7 @@

"use strict";
// Hand structure is represented by plain 34-element Int8Array
// Here are some useful methods for calculation or the index in hand array.
export var SUIT = {
Object.defineProperty(exports, "__esModule", { value: true });
exports.digestAll = exports.digest = exports.isProperOpenSet = exports.is19 = exports.ceil100 = exports.ceil10 = exports.sumSuit = exports.joinFromSuits = exports.sliceBySuit = exports.sumArr = exports.sum = exports.idx = exports.KOKUSHI_IDX = exports.TILES = exports.RET = exports.VAL = exports.SUIT = void 0;
exports.SUIT = {
MAN: 0,

@@ -9,3 +12,3 @@ PIN: 1,

};
export var VAL = {
exports.VAL = {
TON: 0,

@@ -28,3 +31,3 @@ NAN: 1,

};
export var RET = {
exports.RET = {
OK: -1,

@@ -34,63 +37,67 @@ FAIL: -2,

};
export var TILES = {
m1: SUIT.MAN * 9 + VAL.N1,
m2: SUIT.MAN * 9 + VAL.N2,
m3: SUIT.MAN * 9 + VAL.N3,
m4: SUIT.MAN * 9 + VAL.N4,
m5: SUIT.MAN * 9 + VAL.N5,
m6: SUIT.MAN * 9 + VAL.N6,
m7: SUIT.MAN * 9 + VAL.N7,
m8: SUIT.MAN * 9 + VAL.N8,
m9: SUIT.MAN * 9 + VAL.N9,
p1: SUIT.PIN * 9 + VAL.N1,
p2: SUIT.PIN * 9 + VAL.N2,
p3: SUIT.PIN * 9 + VAL.N3,
p4: SUIT.PIN * 9 + VAL.N4,
p5: SUIT.PIN * 9 + VAL.N5,
p6: SUIT.PIN * 9 + VAL.N6,
p7: SUIT.PIN * 9 + VAL.N7,
p8: SUIT.PIN * 9 + VAL.N8,
p9: SUIT.PIN * 9 + VAL.N9,
s1: SUIT.SOU * 9 + VAL.N1,
s2: SUIT.SOU * 9 + VAL.N2,
s3: SUIT.SOU * 9 + VAL.N3,
s4: SUIT.SOU * 9 + VAL.N4,
s5: SUIT.SOU * 9 + VAL.N5,
s6: SUIT.SOU * 9 + VAL.N6,
s7: SUIT.SOU * 9 + VAL.N7,
s8: SUIT.SOU * 9 + VAL.N8,
s9: SUIT.SOU * 9 + VAL.N9,
e: SUIT.HONOR * 9 + VAL.TON,
s: SUIT.HONOR * 9 + VAL.NAN,
w: SUIT.HONOR * 9 + VAL.SHA,
n: SUIT.HONOR * 9 + VAL.PEI,
wd: SUIT.HONOR * 9 + VAL.HAKU,
gd: SUIT.HONOR * 9 + VAL.HATSU,
rd: SUIT.HONOR * 9 + VAL.CHUN,
exports.TILES = {
m1: exports.SUIT.MAN * 9 + exports.VAL.N1,
m2: exports.SUIT.MAN * 9 + exports.VAL.N2,
m3: exports.SUIT.MAN * 9 + exports.VAL.N3,
m4: exports.SUIT.MAN * 9 + exports.VAL.N4,
m5: exports.SUIT.MAN * 9 + exports.VAL.N5,
m6: exports.SUIT.MAN * 9 + exports.VAL.N6,
m7: exports.SUIT.MAN * 9 + exports.VAL.N7,
m8: exports.SUIT.MAN * 9 + exports.VAL.N8,
m9: exports.SUIT.MAN * 9 + exports.VAL.N9,
p1: exports.SUIT.PIN * 9 + exports.VAL.N1,
p2: exports.SUIT.PIN * 9 + exports.VAL.N2,
p3: exports.SUIT.PIN * 9 + exports.VAL.N3,
p4: exports.SUIT.PIN * 9 + exports.VAL.N4,
p5: exports.SUIT.PIN * 9 + exports.VAL.N5,
p6: exports.SUIT.PIN * 9 + exports.VAL.N6,
p7: exports.SUIT.PIN * 9 + exports.VAL.N7,
p8: exports.SUIT.PIN * 9 + exports.VAL.N8,
p9: exports.SUIT.PIN * 9 + exports.VAL.N9,
s1: exports.SUIT.SOU * 9 + exports.VAL.N1,
s2: exports.SUIT.SOU * 9 + exports.VAL.N2,
s3: exports.SUIT.SOU * 9 + exports.VAL.N3,
s4: exports.SUIT.SOU * 9 + exports.VAL.N4,
s5: exports.SUIT.SOU * 9 + exports.VAL.N5,
s6: exports.SUIT.SOU * 9 + exports.VAL.N6,
s7: exports.SUIT.SOU * 9 + exports.VAL.N7,
s8: exports.SUIT.SOU * 9 + exports.VAL.N8,
s9: exports.SUIT.SOU * 9 + exports.VAL.N9,
e: exports.SUIT.HONOR * 9 + exports.VAL.TON,
s: exports.SUIT.HONOR * 9 + exports.VAL.NAN,
w: exports.SUIT.HONOR * 9 + exports.VAL.SHA,
n: exports.SUIT.HONOR * 9 + exports.VAL.PEI,
wd: exports.SUIT.HONOR * 9 + exports.VAL.HAKU,
gd: exports.SUIT.HONOR * 9 + exports.VAL.HATSU,
rd: exports.SUIT.HONOR * 9 + exports.VAL.CHUN,
};
export var KOKUSHI_IDX = [
TILES.m1,
TILES.m9,
TILES.p1,
TILES.p9,
TILES.s1,
TILES.s9,
TILES.e,
TILES.s,
TILES.w,
TILES.n,
TILES.wd,
TILES.gd,
TILES.rd,
exports.KOKUSHI_IDX = [
exports.TILES.m1,
exports.TILES.m9,
exports.TILES.p1,
exports.TILES.p9,
exports.TILES.s1,
exports.TILES.s9,
exports.TILES.e,
exports.TILES.s,
exports.TILES.w,
exports.TILES.n,
exports.TILES.wd,
exports.TILES.gd,
exports.TILES.rd,
];
export var idx = function (suit, val) { return suit * 9 + val; };
export var sum = function (haipai) { return haipai.reduce(function (acc, v) { return acc + v; }, 0); };
export var sumArr = function (haipai) { return haipai.reduce(function (acc, v) { return acc + v; }, 0); };
export var sliceBySuit = function (haipai) { return [
haipai.slice(SUIT.MAN * 9, SUIT.MAN * 9 + 9),
haipai.slice(SUIT.PIN * 9, SUIT.PIN * 9 + 9),
haipai.slice(SUIT.SOU * 9, SUIT.SOU * 9 + 9),
haipai.slice(SUIT.HONOR * 9, SUIT.HONOR * 9 + 7),
var idx = function (suit, val) { return suit * 9 + val; };
exports.idx = idx;
var sum = function (haipai) { return haipai.reduce(function (acc, v) { return acc + v; }, 0); };
exports.sum = sum;
var sumArr = function (haipai) { return haipai.reduce(function (acc, v) { return acc + v; }, 0); };
exports.sumArr = sumArr;
var sliceBySuit = function (haipai) { return [
haipai.slice(exports.SUIT.MAN * 9, exports.SUIT.MAN * 9 + 9),
haipai.slice(exports.SUIT.PIN * 9, exports.SUIT.PIN * 9 + 9),
haipai.slice(exports.SUIT.SOU * 9, exports.SUIT.SOU * 9 + 9),
haipai.slice(exports.SUIT.HONOR * 9, exports.SUIT.HONOR * 9 + 7),
]; };
export var joinFromSuits = function (suits) {
exports.sliceBySuit = sliceBySuit;
var joinFromSuits = function (suits) {
return suits.reduce(function (acc, v) {

@@ -101,5 +108,6 @@ acc.set(v, acc.length);

};
export var sumSuit = function (haipai, suit) {
var lim = suit === SUIT.HONOR ? 7 : 9;
var start = idx(suit, 0);
exports.joinFromSuits = joinFromSuits;
var sumSuit = function (haipai, suit) {
var lim = suit === exports.SUIT.HONOR ? 7 : 9;
var start = (0, exports.idx)(suit, 0);
var sum = 0;

@@ -111,12 +119,16 @@ for (var i = 0; i < lim; i++) {

};
export var ceil10 = function (num) {
exports.sumSuit = sumSuit;
var ceil10 = function (num) {
return Math.ceil(num / 10) * 10;
};
export var ceil100 = function (num) {
exports.ceil10 = ceil10;
var ceil100 = function (num) {
return Math.ceil(num / 100) * 100;
};
export var is19 = function (idx) {
return KOKUSHI_IDX.includes(idx);
exports.ceil100 = ceil100;
var is19 = function (idx) {
return exports.KOKUSHI_IDX.includes(idx);
};
export var isProperOpenSet = function (arr) {
exports.is19 = is19;
var isProperOpenSet = function (arr) {
if (arr.length > 4 || arr.length < 2) {

@@ -141,4 +153,5 @@ return false;

};
exports.isProperOpenSet = isProperOpenSet;
// Create stable digest of a decomposition to use in deduplication code
export var digest = function (decomposition) {
var digest = function (decomposition) {
return decomposition

@@ -149,5 +162,6 @@ .map(function (set) { return '|' + set.join(',') + '|'; })

};
export var digestAll = function (decompositions) {
return decompositions.map(function (dec) { return digest(dec); }).join('$');
exports.digest = digest;
var digestAll = function (decompositions) {
return decompositions.map(function (dec) { return (0, exports.digest)(dec); }).join('$');
};
//# sourceMappingURL=../interfaces.js.map
exports.digestAll = digestAll;

@@ -0,1 +1,2 @@

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -73,9 +74,14 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
import yauzl from 'yauzl-promise';
import { Parser } from 'htmlparser2';
export var readZipFile = function (path, skip, cb) { return __awaiter(void 0, void 0, void 0, function () {
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.prepareTestData = exports.readZipFile = void 0;
var yauzl_promise_1 = __importDefault(require("yauzl-promise"));
var htmlparser2_1 = require("htmlparser2");
var readZipFile = function (path, skip, cb) { return __awaiter(void 0, void 0, void 0, function () {
var zip, entry, counter, _loop_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, yauzl.open(path)];
case 0: return [4 /*yield*/, yauzl_promise_1.default.open(path)];
case 1:

@@ -110,2 +116,3 @@ zip = _a.sent();

}); };
exports.readZipFile = readZipFile;
var yaku = [

@@ -266,3 +273,3 @@ 'menzentsumo',

};
export var prepareTestData = function (content) {
var prepareTestData = function (content) {
var tags = Array.from(content.matchAll(/<(AGARI|UN|INIT|RYUUKYOKU|GO)(.*?)\/>/g)).map(function (tag) {

@@ -282,3 +289,3 @@ return tag[0].replace(/owari=.*?owari=/, 'owari=');

var hasChips = false;
var parser = new Parser({
var parser = new htmlparser2_1.Parser({
onopentag: function (name, attribs) {

@@ -441,2 +448,2 @@ var e_4, _a, e_5, _b;

};
//# sourceMappingURL=../../logs/helpers.js.map
exports.prepareTestData = prepareTestData;

@@ -0,1 +1,2 @@

"use strict";
var __assign = (this && this.__assign) || function () {

@@ -48,6 +49,8 @@ __assign = Object.assign || function(t) {

};
import { checkAll, findAllAgariPatterns } from './agari';
import { hairi } from './shanten';
import { YAKU } from './yaku';
import { ceil10, ceil100, is19, isProperOpenSet } from './interfaces';
Object.defineProperty(exports, "__esModule", { value: true });
exports.Riichi = void 0;
var agari_1 = require("./agari");
var shanten_1 = require("./shanten");
var yaku_1 = require("./yaku");
var interfaces_1 = require("./interfaces");
var sortByInt = function (a1, a2) { return a1 - a2; };

@@ -126,3 +129,3 @@ var Riichi = /** @class */ (function () {

var _loop_1 = function (vv) {
if (isProperOpenSet(vv.tiles)) {
if ((0, interfaces_1.isProperOpenSet)(vv.tiles)) {
this_1.furo.push(__spreadArray([], __read(vv.tiles.map(function (v) { return (vv.open ? v : -v); })), false).sort(sortByInt));

@@ -320,8 +323,8 @@ }

if (this.isTsumo) {
oya = ceil100(base * 2) + ceil100(base * 2) + ceil100(base * 2);
ko = ceil100(base * 2) + ceil100(base) + ceil100(base);
oya = (0, interfaces_1.ceil100)(base * 2) + (0, interfaces_1.ceil100)(base * 2) + (0, interfaces_1.ceil100)(base * 2);
ko = (0, interfaces_1.ceil100)(base * 2) + (0, interfaces_1.ceil100)(base) + (0, interfaces_1.ceil100)(base);
}
else {
oya = ceil100(base * 6);
ko = ceil100(base * 4);
oya = (0, interfaces_1.ceil100)(base * 6);
ko = (0, interfaces_1.ceil100)(base * 4);
}

@@ -374,8 +377,8 @@ this.tmpResult.ten = this.jikaze === 27 ? oya : ko;

else {
if ((v[0] === this.takenTile && !is19(v[2])) ||
(v[2] === this.takenTile && !is19(v[0]))) {
if ((v[0] === this.takenTile && !(0, interfaces_1.is19)(v[2])) ||
(v[2] === this.takenTile && !(0, interfaces_1.is19)(v[0]))) {
canBeRyanmen = true;
}
if ((v[0] === this.takenTile && is19(v[2])) ||
(v[2] === this.takenTile && is19(v[0]))) {
if ((v[0] === this.takenTile && (0, interfaces_1.is19)(v[2])) ||
(v[2] === this.takenTile && (0, interfaces_1.is19)(v[0]))) {
canBePenchan = true;

@@ -402,6 +405,6 @@ }

// hack: count infinity sign to support closed kan of 1m
fu += is19(Math.abs(v[0])) ? (1 / v[0] > 0 ? 16 : 32) : 1 / v[0] > 0 ? 8 : 16;
fu += (0, interfaces_1.is19)(Math.abs(v[0])) ? (1 / v[0] > 0 ? 16 : 32) : 1 / v[0] > 0 ? 8 : 16;
}
else if (v.length === 3 && v[0] === v[1]) {
fu += is19(v[0]) ? 4 : 2;
fu += (0, interfaces_1.is19)(v[0]) ? 4 : 2;
}

@@ -436,10 +439,10 @@ }

if (canBeRyanmen || canBeKanchan || canBePenchan) {
fu += is19(v[0]) ? 8 : 4;
fu += (0, interfaces_1.is19)(v[0]) ? 8 : 4;
}
else {
fu += is19(v[0]) ? 4 : 2;
fu += (0, interfaces_1.is19)(v[0]) ? 4 : 2;
}
}
else {
fu += is19(v[0]) ? 8 : 4;
fu += (0, interfaces_1.is19)(v[0]) ? 8 : 4;
}

@@ -467,3 +470,3 @@ }

}
fu = ceil10(fu);
fu = (0, interfaces_1.ceil10)(fu);
if (fu < 30) {

@@ -479,4 +482,4 @@ fu = 30;

this.tmpResult.han = 0;
for (var k in YAKU) {
var v = YAKU[k];
for (var k in yaku_1.YAKU) {
var v = yaku_1.YAKU[k];
if (this.disabled.includes(k)) {

@@ -547,7 +550,7 @@ continue;

}
this.tmpResult.isAgari = checkAll(this.haipai);
this.tmpResult.isAgari = (0, agari_1.checkAll)(this.haipai);
if (!this.tmpResult.isAgari || this.hai.length + this.furo.length * 3 !== 14) {
if (this.hairi) {
this.tmpResult.hairi = hairi(this.haipai);
this.tmpResult.hairi7and13 = hairi(this.haipai, true);
this.tmpResult.hairi = (0, shanten_1.hairi)(this.haipai);
this.tmpResult.hairi7and13 = (0, shanten_1.hairi)(this.haipai, true);
}

@@ -560,3 +563,3 @@ return this.tmpResult;

this.finalResult.isAgari = true;
this.agariPatterns = findAllAgariPatterns(this.haipai);
this.agariPatterns = (0, agari_1.findAllAgariPatterns)(this.haipai);
try {

@@ -600,3 +603,2 @@ for (var _j = __values(this.agariPatterns), _k = _j.next(); !_k.done; _k = _j.next()) {

}());
export { Riichi };
//# sourceMappingURL=../riichi.js.map
exports.Riichi = Riichi;

@@ -0,1 +1,2 @@

"use strict";
// Inspired by and partially taken from https://github.com/takayama-lily/syanten

@@ -13,8 +14,10 @@ var __values = (this && this.__values) || function(o) {

};
import { KOKUSHI_IDX, RET, sum } from './interfaces';
export var shanten13 = function (haipai) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.hairi = exports.shanten = exports.shanten7 = exports.shanten13 = void 0;
var interfaces_1 = require("./interfaces");
var shanten13 = function (haipai) {
var e_1, _a;
var cnt = sum(haipai);
var cnt = (0, interfaces_1.sum)(haipai);
if (cnt < 13 || cnt > 14) {
return RET.WRONG_COUNT;
return interfaces_1.RET.WRONG_COUNT;
}

@@ -24,3 +27,3 @@ var singles = 0;

try {
for (var KOKUSHI_IDX_1 = __values(KOKUSHI_IDX), KOKUSHI_IDX_1_1 = KOKUSHI_IDX_1.next(); !KOKUSHI_IDX_1_1.done; KOKUSHI_IDX_1_1 = KOKUSHI_IDX_1.next()) {
for (var KOKUSHI_IDX_1 = __values(interfaces_1.KOKUSHI_IDX), KOKUSHI_IDX_1_1 = KOKUSHI_IDX_1.next(); !KOKUSHI_IDX_1_1.done; KOKUSHI_IDX_1_1 = KOKUSHI_IDX_1.next()) {
var i = KOKUSHI_IDX_1_1.value;

@@ -44,6 +47,7 @@ if (haipai[i] >= 1) {

};
export var shanten7 = function (haipai) {
var cnt = sum(haipai);
exports.shanten13 = shanten13;
var shanten7 = function (haipai) {
var cnt = (0, interfaces_1.sum)(haipai);
if (cnt < 13 || cnt > 14) {
return RET.WRONG_COUNT;
return interfaces_1.RET.WRONG_COUNT;
}

@@ -65,2 +69,3 @@ var pairs = 0;

};
exports.shanten7 = shanten7;
var searchHelper = function (handPart, index, isJihai, mentsu, tatsu, singles) {

@@ -139,3 +144,3 @@ if (isJihai === void 0) { isJihai = false; }

};
export var shanten = function (haipai) {
var shanten = function (haipai) {
var res = 9;

@@ -182,5 +187,5 @@ var mentsu = 0;

};
var s = sum(haipai);
var s = (0, interfaces_1.sum)(haipai);
if (s > 14 || s % 3 === 0) {
return RET.WRONG_COUNT;
return interfaces_1.RET.WRONG_COUNT;
}

@@ -211,7 +216,8 @@ furo = Math.round((14 - s) / 3);

};
export var hairi = function (haipai, is7or13) {
exports.shanten = shanten;
var hairi = function (haipai, is7or13) {
if (is7or13 === void 0) { is7or13 = false; }
var shantenCalc = !is7or13
? shanten
: function (haiArr) { return Math.min(shanten7(haiArr), shanten13(haiArr)); };
? exports.shanten
: function (haiArr) { return Math.min((0, exports.shanten7)(haiArr), (0, exports.shanten13)(haiArr)); };
var sht = shantenCalc(haipai);

@@ -221,3 +227,3 @@ var res = {

};
if (sht === RET.WRONG_COUNT) {
if (sht === interfaces_1.RET.WRONG_COUNT) {
return res;

@@ -252,3 +258,3 @@ }

// 13-tile hand: calculate hairi once and return waits
if (sum(haipai) % 3 === 1) {
if ((0, interfaces_1.sum)(haipai) % 3 === 1) {
res.wait = calcHairi();

@@ -271,2 +277,2 @@ return res;

};
//# sourceMappingURL=../shanten.js.map
exports.hairi = hairi;

@@ -0,1 +1,2 @@

"use strict";
var __values = (this && this.__values) || function(o) {

@@ -12,5 +13,10 @@ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;

};
import assert from 'assert';
import { check13, check7 } from './agari';
import { digest, is19, sliceBySuit, sum } from './interfaces';
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.YAKU = void 0;
var assert_1 = __importDefault(require("assert"));
var agari_1 = require("./agari");
var interfaces_1 = require("./interfaces");
var checkAllowed = function (o, allowed) {

@@ -91,5 +97,5 @@ var e_1, _a, e_2, _b, e_3, _c;

var foundSuit = -1;
var slices = sliceBySuit(toHand((_a = o.currentPattern) !== null && _a !== void 0 ? _a : []));
var slices = (0, interfaces_1.sliceBySuit)(toHand((_a = o.currentPattern) !== null && _a !== void 0 ? _a : []));
for (var i in slices) {
if (sum(slices[i]) === 0) {
if ((0, interfaces_1.sum)(slices[i]) === 0) {
continue;

@@ -128,3 +134,3 @@ }

hasJyuntsu = true;
if (!is19(v[0]) && !is19(v[2])) {
if (!(0, interfaces_1.is19)(v[0]) && !(0, interfaces_1.is19)(v[2])) {
return false;

@@ -167,3 +173,3 @@ }

};
export var YAKU = {
exports.YAKU = {
'kokushimusou 13 sides': {

@@ -176,3 +182,3 @@ isLocal: false,

check: function (o) {
return (check13(o.haipai) &&
return ((0, agari_1.check13)(o.haipai) &&
o.hai.reduce(function (total, v) { return (v === o.takenTile ? ++total : total); }, 0) === 2);

@@ -188,3 +194,3 @@ },

check: function (o) {
return (check13(o.haipai) &&
return ((0, agari_1.check13)(o.haipai) &&
o.hai.reduce(function (total, v) { return (v === o.takenTile ? ++total : total); }, 0) === 1);

@@ -200,3 +206,3 @@ },

check: function (o) {
var slices = sliceBySuit(o.haipai);
var slices = (0, interfaces_1.sliceBySuit)(o.haipai);
var foundSuit = getSameSuit(o);

@@ -219,3 +225,3 @@ if (foundSuit === -1 ||

check: function (o) {
var slices = sliceBySuit(o.haipai);
var slices = (0, interfaces_1.sliceBySuit)(o.haipai);
var foundSuit = getSameSuit(o);

@@ -301,3 +307,3 @@ if (foundSuit === -1 ||

}
return kotsu === 4 && o.isTsumo && !YAKU['suuankou tanki'].check(o);
return kotsu === 4 && o.isTsumo && !exports.YAKU['suuankou tanki'].check(o);
},

@@ -485,3 +491,3 @@ },

check: function (o) {
return checkAllowed(o, [27, 28, 29, 30, 31, 32, 33]) && YAKU.chiitoitsu.check(o);
return checkAllowed(o, [27, 28, 29, 30, 31, 32, 33]) && exports.YAKU.chiitoitsu.check(o);
},

@@ -504,3 +510,3 @@ },

check: function (o) {
return getSameSuit(o, true) !== -1 && !YAKU.chinitsu.check(o);
return getSameSuit(o, true) !== -1 && !exports.YAKU.chinitsu.check(o);
},

@@ -528,7 +534,7 @@ },

if (v.length === 3) {
if (arr[digest([v])]) {
arr[digest([v])]++;
if (arr[(0, interfaces_1.digest)([v])]) {
arr[(0, interfaces_1.digest)([v])]++;
}
else {
arr[digest([v])] = 1;
arr[(0, interfaces_1.digest)([v])] = 1;
}

@@ -563,3 +569,3 @@ }

check: function (o) {
return checkChanta(o, [0, 8, 9, 17, 18, 26, 27, 28, 29, 30, 31, 32, 33]) && !YAKU.junchan.check(o);
return checkChanta(o, [0, 8, 9, 17, 18, 26, 27, 28, 29, 30, 31, 32, 33]) && !exports.YAKU.junchan.check(o);
},

@@ -657,3 +663,3 @@ },

}
return kotsuOrToitsu === 3 && !YAKU.daisangen.check(o) && !YAKU.chiitoitsu.check(o);
return kotsuOrToitsu === 3 && !exports.YAKU.daisangen.check(o) && !exports.YAKU.chiitoitsu.check(o);
},

@@ -725,3 +731,3 @@ },

}
var closedPart = (_c = o.currentPattern) === null || _c === void 0 ? void 0 : _c.filter(function (set) { return o.furo.find(function (meld) { return digest([set]) === digest([meld]); }) === undefined; });
var closedPart = (_c = o.currentPattern) === null || _c === void 0 ? void 0 : _c.filter(function (set) { return o.furo.find(function (meld) { return (0, interfaces_1.digest)([set]) === (0, interfaces_1.digest)([meld]); }) === undefined; });
var _loop_1 = function (v) {

@@ -767,3 +773,3 @@ if (openKotsu.has(v[0]) ||

check: function (o) {
return check7(o.haipai) && !YAKU.ryanpeikou.check(o);
return (0, agari_1.check7)(o.haipai) && !exports.YAKU.ryanpeikou.check(o);
},

@@ -884,3 +890,3 @@ },

if (v.length === 4) {
fu += is19(Math.abs(v[0])) ? (v[0] > 0 ? 16 : 32) : v[0] > 0 ? 8 : 16;
fu += (0, interfaces_1.is19)(Math.abs(v[0])) ? (v[0] > 0 ? 16 : 32) : v[0] > 0 ? 8 : 16;
}

@@ -898,3 +904,3 @@ else if (v.length === 2) {

if (v[0] === v[1]) {
fu += is19(v[0]) ? 4 : 2;
fu += (0, interfaces_1.is19)(v[0]) ? 4 : 2;
}

@@ -929,3 +935,3 @@ }

}
if ((v[0] === o.takenTile && !is19(v[2])) || (v[2] === o.takenTile && !is19(v[0]))) {
if ((v[0] === o.takenTile && !(0, interfaces_1.is19)(v[2])) || (v[2] === o.takenTile && !(0, interfaces_1.is19)(v[0]))) {
canBeRyanmen = true;

@@ -959,3 +965,3 @@ }

check: function (o) {
if (YAKU.ryanpeikou.check(o))
if (exports.YAKU.ryanpeikou.check(o))
return false;

@@ -969,3 +975,3 @@ for (var idx in o.currentPattern) {

try {
assert.deepStrictEqual(v, o.currentPattern[i]);
assert_1.default.deepStrictEqual(v, o.currentPattern[i]);
return true;

@@ -994,3 +1000,3 @@ }

isFuroMinus: false,
check: function (o) { return o.extra.riichi && !YAKU['daburu riichi'].check(o); },
check: function (o) { return o.extra.riichi && !exports.YAKU['daburu riichi'].check(o); },
},

@@ -1146,2 +1152,1 @@ ippatsu: {

};
//# sourceMappingURL=../yaku.js.map
{
"name": "riichi-ts",
"version": "1.0.2",
"version": "1.0.3",
"description": "Riichi mahjong calculations library",

@@ -5,0 +5,0 @@ "type": "module",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc