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

riichi-ts

v1.0.7

Published

Riichi mahjong calculations library

Downloads

3

Readme

Riichi Typescript library

Small library to calculate hands and yaku for japanese (riichi) mahjong.

Usage

Install the library using npm install riichi-ts or yarn add riichi-ts. Type definitions for typescript are included in the package.

Tiles definition

Tiles are defined by a single integer number according to the following table:

  • Man suit: 0 is 1man, ... 8 is 9man
  • Pin suit: 9 is 1pin, ... 17 is 9pin
  • Sou suit: 18 is 1sou, ... 26 is 9sou
  • Honors:
    • Winds: 27 is east, ... 30 is north
    • Dragons: 31 is white, 32 is green, 33 is red

Usage:

import { Riichi } from 'riichi-ts';

const hand = new Riichi(
  [10, 10, 10, 11, 11, 12, 12], // closed part of the hand.  Taken tile from the wall should be the last here in case of tsumo.
  [ // melds
    { open: true, tiles: [13, 14, 15] }, // set open: false to mark closed kan (ankan)
    { open: true, tiles: [15, 16, 17] },
  ],
  { 
    bakaze: 27, // round wind
    jikaze: 28 // seat wind
  },
  13, // tile taken from someone's discard. In case of tsumo, set this to null. 
  false, // was this the first take? Used to determine tenhou/chinou/renhou
  true, // does this hand have riichi?
  false, // does this hand have ippatsu?
  false, // does this hand have daburu-riichi?
  false, // is it the last taken tile? Used to determine haitei/houtei
  false, // was it agari after a kan? Used to determine rinshan/chankan
  0, // akadora count in hand
  true, // allow akadora; if this is false, previous parameter is ignored
  true, // allow kuitan?
  false, // use kiriage mangan?
);
hand.disableDoubleyakuman(); // call this to count all yakumans as single
hand.disableYaku('yaku name'); // You can also disable some of the yaku
hand.disableHairi(); // Don't calculate improvements for the non-winning hand
const result = hand.calc();
/*
    Result format:
    {
      error: false, // true if hand couldn't be parsed
      fu: 30,
      han: 6,
      isAgari: true, // will be false if the hand is not winning
      ten: 12000, // amount of points won by the hand
      text: '', // additional info. Will contain 'no yaku' if the hand has no winning points 
      yaku: { // list of found yaku in the hand
       chinitsu: 5, // yaku name and amount of han for certain yaku
       tanyao: 1 
      },
      yakuman: 0, // Count of yakumans found
      hairi: { // shanten count and waits info
         now: 0, // current shanten count. 0 for tenpai.
         wait: [12], // tiles this hand is waiting for to improve or win
         waitsAfterDiscard: { // waits after discarding a certain tile
          12: [13, 14] 
         } 
      }
      hairi7and13: { // same as above but only for chiitoitsu and kokushimusou.
         now: 0,
         wait: [12],
         waitsAfterDiscard: { 12: [13, 14] }
      }
    }
 */

Full list of yaku names that can be detected:

  • menzentsumo
  • riichi
  • ippatsu
  • chankan
  • rinshan
  • haitei
  • houtei
  • pinfu
  • tanyao
  • iipeikou
  • own wind east
  • own wind south
  • own wind west
  • own wind north
  • round wind east
  • round wind south
  • round wind west
  • round wind north
  • haku
  • hatsu
  • chun
  • daburu riichi
  • chiitoitsu
  • chanta
  • ittsu
  • sanshoku
  • sanshoku doukou
  • sankantsu
  • toitoi
  • sanankou
  • shosangen
  • honroutou
  • ryanpeikou
  • junchan
  • honitsu
  • chinitsu
  • renhou
  • tenhou
  • chihou
  • daisangen
  • suuankou
  • suuankou tanki
  • tsuuiisou
  • ryuuiisou
  • chinroutou
  • chuurenpoto
  • chuurenpoto 9 sides
  • kokushimusou
  • kokushimusou 13 sides
  • daisuushi
  • shosuushi
  • suukantsu
  • dora
  • uradora
  • akadora

Credits

Inspired by and partially taken from following repositories:

  • https://github.com/takayama-lily/riichi
  • https://github.com/takayama-lily/syanten
  • https://github.com/takayama-lily/agari

Testing on real games data

The library was tested against millions of real-life game logs from Tenhou.net phoenix lobby. Though we don't supply these logs in the repo, you can still download it on Tenhou.net and use it for testing.

Please place zip archives with real replay logs into logs folder. The testing script will traverse over all zip files there and will try to parse every replay file found.