npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

syanten

v1.6.0

Published

Japanese riichi mahjong hand shanten calculation

Downloads

156

Readme

syanten

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

Install with npm:

# npm i syanten

Use in browser:

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

Example:

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:

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

一般型牌理計算

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:

//手牌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 "東南西北白發中"

//手牌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:

//手牌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三枚
}

七対&国士牌理計算

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))