Skip to content

Commit 4e12ef4

Browse files
authored
deckz:0.3.1 (#3106)
1 parent d277869 commit 4e12ef4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+5037
-0
lines changed

packages/preview/deckz/0.3.1/LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

packages/preview/deckz/0.3.1/README.md

Lines changed: 416 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#import "../template.typ": *
2+
3+
// Complete documentation for DECKZ functions and features
4+
= Documentation
5+
<sec:documentation>
6+
7+
8+
== Card visualization
9+
This section provides a comprehensive overview of the DECKZ package's *card visualization* capabilities. It presents the available formats and how to use them effectively.
10+
#show-module(("view/format", "view/back"))
11+
12+
13+
#pagebreak()
14+
== Group visualization
15+
This section covers the *group visualization* features of the DECKZ package, i.e. all functions that allow you to visualize groups of cards, such as hands, decks, and heaps.
16+
#show-module("view/group")
17+
18+
19+
#pagebreak()
20+
== Data
21+
This section provides an overview of the *data structures* used in the DECKZ package, including suits, ranks, and cards. It explains how these data structures are organized and how to access them.
22+
#show-module(("data/suit", "data/rank", "logic/structs"))
23+
//#show-module("data/style")
24+
25+
26+
#pagebreak()
27+
== Randomization
28+
The DECKZ package includes essential *randomization features* for card games, such as shuffling and drawing random cards from a deck. However, since *Typst* is a pure functional language, true randomness is not available; instead, DECKZ uses the #universe("suiji") package to generate pseudo-random numbers.
29+
30+
This section explains how to use these randomization tools within DECKZ, describes the underlying concepts, and provides practical guidance for integrating randomness into your projects.
31+
Randomization functions are available under the #primary[`deckz.mix`] namespace, and they include:
32+
#show-module("logic/mix", submodule: "mix")
33+
34+
#pagebreak()
35+
== Arranging hands
36+
This section covers the *sorting and organizing functions* available in the #primary[`arr`] module in the DECKZ package.
37+
It explains how to sort cards by rank, suit, and other criteria, providing a foundation for building more complex card games and applications.
38+
#show-module("logic/sort", submodule: "arr")
39+
40+
41+
#pagebreak()
42+
== Evaluating hands
43+
This section provides an overview of the *scoring functions* from the #primary[`val`] module of the DECKZ package, which are essential for evaluating hands in card games. Such functions are helpful for assessing the value of a hand based on various criteria and combinations, such as n-of-a-kind, flushes, and straights.
44+
#show-module("logic/score", submodule: "val")
45+
46+
47+
#pagebreak()
48+
== Language-aware card symbols
49+
DECKZ automatically adapts the rendering of card rank symbols based on the document's language. This process is seamless: users only need to set the desired language using the `text` command, and DECKZ will adjust the symbols accordingly. No additional configuration is required.
50+
51+
#let build-lang-row(lang) = {
52+
return (
53+
text(weight: "bold")[
54+
#primary(smallcaps(lang))
55+
],
56+
..deckz.ranks.values().map(rank-data => [
57+
#set text(lang: lang)
58+
#text(size: 1.2em, weight: "medium", rank-data.symbol)
59+
#linebreak()
60+
#text(size: 0.5em)[#rank-data.name]
61+
]),
62+
)
63+
}
64+
65+
The current version of DECKZ supports the following *languages*:
66+
67+
#show table.cell: set align(center)
68+
#show table.cell: set text(font: "Roboto Slab", size: 0.9em)
69+
#table(
70+
stroke: gray.transparentize(70%) + 1pt,
71+
columns: (1cm, ) + (1fr,) * 13,
72+
..build-lang-row("en"),
73+
..build-lang-row("it"),
74+
..build-lang-row("fr"),
75+
..build-lang-row("de"),
76+
..build-lang-row("ru"),
77+
)
78+
79+
The localization is powered by the #universe("linguify") package, thanks to the generous contribution of the users who helped translating card names and symbols.
80+
81+
#example(breakable: true, side-by-side: true)[
82+
```typ
83+
#let seq = ("10C", "JH", "QS", "KD", "AC")
84+
85+
#set text(lang: "en")
86+
#deckz.line(..seq, format: "small")
87+
88+
#set text(lang: "it")
89+
#deckz.line(..seq, format: "small")
90+
91+
#set text(lang: "fr")
92+
#deckz.line(..seq, format: "small")
93+
```
94+
]
95+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#let cards-window(body) = block(fill: white, width: 100%, inset: 5pt, body)
2+
3+
#block(fill: gray.lighten(60%), inset: 5pt, breakable: false)[
4+
5+
#let example-cards = ("AS", "5H", "10C", "QD")
6+
7+
#text(blue)[`inline`] --- A minimal format where the rank and suit are displayed directly within the flow of text; perfect for quick references.
8+
#cards-window[
9+
#deckz.line(..example-cards, format: "inline", width: 100%)
10+
]
11+
12+
#text(blue)[`mini`] --- The smallest visual format: a compact rectangle showing the rank at the top and the suit at the bottom.
13+
#cards-window[
14+
#deckz.line(..example-cards, format: "mini", width: 100%)
15+
]
16+
17+
#text(blue)[`small`] --- A slightly larger card with rank indicators on opposite corners and a central suit symbol; ideal for tight layouts with better readability.
18+
#cards-window[
19+
#deckz.line(..example-cards, format: "small", width: 100%)
20+
]
21+
22+
#text(blue)[`medium`] --- A fully structured card layout featuring proper suit placement and figures. Rank and suit appear in two opposite corners, offering a realistic visual.
23+
#cards-window[
24+
#deckz.line(..example-cards, format: "medium", width: 100%)
25+
]
26+
27+
#text(blue)[`large`] --- The most detailed format, with corner summaries on all four corners and an expanded layout; great for presentations or printable decks.
28+
#cards-window[
29+
#deckz.line(..example-cards, format: "large", width: 100%)
30+
]
31+
]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#let player-mat(body) = box(
2+
stroke: olive.darken(20%),
3+
fill: olive.lighten(10%),
4+
radius: (top: 50%, bottom: 5%),
5+
inset: 15%,
6+
body
7+
)
8+
9+
#text(white, font: "Roboto Slab", weight: "semibold")[
10+
#box(fill: olive,
11+
width: 100%, height: 12cm,
12+
inset: 4mm, radius: 2mm
13+
)[
14+
15+
#place(center + bottom)[
16+
#player-mat[
17+
#deckz.hand(format: "small", width: 3cm, "9S", "10H", "4C", "4D", "2D")
18+
Alice
19+
]
20+
]
21+
#place(left + horizon)[
22+
#rotate(90deg, reflow: true)[
23+
#player-mat[
24+
#deckz.hand(format: "small", width: 3cm, "AS", "JH", "JC", "JD", "3D")
25+
#align(center)[Bob]
26+
]
27+
]
28+
]
29+
#place(center + top)[
30+
#rotate(180deg, reflow: true)[
31+
#player-mat[
32+
#deckz.hand(format: "small", width: 3cm, "KH", "8H", "7H", "5C", "3C")
33+
#rotate(180deg)[Carol]
34+
]
35+
]
36+
]
37+
#place(right + horizon)[
38+
#rotate(-90deg, reflow: true)[
39+
#player-mat[
40+
#deckz.hand(format: "small", width: 3cm, "6S", "3H", "2H", "QC", "9C")
41+
#align(center)[Dave]
42+
]
43+
]
44+
]
45+
#place(center + horizon)[
46+
#deckz.deck(format: "small", angle: 80deg, height: 8mm, "back")
47+
]
48+
]
49+
]
50+
51+
In this situation, Alice has a *Pair of Four* (#deckz.inline("4C"), #deckz.inline("4D")). _What should the player do?_
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#text(white, font: "Oldenburg", size: 10pt)[
2+
#block(fill: aqua.darken(40%), inset: 4mm, radius: 2mm)[
3+
#deckz.hand(
4+
angle: 270deg,
5+
width: 5.8cm,
6+
format: "large",
7+
noise: 0.05,
8+
..deckz.deck52
9+
)
10+
#place(center + horizon)[#text(size: 20pt, baseline: 8pt)[Deckz]]
11+
]
12+
]
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Defining players and their hands
2+
#let players = ("Alice", "Bob", "Carol", "David")
3+
#let (players-hands, board-cards) = deckz.mix.split(
4+
deckz.deck52, // Start with a standard deck of 52 cards
5+
size: ((players.len(), 2), 5), // 2 cards per player + 5 board cards
6+
rest: false,
7+
)
8+
9+
#set align(center)
10+
#set text(fill: white, size: 13pt, font: "Arvo")
11+
12+
#block(
13+
fill: olive,
14+
inset: 15pt,
15+
radius: 5pt,
16+
breakable: false,
17+
)[
18+
// Board cards
19+
*Board*
20+
#deckz.hand(
21+
format: "small",
22+
width: 4cm,
23+
angle: 20deg,
24+
noise: 0.2,
25+
..board-cards
26+
)
27+
// Displaying the deck of cards
28+
#place(right + top)[
29+
#deckz.deck(
30+
format: "small",
31+
angle: 90deg,
32+
noise: 0.2,
33+
"back"
34+
)
35+
]
36+
37+
#v(1cm)
38+
#set table.cell(
39+
fill: olive.darken(20%),
40+
stroke: olive.darken(10%) + 2pt,
41+
)
42+
43+
// Players' hands
44+
#table(
45+
columns: players.len(),
46+
column-gutter: 1fr,
47+
48+
..players-hands
49+
.zip(players)
50+
.map(((hand, player)) => [
51+
#player
52+
#deckz.hand(
53+
format: "small",
54+
width: 1cm,
55+
angle: 30deg,
56+
noise: 0.4,
57+
..hand
58+
)
59+
])
60+
)
61+
]
62+
63+
#set align(left)
64+
#set text(fill: black, size: 12pt)
65+
66+
Which is the *best hand* each player can make?
67+
#for (player, hand) in players.zip(players-hands) [
68+
69+
- *#player*
70+
#box(
71+
fill: olive,
72+
inset: 8pt,
73+
radius: 15%,
74+
)[
75+
#(hand + board-cards).map(deckz.mini).join(" ")
76+
]
77+
$stretch(=>)^" Best hand "$
78+
#let best = deckz.val.extract-highest(hand + board-cards, sort: true).first()
79+
#box(
80+
fill: none,
81+
stroke: (paint: green, thickness: 3pt, dash: "dashed"),
82+
inset: 8pt,
83+
radius: 45%,
84+
)[
85+
#best.map(deckz.mini).join(" ")
86+
]
87+
]
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Define and sort the initial hand
2+
#let my-hand = deckz.arr.sort-by-score(("8S", "9S", "10S", "JS", "QS", "9H", "9D", "9C", "QD", "3D", "4D", "5D"))
3+
4+
#set text(font: "Roboto Slab")
5+
My current *hand*:
6+
7+
#deckz.hand(..my-hand,
8+
format: "small",
9+
angle: 10deg,
10+
width: 12cm,
11+
)
12+
13+
#let show-combination(combination) = [
14+
15+
Which *#combination* can I make?
16+
17+
#let combinations = deckz.val.extract(combination, my-hand)
18+
#if combinations.len() == 0 {
19+
[None.]
20+
} else {
21+
for combo in combinations {
22+
box(
23+
fill: eastern,
24+
inset: 6pt,
25+
radius: 12pt,
26+
)[
27+
#deckz.line(..combo, format: "mini", spacing: 6pt)
28+
]
29+
h(1mm)
30+
}
31+
}
32+
]
33+
34+
#show-combination("high-card")
35+
#show-combination("pair")
36+
#show-combination("two-pairs")
37+
#show-combination("three-of-a-kind")
38+
#show-combination("straight")
39+
#show-combination("flush")
40+
#show-combination("full-house")
41+
#show-combination("four-of-a-kind")
42+
#show-combination("straight-flush")
43+
#show-combination("five-of-a-kind")
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#import "../template.typ": *
2+
3+
// Examples of how to use DECKZ
4+
= Examples
5+
<sec:examples>
6+
7+
8+
The following examples showcase more advanced and interesting *use cases* of DECKZ. In this Section, you can find how DECKZ can be used to represent real game states, compare card formats, and display entire decks in creative ways.
9+
10+
== Displaying the current state of a game
11+
12+
You can use DECKZ to display the *current state of a game*, such as the cards in hand, the cards on the table, and the deck.
13+
14+
#example(breakable: true)[
15+
#raw(
16+
lang: "typ",
17+
read("exmp_current_state.typ"),
18+
)
19+
]
20+
21+
#pagebreak()
22+
== Comparing different formats
23+
24+
You can use DECKZ to *compare different formats* of the same card, or to show how a card looks in different contexts.
25+
26+
#example(breakable: true)[
27+
#raw(
28+
lang: "typ",
29+
read("exmp_comparison_table.typ"),
30+
)
31+
]
32+
33+
#pagebreak()
34+
== Displaying a full deck
35+
36+
You can use DECKZ to display a *full deck of cards*, simply by retrieving the `deckz.deck52` array, which contains all 52 standard playing cards.
37+
38+
#example(breakable: true)[
39+
#raw(
40+
lang: "typ",
41+
read("exmp_deck_circle.typ"),
42+
)
43+
]
44+
45+
#pagebreak()
46+
== Randomized game with card scoring
47+
48+
You can use DECKZ to create a *randomized _Texas Hold'em_-like game*, where players are dealt random hands and their best hands are determined based on the cards on the table/*, using the @cmd:deckz:val:extract-highest function*/.
49+
50+
#example(breakable: true)[
51+
#raw(
52+
lang: "typ",
53+
read("exmp_game_random.typ"),
54+
)
55+
]
56+
57+
#pagebreak()
58+
== Scoring hands
59+
You can use DECKZ to *score hands* in a game, such as Poker, by extracting combinations of cards that form specific hands, such as pairs, three-of-a-kinds, straights, flushes, and so on.
60+
61+
#example(breakable: true)[
62+
#raw(
63+
lang: "typ",
64+
read("exmp_scoring.typ"),
65+
)
66+
]

0 commit comments

Comments
 (0)