# syanten

> Japanese riichi mahjong hand shanten calculation

Latest version **1.6.0** (published 2023-03-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install syanten
pnpm add syanten
yarn add syanten
bun add syanten
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.6.0 |
| Published | 2023-03-22 |
| First published | 2019-10-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 58.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | takayama |
| Maintainers | takayama |
| Keywords | riichi, mahjong, syanten, shanten, agari |

## Links

- npm: https://www.npmjs.com/package/syanten
- Repository: https://github.com/takayama-lily/syanten
- Homepage: https://github.com/takayama-lily/syanten#readme
- Issues: https://github.com/takayama-lily/syanten/issues
- npm.io page: https://npm.io/package/syanten

## Recent versions

- 1.6.0 (latest) — 2023-03-22
- 1.5.0 — 2021-01-01
- 1.4.0 — 2020-05-30
- 1.3.2 — 2020-05-15
- 1.3.1 — 2020-05-15
- 1.3.0 — 2020-05-14
- 1.2.5 — 2020-04-08
- 1.2.4 — 2020-04-06
- 1.2.3 — 2020-04-06
- 1.2.2 — 2020-04-03
- 1.2.1 — 2020-03-25
- 1.2.0 — 2020-03-19
- 1.1.0 — 2019-10-28
- 1.0.0 — 2019-10-27

## README

# **syanten**

麻雀シャンテン向聴数牌理計算  
Japanese riichi mahjong hand shanten calculation

**Install with npm:**

```shell
# npm i syanten
```

**Use in browser:**

```html
<script src="https://cdn.jsdelivr.net/npm/syanten"></script>
```

**Example:**

```js
const syanten = require('syanten')
let hai = [
    [4, 1, 1, 1, 1, 1, 1, 1, 3], //萬子
    [0, 0, 0, 0, 0, 0, 0, 0, 0], //筒子
    [0, 0, 0, 0, 0, 0, 0, 0, 0], //索子
    [0, 0, 0, 0, 0, 0, 0]        //字牌
]
console.log(syanten.syanten(hai))     //一般形
console.log(syanten.syanten7(hai))    //七対子形
console.log(syanten.syanten13(hai))   //国士形
console.log(syanten(hai))             //全部形最小値

//手牌可能枚数: 14,13, 11,10, 8,7, 5,4, 2,1
```

**Output:**

```text
-2  牌数不正
-1  和了形
0   聴牌形
1~  向聴数
```

## 一般型牌理計算

```js
const syanten = require('syanten')
let hai = [
    [3, 3, 3, 0, 0, 0, 0, 0, 0],
    [2, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0],
    [1, 1, 1, 0, 0, 0, 0]
]
console.log(syanten.hairi(hai))
```

**Output:**

```js
//手牌14,11,8,5,2枚の場合
{
  now: 1, //現在向聴数
  '1m': {},
  '2m': {},
  '3m': {},
  '1p': {},
  '1z': { '1p': 2, '2z': 3, '3z': 3 }, //打1z 待1p二枚 2z三枚 3z三枚
  '2z': { '1p': 2, '1z': 3, '3z': 3 }, //打2z 待1p二枚 1z三枚 3z三枚
  '3z': { '1p': 2, '1z': 3, '2z': 3 }  //打3z 待1p二枚 1z三枚 2z三枚
}
```

"m,p,s,z" means "萬子,筒子,索子,字牌"  
"1z-7z" means "東南西北白發中"

```js
//手牌13,10,7,4,1枚の場合
let hai = [
    [3, 3, 3, 0, 0, 0, 0, 0, 0],
    [1, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0],
    [1, 1, 1, 0, 0, 0, 0]
]
console.log(syanten.hairi(hai))
```

**Output:**

```js
//手牌13,10,7,4,1枚の場合
{
  now: 2, //現在向聴数
  wait: {'1p': 3, '2p': 4, '3p': 4, '1z': 3, '2z': 3, '3z': 3 } //待1p三枚 2p四枚 3p四枚 1z三枚 2z三枚 3z三枚
}
```

## 七対&国士牌理計算

```js
let hai = [
    [2, 2, 2, 0, 0, 0, 0, 0, 0],
    [1, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0],
    [2, 2, 1, 1, 1, 0, 0]
]
console.log(syanten.hairi(hai, true))
```

---
_Source: https://npm.io/package/syanten · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
