Discount Gambling

Card Craps Source Code

Posted in card craps by stephenhow on September 5, 2010

The card craps players at Viejas definitely lean towards Don’t Pass now, even when I’m not at the table 🙂 The astute players understand that the game is unlike dice craps, and the rolls aren’t quite independent of each other. Yesterday a Don’t player I’ve never seen before started to lecture me on this point before I could tell him I agreed. Then a young couple came and started playing DP and laying odds, like they knew what was going on. When the regulars are playing, at least half the table plays Don’t.

Anyways, I decided to clean up and post my Java source code for card craps, including the CSM model, the roll window, etc. You can download my source code, inspect the models, experiment with the parameters, and verify my results (+1.5% of the flat bet @ 10x Dont’ Pass odds using 3-roll count for the current Viejas shuffler; -3.6% for 10x odds Pass Line player!). I’m posting the source code to show how simple the CSM effect is on the craps game. I.e., given a simple but accurate model of the CSM, the Don’t Pass edge follows:

package net.discountgambling.cardcraps;

import java.util.Vector;
import java.util.Random;

/**
 *
 * @author show
 */

public class CSM {
    // params approximate the ShuffleMaster 126 model Constant Shuffle Machine
    static final int NUM_SLOTS = 40;
    static final int DICE_SETS = 52;
    static final int MIN_BUFFER_DEPTH = 4;  // minimum cards in chute
    protected Vector[] slot = new Vector[NUM_SLOTS];    // card slots in "wheel"
    protected Vector chute = new Vector();  // cards are dealt from chute
    protected Random random = new Random();

    public CSM() {
        for (int i=0; i<NUM_SLOTS; i++) {
            slot[i] = new Vector();
        }
        // load dice
        for (int i=0; i<DICE_SETS; i++) {
            for (int d=1; d<=6; d++) {
                shuffleCard(d);
            }
        }
    }

    // shuffle roll back into CSM
    public void shuffleRoll(Roll roll) {
        shuffleCard(roll.getDie1());
        shuffleCard(roll.getDie2());
    }

    public Roll dealRoll() {
        return new Roll(dealCard(), dealCard());
    }

    // deal card from chute
    protected int dealCard() {
        // drop a slot if chute is running out of cards
        while (chute.size() < MIN_BUFFER_DEPTH) {
            // select a random slot of cards from the "wheel"
            Vector randomSlot = slot[random.nextInt(NUM_SLOTS)];
            // drop slot of cards into the chute
            chute.addAll(randomSlot);
            randomSlot.clear();
        }
        return (Integer) chute.remove(0);
    }

    // shuffle card into random position of random slot
    protected void shuffleCard(int card) {
        Vector randomSlot = slot[random.nextInt(NUM_SLOTS)];
        if (randomSlot.isEmpty()) {
            randomSlot.add(card);
        } else {
            int randomPosition = random.nextInt(randomSlot.size());
            randomSlot.add(randomPosition, card);
        }
    }
}
 

2 Responses

Subscribe to comments with RSS.

  1. John D. said, on August 3, 2011 at 1:36 pm

    Thanks for the code! I wrote software for this machine as well but I noticed that there are a few discrepancies. Perhaps one of us has made some assumptions that do not reflect how the machine truly works. I am very interested in learning more and fixing my software. Please contact me if you want to discuss this. Thank you, and great site!

    • stephenhow said, on August 3, 2011 at 5:58 pm

      As far as card craps goes, the only important aspect of the shuffler is the buffer in the front of the chute. It’s the delay of the buffer that adds state and dependency between rolls, and makes Don’t Pass +EV. The actual mechanism of the shuffler is unimportant (can be a black box). I’ll email you, but it’s better to keep this thread going if it’s useful for others.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: