Title: | Miscellaneous Functions for Japanese Mahjong |
---|---|
Description: | A collection of miscellaneous functions for Japanese Mahjong that wraps C++ sources of 'cmajiang' <https://github.com/TadaoYamaoka/cmajiang>. |
Authors: | Akiru Kato [aut, cre], Tadao Yamaoka [ctb], Lee Thomason [ctb] |
Maintainer: | Akiru Kato <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.3.9003 |
Built: | 2024-10-22 17:15:19 UTC |
Source: | https://github.com/paithiov909/shikakusphere |
Calculate score of hand
calc_defen( pai, baopai, libaopai = "", rongpai = "", rule = default_rule(), zhuangfeng = c("z1", "z2", "z3", "z4"), menfeng = c("z2", "z3", "z4", "z1"), lizhi = c("none", "lizhi", "double-lizhi"), yifa = FALSE, qianggang = FALSE, lingshang = FALSE, haidi = c("none", "haidimoyue", "hedilaoyu"), tianhe = c("none", "tianhe", "dihe"), changbang = 0L, lizhibang = 0L )
calc_defen( pai, baopai, libaopai = "", rongpai = "", rule = default_rule(), zhuangfeng = c("z1", "z2", "z3", "z4"), menfeng = c("z2", "z3", "z4", "z1"), lizhi = c("none", "lizhi", "double-lizhi"), yifa = FALSE, qianggang = FALSE, lingshang = FALSE, haidi = c("none", "haidimoyue", "hedilaoyu"), tianhe = c("none", "tianhe", "dihe"), changbang = 0L, lizhibang = 0L )
pai |
A string scalar. This param is not vectorized. |
baopai |
A character vector. "Dora" indicators. |
libaopai |
A character vector. "Ura-dora" indicators. Leave empty if there is no libaopai. |
rongpai |
A string scalar such as |
rule |
A list; a rule set. Defaults to |
zhuangfeng |
A string scalar; "ba-kaze" tile. |
menfeng |
A string scalar; "ji-kaze" tile. |
lizhi |
A string scalar. Either "none", "lizhi", or "double-lizhi". |
yifa |
A logical scalar; flag for "ippatsu". |
qianggang |
A logical scalar; flag for "chankan". |
lingshang |
A logical scalar; flag for "rinshan-kaihou". |
haidi |
A string scalar. Either "none", "haidimoyue", or "hedilaoyu". |
tianhe |
A string scalar; Either "none", "tianhe", or "dihe". |
changbang |
An integer scalar; the number of counter sticks that indicates "honba". |
lizhibang |
An integer scalar; the number of 1,000-point sticks on the table. |
A data frame.
calc_defen("m345567p234s3378", baopai = "z1", rongpai = "s9=")
calc_defen("m345567p234s3378", baopai = "z1", rongpai = "s9=")
Calculate xiangting number of hands
calc_xiangting(pai)
calc_xiangting(pai)
pai |
A character vector. |
An integer vector.
calc_xiangting(c("m345567p234s3378", "p222345z1234567"))
calc_xiangting(c("m345567p234s3378", "p222345z1234567"))
Collect tiles that can decrease the xiangting number of hands
if they are drawn.
In case of already winning hands, corresponding vectors will be NA
.
collect_tingpai(pai)
collect_tingpai(pai)
pai |
A character vector. |
A list of character vectors.
collect_tingpai(c("m345567p234s3378", "p222345z1234567"))
collect_tingpai(c("m345567p234s3378", "p222345z1234567"))
Create default rule set
default_rule()
default_rule()
A list.
https://github.com/kobalab/majiang-core/wiki/%E3%83%AB%E3%83%BC%E3%83%AB
This function is a short hand for paistr(pai) |> plot()
hand2img(pai, ...)
hand2img(pai, ...)
pai |
A character vector. |
... |
Other arguments passed to |
List of hupai
hupai
hupai
An object of class data.frame
with 54 rows and 3 columns.
A data frame that contains the list of hupai.
The list includes the following columns:
id
: The id of the hupai.
en
: The English name of the hupai.
jp
: The Japanese name of the hupai.
Convert integers to tiles
int2tile(x = seq_len(38) - 1, origin = c("zero", "one"))
int2tile(x = seq_len(38) - 1, origin = c("zero", "one"))
x |
An integer vector. |
origin |
A string scalar. Either "zero" or "one". |
A factor.
int2tile(c(0, 1, 25, 37))
int2tile(c(0, 1, 25, 37))
Arrange all tiles from a data frame.
lineup(x)
lineup(x)
x |
A data frame with columns |
An object of x$tile
class.
rand_hands()(3) |> paistr() |> tidy() |> lineup()
rand_hands()(3) |> paistr() |> tidy() |> lineup()
Compose hands from character vectors while ignoring invalid tiles. This function can handle any number of tiles in each hand, but cannot more than 5 identical tiles. If there are more than 5 identical tiles, arises an error.
lipai(x)
lipai(x)
x |
A list of character vectors or a character vector. |
A character vector.
lipai(list(c("m1", "m2", "m3"), c("p1", "p2", "p3")))
lipai(list(c("m1", "m2", "m3"), c("p1", "p2", "p3")))
Modify the default rule set by patch
modify_rule(patch = list())
modify_rule(patch = list())
patch |
A list. |
A list.
paistr
vectorCreate a paistr
vector from a character vector
that represents player's hands.
paistr(x = character()) is_paistr(x) ## S3 method for class 'skksph_paistr' plot(x, y, ...) ## S3 method for class 'skksph_paistr' tidy(x, ...)
paistr(x = character()) is_paistr(x) ## S3 method for class 'skksph_paistr' plot(x, y, ...) ## S3 method for class 'skksph_paistr' tidy(x, ...)
x |
|
y |
|
... |
Other arguments for |
Note that the validation of this function is not so strict.
For example, paistr("z0")
still produces a valid paistr
vector
even though "z0" is not a tile that actually exists.
These paistr
are simply ignored by the ‘cmajiang’ function wrapper.
The number of tiles displayed when print()
is not always accurate,
so if you need to count the actual number of tiles, use tidy()
.
For paistr()
: An object of class skksph_paistr
.
For is_paistr()
: A logical scalar.
For plot()
: A bitmap image that internally converted
by magick::image_read_svg()
is invisibly returned.
For tidy()
: A data frame (not a tibble).
pai <- paistr(c("m055z7z7,m78-9,z5555,z666=", "m123s789z1117*,p5550")) print(pai) is_paistr(pai) tidy(pai)
pai <- paistr(c("m055z7z7,m78-9,z5555,z666=", "m123s789z1117*,p5550")) print(pai) is_paistr(pai) tidy(pai)
Parse comma separated chains of hupai ids into a list of factors.
parse_hupai(str, lang = c("en", "jp"))
parse_hupai(str, lang = c("en", "jp"))
str |
A character vector. |
lang |
A string scalar. Either "en" or "jp". |
A list of factors.
Create a function to randomly generate hands
rand_hands( hupai = c("pinghe", "zhuangfeng", "menfeng", "fanpai", "duanyaojiu", "yibeikou", "sansetongshun", "yiqitongguan", "hunquandaiyaojiu", "qiduizi", "duiduihu", "sananke", "sangangzi", "sansetongke", "hunlaotou", "xiaosanyuan", "hunyise", "chunquandaiyaojiu", "erbeikou", "qingyise", "guoshiwushuang", "sianke", "dasanyuan", "xiaosixi", "dasixi", "ziyise", "lvyise", "qinglaotou", "sigangzi", "jiulianbaodeng"), zhuangfeng = c("z1", "z2", "z3", "z4"), menfeng = c("z2", "z3", "z4", "z1"), rule = default_rule(), seed = 1234 )
rand_hands( hupai = c("pinghe", "zhuangfeng", "menfeng", "fanpai", "duanyaojiu", "yibeikou", "sansetongshun", "yiqitongguan", "hunquandaiyaojiu", "qiduizi", "duiduihu", "sananke", "sangangzi", "sansetongke", "hunlaotou", "xiaosanyuan", "hunyise", "chunquandaiyaojiu", "erbeikou", "qingyise", "guoshiwushuang", "sianke", "dasanyuan", "xiaosixi", "dasixi", "ziyise", "lvyise", "qinglaotou", "sigangzi", "jiulianbaodeng"), zhuangfeng = c("z1", "z2", "z3", "z4"), menfeng = c("z2", "z3", "z4", "z1"), rule = default_rule(), seed = 1234 )
hupai |
A string scalar. |
zhuangfeng |
A string scalar; "ba-kaze" tile. |
menfeng |
A string scalar; "ji-kaze" tile. |
rule |
A list; a rule set. Defaults to |
seed |
An integer scalar. Used for initializing the random number generator. |
A function inheriting class purrr_function_partial
that takes single arguments n
: number of hands to be generated.