Package 'shikakusphere'

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

Help Index


Calculate score of hand

Description

Calculate score of hand

Usage

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
)

Arguments

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 "m1=". Leave empty if there is no rongpai.

rule

A list; a rule set. Defaults to default_rule().

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.

Value

A data frame.

Examples

calc_defen("m345567p234s3378", baopai = "z1", rongpai = "s9=")

Calculate xiangting number of hands

Description

Calculate xiangting number of hands

Usage

calc_xiangting(pai)

Arguments

pai

A character vector.

Value

An integer vector.

Examples

calc_xiangting(c("m345567p234s3378", "p222345z1234567"))

Collect tingpais for hands

Description

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.

Usage

collect_tingpai(pai)

Arguments

pai

A character vector.

Value

A list of character vectors.

Examples

collect_tingpai(c("m345567p234s3378", "p222345z1234567"))

Create default rule set

Description

Create default rule set

Usage

default_rule()

Value

A list.

See Also

https://github.com/kobalab/majiang-core/wiki/%E3%83%AB%E3%83%BC%E3%83%AB


Plot a player's hand as an image

Description

This function is a short hand for paistr(pai) |> plot()

Usage

hand2img(pai, ...)

Arguments

pai

A character vector.

...

Other arguments passed to plot().

See Also

paistr


List of hupai

Description

List of hupai

Usage

hupai

Format

An object of class data.frame with 54 rows and 3 columns.

Details

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

Description

Convert integers to tiles

Usage

int2tile(x = seq_len(38) - 1, origin = c("zero", "one"))

Arguments

x

An integer vector.

origin

A string scalar. Either "zero" or "one".

Value

A factor.

Examples

int2tile(c(0, 1, 25, 37))

Line up tiles

Description

Arrange all tiles from a data frame.

Usage

lineup(x)

Arguments

x

A data frame with columns id, tile, and n.

Value

An object of x$tile class.

Examples

rand_hands()(3) |>
  paistr() |>
  tidy() |>
  lineup()

Compose hands from character vectors

Description

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.

Usage

lipai(x)

Arguments

x

A list of character vectors or a character vector.

Value

A character vector.

Examples

lipai(list(c("m1", "m2", "m3"), c("p1", "p2", "p3")))

Modify the default rule set by patch

Description

Modify the default rule set by patch

Usage

modify_rule(patch = list())

Arguments

patch

A list.

Value

A list.


paistr vector

Description

Create a paistr vector from a character vector that represents player's hands.

Usage

paistr(x = character())

is_paistr(x)

## S3 method for class 'skksph_paistr'
plot(x, y, ...)

## S3 method for class 'skksph_paistr'
tidy(x, ...)

Arguments

x
  • For paistr(): A character vector.

  • For is_paistr(): An object to test.

  • For plot(): An object to plot as an image.

  • For tidy(): An object to tidy up.

y
  • For plot(): Not used.

...

Other arguments for plot() or tidy().

Details

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

Value

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

Examples

pai <- paistr(c("m055z7z7,m78-9,z5555,z666=", "m123s789z1117*,p5550"))
print(pai)
is_paistr(pai)
tidy(pai)

Parse chains of hupai ids

Description

Parse comma separated chains of hupai ids into a list of factors.

Usage

parse_hupai(str, lang = c("en", "jp"))

Arguments

str

A character vector.

lang

A string scalar. Either "en" or "jp".

Value

A list of factors.


Create a function to randomly generate hands

Description

Create a function to randomly generate hands

Usage

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
)

Arguments

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 default_rule().

seed

An integer scalar. Used for initializing the random number generator.

Value

A function inheriting class purrr_function_partial that takes single arguments n: number of hands to be generated.