Title: | Play Games in the Console |
Version: | 0.1.0 |
Description: | Games that can be played in the R console. Includes coin flip, hangman, jumble, magic 8 ball, poker, rock paper scissors, shut the box, spelling bee, and 2048. |
License: | MIT + file LICENSE |
URL: | https://github.com/rossellhayes/player |
BugReports: | https://github.com/rossellhayes/player/issues |
Depends: | R (≥ 3.5) |
Imports: | and, cli, crayon, dplyr, glue, nnet, plu, purrr, R6, rlang, stats, stringr, tools, twenty48 (≥ 0.2.1), utils, withr |
Suggests: | job, rstudioapi, testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.3 |
NeedsCompilation: | no |
Packaged: | 2025-09-16 14:22:54 UTC; alex |
Author: | Alexander Rossell Hayes
|
Maintainer: | Alexander Rossell Hayes <alexander@rossellhayes.com> |
Repository: | CRAN |
Date/Publication: | 2025-09-22 08:10:02 UTC |
player: Play Games in the Console
Description
Games that can be played in the R console. Includes coin flip, hangman, jumble, magic 8 ball, poker, rock paper scissors, shut the box, spelling bee, and 2048.
Author(s)
Maintainer: Alexander Rossell Hayes alexander@rossellhayes.com (ORCID) [copyright holder]
Other contributors:
Alan Beale 12dicts@pobox.com (Word lists) [data contributor]
Kevin Atkinson kevina@users.sourceforge.net (Word lists) [data contributor]
Luis Von Ahn (Word lists) [data contributor]
Flavia Rossell Hayes [illustrator]
Kristin Bott kristin.bott@posit.co (look_busy() status messages) [contributor]
Daniel Chen daniel.chen@posit.co (ORCID) (look_busy() status messages) [contributor]
Steven Smallberg steven.smallberg@posit.co (look_busy() status messages) [contributor]
See Also
Useful links:
Look like you're working hard when you're hardly working
Description
Look like you're working hard when you're hardly working
Usage
look_busy(
minutes = if (rlang::is_interactive()) Inf else 0,
speed = 1,
lambda = 3,
background_job = FALSE,
end = invisible(NULL)
)
Arguments
minutes |
How long to keep this up for.
Defaults to |
speed |
How fast to produce output.
The default value, |
lambda |
Input to a poisson distribution determining how many
calculations to perform between each message.
Defaults to |
background_job |
Whether to produce output in in a background job
(if |
end |
Code to run after |
Value
end
if minutes
is finite.
Author(s)
Alexander Rossell Hayes alexander@rossellhayes.com (ORCID)
With status messages contributed by:
Kristin Bott kristin.bott@posit.co
Daniel Chen daniel.chen@posit.co (ORCID)
Steven Smallberg steven.smallberg@posit.co
Examples
look_busy()
Play a game in the console
Description
Interact with the game by typing commands into the console and pressing enter.
Usage
play(game = NULL, ...)
Arguments
game |
The name of a game to play.
If |
... |
Additional arguments passed to the chosen game. |
Value
Calls the selected game function.
Examples
if (rlang::is_interactive()) play()
play("magic_8_ball")
Flip a coin
Description
Flip a coin
Usage
play_coin_flip(
n = NULL,
animate = rlang::is_interactive(),
header = rlang::is_interactive()
)
Arguments
n |
How many coins to flip.
Defaults to |
animate |
If |
header |
If |
Value
A character vector of "heads"
or "tails"
results.
Examples
play_coin_flip(1)
if (rlang::is_interactive()) play_coin_flip()
Play a game of hangman in the console
Description
Play a game of hangman in the console
Usage
play_hangman(
difficulty = c("beginner", "easy", "medium", "hard", "expert"),
word_list = NULL
)
Arguments
difficulty |
Determines the length of words used for the game and,
if |
word_list |
Optionally, a character vector of words used to play the
game.
If unspecified, a default word list will be used based on |
Value
Generates interactive output in the console.
Problematic words?
You can report any words you find objectionable to https://github.com/rossellhayes/hangman/issues.
Please report:
offensive words
words that deal with uncomfortable topics
proper nouns
text that is not a common English word
Source
The default word list is derived from 12dicts created by Alan Beale.
This word list is passed through the Offensive/Profane Word List created by Luis Von Ahn to filter out potentially unwanted words.
Examples
play_hangman()
play_hangman("beginner")
play_hangman("easy")
play_hangman("medium")
play_hangman("hard")
play_hangman("expert")
cars <- unique(gsub(" .*", "", rownames(mtcars)))
play_hangman(word_list = cars)
Play a game of jumbles in the console
Description
Play a game of jumbles in the console
Usage
play_jumble(
difficulty = c("beginner", "easy", "medium", "hard", "expert"),
word_list = NULL
)
Arguments
difficulty |
Determines the length of words used for the game and,
if |
word_list |
Optionally, a character vector of words used to play the
game.
If unspecified, a default word list will be used based on |
Value
Generates interactive output in the console.
Difficulty
Difficulty levels are defined as follows:
-
beginner
: very common English words with 3 to 5 letters -
easy
: common English words with 4 to 6 letters -
medium
: slightly less common English words with 5 to 8 letters -
hard
: somewhat less common English words with 6 to 11 letters -
expert
: less common English words with 7 to 15 letters
Problematic words?
You can report any words you find objectionable to https://github.com/rossellhayes/hangman/issues.
Please report:
offensive words
words that deal with uncomfortable topics
proper nouns
text that is not a common English word
Source
The default word list is derived from 12dicts created by Alan Beale.
This word list is passed through the Offensive/Profane Word List created by Luis Von Ahn to filter out potentially unwanted words.
Examples
play_jumble()
play_jumble("beginner")
play_jumble("easy")
play_jumble("medium")
play_jumble("hard")
play_jumble("expert")
cars <- unique(gsub(" .*", "", rownames(mtcars)))
play_jumble(word_list = cars)
Ask a Magic 8 Ball a question in the console
Description
Ask a Magic 8 Ball a question in the console
Usage
play_magic_8_ball(question = NULL, header = rlang::is_interactive())
Arguments
question |
A character string.
Ask the Magic 8 Ball anything your heart desires.
If |
header |
If |
Value
A character string answering your question
.
Examples
play_magic_8_ball("Will I ever find love?")
if (rlang::is_interactive()) play_magic_8_ball()
Play five-card draw poker
Description
Interact with the game by typing commands into the console and pressing enter.
Usage
play_poker(colors = c(2, 4, 1))
Arguments
colors |
One of
|
Value
Generates an interactive game of poker in the console.
Scoring
Hand | Points | Description |
Junk | -10 | Nothing of value. |
Low pair | 0 | Two cards of the same rank, ten or below. |
High pair | 5 | Two aces, kings, queens, or jacks. |
Two pair | 10 | Two cards of one rank and two cards of another. |
Three of a kind | 20 | Three cards of the same rank. |
Straight | 50 | Five cards in sequential order. |
Flush | 75 | Five cards of the same suit. |
Full house | 100 | Three cards of one rank and two cards of another. |
Four of a kind | 1,000 | Four cards of the same rank. |
Straight flush | 50,000 | Five cards of the same suit in sequential order. |
Royal flush | 1,000,000 | Ace, king, queen, jack, and ten of the same suit. |
For straights, aces may be considered the highest card (above king) or the lowest card (below two). However, aces may not be used to connect a king and a two (e.g. Q-K-A-2-3 is not a straight).
Examples
play_poker()
play_poker(colors = 4)
play_poker(colors = 1)
Play a game of rock, paper, scissors in the console
Description
Play a game of rock, paper, scissors in the console
Usage
play_rock_paper_scissors(
selection = c(NA, "rock", "paper", "scissors"),
predict = TRUE,
record_data = rlang::is_interactive(),
animate = rlang::is_interactive(),
header = rlang::is_interactive()
)
Arguments
selection |
Whether to throw rock, paper, or scissors.
Can be abbreviated as "r", "p", or "s".
Defaults to |
predict |
If |
record_data |
If |
animate |
If |
header |
If |
Examples
play_rock_paper_scissors("rock")
if (rlang::is_interactive()) play_rock_paper_scissors()
Play a game of shut the box in the console
Description
Your goal is to flip down all nine tiles numbered from 1 to 9. Each turn, you roll two dice and flip down any number of tiles that add up to the same number as the sum of your dice. After you have flipped down the 7, 8, and 9 tiles, you may choose whether to roll one or two dice. You win the game if you flip down all nine tiles! But if you ever can't flip down a combination of tiles that sums to your die roll, it's game over.
Usage
play_shut_the_box()
Value
Generates interactive output in the console.
Examples
play_shut_the_box()
Play a game of Spelling Bee in the console
Description
Inspired by the New York Times Spelling Bee, created by Sam Ezersky.
Usage
play_spelling_bee()
Value
Generates interactive output in the console.
Problematic words?
You can report any words you find objectionable to https://github.com/rossellhayes/hangman/issues.
Please report:
offensive words
words that deal with uncomfortable topics
proper nouns
text that is not a common English word
Source
The default word list is derived from 12dicts created by Alan Beale.
This word list is passed through the Offensive/Profane Word List created by Luis Von Ahn to filter out potentially unwanted words.
Examples
play_spelling_bee()
Objects exported from other packages
Description
These objects are imported from other packages. Follow the links below to see their documentation.
- twenty48