MyNixOS website logo
Description

Play Casino Games.

Play casino games in the R console, including poker, blackjack, and a slot machine. Try to build your fortune before you succumb to the gambler's ruin!

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"!

Overview

Play casino games in the R console!

Available games:

  • Poker (5-card draw/stud)
  • Blackjack
  • Slot machine

Installation

# 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()
#> No records found.
#> Storing player records at '/Users/anthony/Documents/casino/.casino'
#> Updating value for environment variable 'CASINO_FILE'.

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")
#> You have no money!
#> Player: 
#>   Name: Player 1
#>   Balance:  100
#>   Level:  0
#>   Played:  1
#>   Debt:  100

# View all available player profiles
players()
#> # A tibble: 1 x 2
#>   name     balance   
#>   <chr>    <chr>     
#> 1 Player 1 100.000000

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")
#> You have no money!
#> Blackjack (w/  1  decks): 
#> Player: Player 2
#> Bank: 100
#> Start a new game with `play()`.

# View all available player profiles (again)
players()
#> # A tibble: 2 x 2
#>   name     balance   
#>   <chr>    <chr>     
#> 1 Player 1 100.000000
#> 2 Player 2 100.000000

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)
#> Loading player profile...

# play a game
x$play()
#> You bet 10; you have 90 left.
#>  Hand: 2 ♦, 3 ♦, A ♠, 3 ♥, K ♦
#>  Result: one pair
#>    You lost -10!
#>    Now you have 90 in your account.
#> Do you want to `play()` again?

# specify a different bet for this game
x$play(bet = 5)
#> You bet 5; you have 85 left.
#>  Hand: 10 ♦, J ♣, J ♠, Q ♠, 9 ♣
#>  Result: one pair (jacks or better)
#>    You won 0!
#>    Now you have 90 in your account.
#> Do you want to `play()` again?

Poker (5-card draw)

x <- Poker$new(who = "Player 1", type = "draw", bet = 20)
#> Loading player profile...

# play a game
x$play()
#> You bet 20; you have 70 left.
#>  Hand: 2 ♠, 3 ♥, 3 ♠, 6 ♦, 8 ♦
#> Choose cards to `hold()`` and then `draw()`.

x$hold(1, 2, 5)    # hold cards in positions {1, 2, 5}
#>  Hand: 2 ♠, 3 ♥, 3 ♠, 6 ♦, 8 ♦
#> Choose cards to `hold()`` and then `draw()`.

x$draw()           # draw new cards for positions {3, 4}
#>  Hand: 2 ♠, 3 ♥, 8 ♦, K ♦, 7 ♣
#>  Result: K high
#>    You lost -20!
#>    Now you have 70 in your account.
#> Do you want to `play()` again?

Blackjack

x <- Blackjack$new(who = "Player 1", bet = 25)
#> Loading player profile...

x$play()$stand()
#> You bet 25; you have 45 left.
#>  Player Hand: {7, A} = 18
#>  Dealer Hand: {?, A} = ?
#> Will you `hit()` or `stand()`?
#> Game over! push
#>   You won 0!
#>   Now you have 70 in your account.

Slot Machine

x <- Slots$new(who = "Player 1", bet = 1)
#> Loading player profile...

x$play()
#> You bet 1; you have 69 left.
#>  Reels: & & *
#>    You lost -1!
#>    Now you have 69 in your account.
#> Do you want to `play()` again?

# set the `spins` argument to play > 1 game at a time
x$play(spins = 2)
#> You bet 1; you have 68 left.
#>  Reels: * & ^
#>    You lost -1!
#>    Now you have 68 in your account.
#> You bet 1; you have 67 left.
#>  Reels: * ^ %
#>    You lost -1!
#>    Now you have 67 in your account.
#> Do you want to `play()` again?

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)
#> Loading player profile...
for (i in 1:50) 
  suppressMessages(x$play())

# blackjack (blind)
x <- Blackjack$new(who = "Player 1", bet = 5, verbose = FALSE, sound = FALSE)
#> Loading player profile...
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)
#> Loading player profile...
suppressMessages(x$play(spins = 50))
#> Do you want to `play()` again?

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()
#> [1] 300

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()
#> # A tibble: 1 x 4
#>   games   bet   win   net
#>   <int> <dbl> <dbl> <dbl>
#> 1   157   739   566  -173

# By Game
player$summary(game)  
#> # A tibble: 3 x 5
#>   game      games   bet   win   net
#>   <chr>     <int> <dbl> <dbl> <dbl>
#> 1 Blackjack    51   275   245   -30
#> 2 Poker        53   411   204  -207
#> 3 Slots        53    53   117    64

Let's relive the excitement!

player$plot()

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

Metadata

Version

0.1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows