Skip to content

A C++ library for the (self-proclaimed) world's fastest calculation of deficiency number (a.k.a. shanten number, 向聴数)

License

Notifications You must be signed in to change notification settings

Cryolite/nyanten

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nyanten

Nyanten is a C++ library for fast calculation of deficiency number (a.k.a. shanten number, 向聴数).

Typical Usage

#include <nyanten/replacement_number.hpp>

int main()
{
  std::vector<unsigned> hand;
  // Set the count of each tile to `hand`.
  unsigned const replacement_number = Nyanten::calculateReplacementNumber(hand);
}

Interfaces

template<typename ForwardIterator>
std::uint_fast8_t Nyanten::calculateReplacementNumber(ForwardIterator first, ForwardIterator last)

Preconditions

  • std::distance(first, last) == 34
  • For every iter in the range [first, last), 0 <= *iter and *iter <= 4
  • The sum of the numbers in the range [first, last) is less or equal to 14.
  • The sum of the numbers in the range [first, last) is congruent to 1 or 2 modulo 3.

Effects

Calculate the replacement number, which is equal to the deficiency number (a.k.a. Shanten number, 向聴数) plus one. The hand is represented by the range [first, last). Each element of the range corresponds to the count of each tile type. If there are melds (副露), the count must exclude the melded tiles. The correspondence between the element indices of the range and the tile types is as shown in the table below.

Index 0 1 2 3 4 5 6 7 8
Tile 🀇 (1m) 🀈 (2m) 🀉 (3m) 🀊 (4m) 🀋 (5m) 🀌 (6m) 🀍 (7m) 🀎 (8m) 🀏 (9m)
Index 9 10 11 12 13 14 15 16 17
Tile 🀙 (1p) 🀚 (2p) 🀛 (3p) 🀜 (4p) 🀝 (5p) 🀞 (6p) 🀟 (7p) 🀠 (8p) 🀡 (9p)
Index 18 19 20 21 22 23 24 25 26
Tile 🀐 (1s) 🀑 (2s) 🀒 (3s) 🀓 (4s) 🀔 (5s) 🀕 (6s) 🀖 (7s) 🀗 (8s) 🀘 (9s)
Index 27 28 29 30 31 32 33
Tile 🀀 (E) 🀁 (S) 🀂 (W) 🀃 (N) 🀆 (White) 🀅 (Green) 🀄 (Red)

template<typename ForwardRange>
std::uint_fast8_t Nyanten::calculateReplacementNumber(ForwardRange const &r)

Call Nyanten::calculateReplacementNumber(std::cbegin(r), std::cend(r)).

About

A C++ library for the (self-proclaimed) world's fastest calculation of deficiency number (a.k.a. shanten number, 向聴数)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages