knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/"
)

set.seed(101315)

casino

Welcome to the casino, we've got fun and games

We got everything you want and we know your name

We are a place where you can find whatever you may need

And if you got no money, don't worry! You can play for "free"!

CRAN status CRAN downloads

Overview

Play casino games in the R console!

Available games:

Installation

# Install the CRAN version
install.packages("casino")

# Install development version from GitHub
devtools::install_github("anthonypileggi/casino")

Quick Start

Are you getting impatient already? Then use play() to get started immediately.

casino::play()

Setup (.casino)

All players must agree to our policies on recording activity. If you do not agree, you cannot play. House rules!

library(casino)

# create a local file for storing persisent player data
setup()

This allows us to store player information persistently between games and R sessions.

Create a Player

You can create a new player manually.

# Create a new player
Player$new(name = "Player 1")

# View all available player profiles
players()

Or just start playing, and one will automatically be created for you.

# Start a new game (this will auto-create a player)
Blackjack$new(who = "Player 2")

# View all available player profiles (again)
players()

Play Casino Games

Now it's time to head off to the casino! What do you want to play first?!

Poker (5-card stud)

x <- Poker$new(who = "Player 1", type = "stud", bet = 10)

# play a game
x$play()

# specify a different bet for this game
x$play(bet = 5)

Poker (5-card draw)

x <- Poker$new(who = "Player 1", type = "draw", bet = 20)

# play a game
x$play()

x$hold(1, 2, 5)    # hold cards in positions {1, 2, 5}

x$draw()           # draw new cards for positions {3, 4}

Blackjack

x <- Blackjack$new(who = "Player 1", bet = 25)

x$play()$stand()

Slot Machine

x <- Slots$new(who = "Player 1", bet = 1)

x$play()

# set the `spins` argument to play > 1 game at a time
x$play(spins = 2)

I think I have a gambling problem

If you want to play a lot of games, you can write a script.
Just make sure to silence the output (verbose = FALSE) and sounds (sound = FALSE).

# poker (stud)
x <- Poker$new(who = "Player 1", type = "stud", bet = 10, verbose = FALSE, sound = FALSE)
for (i in 1:50) 
  suppressMessages(x$play())

# blackjack (blind)
x <- Blackjack$new(who = "Player 1", bet = 5, verbose = FALSE, sound = FALSE)
for (i in 1:50) {
  suppressMessages(x$play())
  if (x$active)
    x$stand()
}

# penny slots
x <- Slots$new(who = "Player 1", bet = 1, verbose = FALSE, sound = FALSE)
suppressMessages(x$play(spins = 50))

Ok, now I lost everything...

If you run out of money, the Bank will immediately loan you 100.

You: "So, what's the interest rate on this loan?"
Bank: "Oh, don't worry. It's very reasonable..."

Wait, how much did you say I owe?

# player profile is stored in `$who` of a game object
player <- x$who

player$debt()

It's closing time...

What a fun day at the casino! Or, was it?

# player profile is stored in `$who` of a game object
player <- x$who

# Overall
player$summary()

# By Game
player$summary(game)  

Let's relive the excitement!

player$plot()

Well, I guess we'll you'll be back tomorrow. See you then!

# clean-up player information created while compiling readme
delete()


anthonypileggi/casino documentation built on May 16, 2019, 4:54 p.m.