Git Product home page Git Product logo

agari's Introduction

Agari

麻雀アガリ和了形計算
Japanese riichi mahjong hand agari calculation

Install with npm:

# npm i agari

Use in browser:

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

Usage:

const agari = require('agari')
let hai = [
    [3,1,1,3,0,0,0,0,0], //萬子
    [3,0,0,0,0,0,0,0,0], //筒子
    [3,0,0,0,0,0,0,0,0], //索子
    [0,0,0,0,0,0,0]      //字牌
]
console.log(agari(hai))

Output:

[
    //和了形1
    [
        '1m', //雀頭
        [ '1m', '2m', '3m' ], //順子
        [ '1p' ], //刻子
        [ '1s' ], //刻子
        [ '4m' ]  //刻子
    ],
    //和了形2
    [
        [ '1m' ], //刻子
        [ '1p' ], //刻子
        [ '1s' ], //刻子
        [ '2m', '3m', '4m' ], //順子
        '4m' //雀頭
    ]
]

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

Check only:

const agari = require('agari')

//check 一般形
agari.check([
    [3,1,1,1,2,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]
]) //return true

//check7 七対子形
agari.check7([
    [2,0,2,2,2,2,2,0,2],
    [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]
]) //return true

//check13 国士形
agari.check13([
    [1,0,0,0,0,0,0,0,1],
    [1,0,0,0,0,0,0,0,1],
    [1,0,0,0,0,0,0,0,1],
    [1,1,1,1,2,1,1]
]) //return true

//check all types
agari.checkAll([
    [1,1,1,1,1,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,0,0,0,0]
]) //return boolean

agari's People

Contributors

takayama-lily 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.