Skip to content

Latest commit

 

History

History
160 lines (111 loc) · 4.12 KB

README.md

File metadata and controls

160 lines (111 loc) · 4.12 KB

suitr

Coverage status Travis build status AppVeyor Build Status

This package makes it easy to create cards in R either for printing in the console or for html export. The logic is based around the Unicode representation of cards (and other objects) which are wrapped in a span container.

Installation

You can install suitr from GitHub via install_github()

devtools::install_github("r-webutils/suitr")

Cards

Cards are always represented by strings like "Kc" or "7s". They can be converted into HTML via card_html().

library(suitr)
span(card_html("Jh"), card_html("As"), card_html("Tc"), card_html("2d"))

card_unicode() converts cards into a Unicode representation which means they can be printed directly into the console.

cat(card_unicode("Ad"))
#> 🃁

suitr uses a four color deck by default. This behavior can be changed with the parameter four_color.

card_list()
#>  [1] "2s" "2h" "2c" "2d" "3s" "3h" "3c" "3d" "4s" "4h" "4c" "4d" "5s" "5h"
#> [15] "5c" "5d" "6s" "6h" "6c" "6d" "7s" "7h" "7c" "7d" "8s" "8h" "8c" "8d"
#> [29] "9s" "9h" "9c" "9d" "Ts" "Th" "Tc" "Td" "Js" "Jh" "Jc" "Jd" "Qs" "Qh"
#> [43] "Qc" "Qd" "Ks" "Kh" "Kc" "Kd" "As" "Ah" "Ac" "Ad"
card_list() %>% lapply(card_html, size = 50) %>% span()

card_list() %>% lapply(card_html, size = 50, four_color = FALSE) %>% span()

Suits

It is also possible to get the Unicode representation of the suits symbols and export them into html.

suit_list()
#> [1] "s" "h" "c" "d"
suit_list() %>% lapply(suit_html) %>% span()

suit_list() %>% lapply(suit_html, fill = FALSE) %>% span()

suit_list() %>% sapply(suit_unicode) %>% cat()
#> ♠ ♥ ♣ ♦

Special cards

There are currently 3 "special" cards implemented which do not match the rank-suit pattern of the cards above. Those are wrapped into a named list which can be obtained with card_specials().

names(card_specials())
card_specials() %>% lapply(unicode_html, style = "color: blue;") %>% span()

Dice

1:6 %>% lapply(dice_html, size = 140) %>% span()

Chess

pieces_list()
#> [1] "k" "q" "r" "b" "n" "p"
pieces_list() %>% lapply(chess_html, size = 140) %>% span()

pieces_list() %>% lapply(chess_html, color = "black", size = 140) %>% span()

Mahjong

mahjong_list()[1:4]
#> [1] "east wind"  "south wind" "west wind"  "north wind"
mahjong_list() %>% lapply(mahjong_html, size = 68) %>% span()

Domino

span(domino_html(4, 5), domino_html(0, 6), domino_html(6, 2, horizontal = FALSE))

Draughts

span(draughts_html("white", "man"), draughts_html("white", "king"),
     draughts_html("black", "man"), draughts_html("black", "king")) %>% browsable()