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 ORCID iD [aut, cre, cph], Alan Beale [dtc] (Word lists), Kevin Atkinson [dtc] (Word lists), Luis Von Ahn [dtc] (Word lists), Flavia Rossell Hayes [ill], Kristin Bott [ctb] (look_busy() status messages), Daniel Chen ORCID iD [ctb] (look_busy() status messages), Steven Smallberg [ctb] (look_busy() status messages)
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

logo

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:

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 Inf, which runs forever.

speed

How fast to produce output. The default value, 1, takes between 0.1 and 0.5 seconds to produce a calculation and between 1 and 5 seconds to produce a status update.

lambda

Input to a poisson distribution determining how many calculations to perform between each message. Defaults to 3.

background_job

Whether to produce output in in a background job (if TRUE) or the console (if FALSE). Defaults to FALSE. Running in a background process requires the job package.

end

Code to run after minutes. If minutes is Inf, end is never run.

Value

end if minutes is finite.

Author(s)

Alexander Rossell Hayes alexander@rossellhayes.com (ORCID)

With status messages contributed by:

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 NULL, you can choose a game interactively in the console.

...

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 NULL, which interactively asks how many to flip.

animate

If TRUE, play an animation before revealing the result. Defaults to TRUE if the session is interactive and FALSE otherwise.

header

If TRUE, prints a header for the game. Defaults to TRUE if the session is interactive and FALSE otherwise.

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 is NULL, how common the words are

word_list

Optionally, a character vector of words used to play the game. If unspecified, a default word list will be used based on difficulty.

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:

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 is NULL, how common the words are

word_list

Optionally, a character vector of words used to play the game. If unspecified, a default word list will be used based on difficulty.

Value

Generates interactive output in the console.

Difficulty

Difficulty levels are defined as follows:

Problematic words?

You can report any words you find objectionable to https://github.com/rossellhayes/hangman/issues.

Please report:

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 NULL, the default, you will be prompted to type a question interactively in the console.

header

If TRUE, prints a header for the game. Defaults to TRUE if the session is interactive and FALSE otherwise.

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 1, 2, or 4. The number of colors to use to render the suits.

  • For 1, all suits are the default console color.

  • For 2, hearts and diamonds are red and spades and clubs are the default console color.

  • For 4, hearts are red, clubs are green, diamonds are blue, and spades are the default console color.

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 NA, which interactively asks which to throw.

predict

If TRUE, the computer player fits a model on past games to predict what you will throw and try to beat you.

record_data

If TRUE, save data from this game into a file. This data is used for predictions when predict is TRUE. Defaults to TRUE if the session is interactive and FALSE otherwise.

animate

If TRUE, play a "rock, paper, scissors, shoot!" animation before revealing what you and the computer throw. Defaults to TRUE if the session is interactive and FALSE otherwise.

header

If TRUE, prints a header for the game. Defaults to TRUE if the session is interactive and FALSE otherwise.

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:

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

play_2048