---
title: "alternative-decks"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{alternative-decks}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```


# Alternative Decks in mmcards

This vignette explores three alternative types of decks offered by the 'mmcards' package that may better suit your specific use case compared to a standard 52-card deck. First, load the 'mmcards' library, and then we'll play simple games to illustrate how each deck works.

```{r setup}
library(mmcards)
```


## AnonymousDeck

Suppose you're teaching a statistical concept and want to simulate drawing samples from a population. In that case, you can define a custom AnonymousDeck and play a game to drive the idea home.

### Whose Card is Closer to the Population Mean?

```{r}
# Define the Players
p1 <- NULL
p2 <- NULL

# Create a shuffled anonymous deck of 10 cards using a random number seed for reproducibility
game_deck <- shuffle_deck(deck_of_cards = function(x){rnorm(10, 0, 5)},
                          seed = 147)

# Deal a card to each player
game_deck <- deal_card(game_deck)
p1 <- game_deck$dealt_card

game_deck <- deal_card(game_deck)
p2 <- game_deck$dealt_card

# Display the cards and determine the winner
paste("p1 has:", p1$card, "with a value of", p1$value)
paste("p2 has:", p2$card, "with a value of", p2$value)
paste0("The winner is: ", ifelse(abs(p1$value) < abs(p2$value), "p1", "p2"))

# Here are the remaining 8 cards in the deck
print(game_deck$updated_deck)
```


## InterleavedDeck

If you want to simulate drawing samples from two distinct populations, an InterleavedDeck can be useful.

### Whose Card is Closer to the Population Mean? with Biased Decks

```{r}
# Define the Players
p1 <- NULL
p2 <- NULL

# Create a shuffled interleaved deck of 10 cards using a random number seed for reproducibility
game_deck <- shuffle_deck(deck_of_cards = function(x){list(rnorm(5, 0, 5),
                                                           rnorm(5, 0, 3))},
                          seed = 157)

# Deal a card to each player
game_deck <- deal_card(game_deck)
p1 <- game_deck$dealt_card

game_deck <- deal_card(game_deck)
p2 <- game_deck$dealt_card

# Display the cards and determine the winner
paste("p1 has:", p1$card, "with a value of", p1$value)
paste("p2 has:", p2$card, "with a value of", p2$value)
paste0("The winner is: ", ifelse(abs(p1$value) < abs(p2$value), "p1", "p2"))

# Here are the remaining 8 cards in the deck
print(game_deck$updated_deck)
```


## PairedDeck

A PairedDeck is ideal for games that require maintaining a natural pairing between cards, such as in a paired t-test scenario.

### Hanging from Pull-up Bar: Left Hand vs Right Hand

```{r}
# Define the hands
LH <- NULL
RH <- NULL

# Create a shuffled paired deck of 20 cards using a random number seed for reproducibility
game_deck <- shuffle_deck(deck_of_cards = function(x){list(rpois(10, 30),
                                                           rnorm(10, 40))},
                          seed = 232,
                          paired = TRUE)


# For the student whose cards came out on top, get the hang time for each hand
game_deck <- deal_card(game_deck)
LH <- game_deck$dealt_card

game_deck <- deal_card(game_deck)
RH <- game_deck$dealt_card

# Display the cards and determine which hand was stronger
paste("This student's left hand card is:",
      LH$card, "with a value of", LH$value)
paste("This student's right hand card is:", RH$card, "with a value of", RH$value)
paste0("Did this student hang for longer with left hand?: ",
       ifelse(LH$value > RH$value, "Yes", "No"))

# Here are the remaining students' hang times
print(game_deck$updated_deck)
```


Notice that the students' order is shuffled but the LH and RH pairs are intact.
