Giter Club home page Giter Club logo

syanten's Introduction

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

syanten's People

Contributors

takayama-lily avatar thttnt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.