Skip to content

Commit

Permalink
Initial snapshot.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhow committed Jun 17, 2012
0 parents commit 08160bc
Show file tree
Hide file tree
Showing 10 changed files with 653 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
*.o
sevenUp

8 changes: 8 additions & 0 deletions Makefile
@@ -0,0 +1,8 @@
OBJS = main.o baccarat7up.o mersenne64.o averager.o
CC = g++
CPPFLAGS = -Wall -O3
CFLAGS = -Wall -O3 -c
LFLAGS = -Wall $(DEBUG)

sevenUp : $(OBJS)
$(CC) $(LFLAGS) $(OBJS) -o sevenUp
7 changes: 7 additions & 0 deletions README
@@ -0,0 +1,7 @@
Examples:

Run with minBufferDepth of 16, and print out Super-7's EV vs. Windowed Count stats
>./sevenUp -m16 -v2

Run with minBufferDepth of 30, and windowSize of 30
>./sevenUp -m30 -w30
15 changes: 15 additions & 0 deletions averager.cpp
@@ -0,0 +1,15 @@
#include "averager.h"

Averager::Averager() {
samples = 0;
net = 0;
}

void Averager::addSample(double value) {
net += value;
samples++;
}

double Averager::getMean() {
return net/(double)samples;
}
14 changes: 14 additions & 0 deletions averager.h
@@ -0,0 +1,14 @@
#ifndef AVERAGER_H
#define AVERAGER_H

class Averager {
protected:
unsigned long samples;
double net;
public:
Averager();
void addSample(double);
double getMean();
};

#endif
177 changes: 177 additions & 0 deletions baccarat7up.cpp
@@ -0,0 +1,177 @@
#include "baccarat7up.h"

Hand::Hand() : vector<int>() {
}

int Hand::getTotal() {
int total=0;
for (vector<int>::iterator iter=this->begin(); iter!=this->end(); iter++) {
total += *iter;
}
return (total%10);
}

bool Hand::isNatural() {
return (this->size() == 2) && (this->getTotal() >= 8);
}

// assume banker empty, player initialized with a 7
void Rules7Up::deal(Hand &player, Hand &banker, CSM &shoe) {
// deal 1st banker card
banker.push_back(shoe.deal());
// deal 2nd player card
player.push_back(shoe.deal());
// deal 2nd banker card
banker.push_back(shoe.deal());
if (!player.isNatural() && !banker.isNatural()) {
if (player.getTotal() <= 5) {
// player draws
player.push_back(shoe.deal());
}
if (player.size() == 2) {
// player did not draw
if (banker.getTotal() <= 5) {
// banker draws
banker.push_back(shoe.deal());
}
} else {
// player drew
int playerDraw = player[2];
switch (banker.getTotal()) {
case 0: case 1: case 2:
banker.push_back(shoe.deal());
break;
case 3:
if (playerDraw != 8) {
banker.push_back(shoe.deal());
}
break;
case 4:
if ((playerDraw >= 2) && (playerDraw <= 7)) {
banker.push_back(shoe.deal());
}
break;
case 5:
if ((playerDraw >= 4) && (playerDraw <= 7)) {
banker.push_back(shoe.deal());
}
break;
case 6:
if ((playerDraw >= 6) && (playerDraw <= 7)) {
banker.push_back(shoe.deal());
}
break;
}
}
}
}

double Rules7Up::playerOutcome(Hand &player, Hand &banker) {
int playerTotal = player.getTotal();
int bankerTotal = banker.getTotal();
if (playerTotal > bankerTotal) {
return (playerTotal == 7 ? 0.5 : 1.0);
} else if (playerTotal < bankerTotal) {
return -1;
} else {
return 0;
}
}

double Rules7Up::bankerOutcome(Hand &player, Hand &banker) {
int playerTotal = player.getTotal();
int bankerTotal = banker.getTotal();
if (bankerTotal > playerTotal) {
return (bankerTotal == 7 ? 1.8 : 1.0);
} else if (bankerTotal < playerTotal) {
return -1;
} else {
return 0;
}
}

double Rules7Up::super7s(Hand &player, Hand &banker) {
int sevens=0;
for (vector<int>::iterator iter=player.begin(); iter!=player.end(); iter++) {
if (*iter == 7) sevens++;
}
for (vector<int>::iterator iter=banker.begin(); iter!=banker.end(); iter++) {
if (*iter == 7) sevens++;
}
switch (sevens) {
case 6: return 700;
case 5: return 70;
case 4: return 17;
case 3: return 5;
case 2: return 2;
default: return -1;
}
}

CSM::CSM(int minDepth) {
minBufferDepth = minDepth;
minBufferDepth = minDepth;
for (int i=0; i<6; i++) {
for (int j=1; j<=9; j++) {
for (int k=0; k<4; k++) reservoir.push_back(j);
}
for (int k=0; k<16; k++) reservoir.push_back(0);
}
}

int CSM::deal() {
int card, pos;
while (buffer.size() < 1+minBufferDepth) {
pos = reservoir.size()*random.genrand64_real2();
buffer.insert(buffer.end(), reservoir[pos]);
reservoir.erase(reservoir.begin()+pos);
}
card = buffer[0];
buffer.erase(buffer.begin());
return card;
}

void CSM::muck(int card) {
reservoir.push_back(card);
}

ShuffleMaster126::ShuffleMaster126(int minDepth, int maxDepth) : CSM(minDepth) {
maxCardsPerSlot = maxDepth;
// shuffle in 6 decks
for (int i=0; i<6; i++) {
for (int j=1; j<=9; j++) {
for (int k=0; k<4; k++) muck(j);
}
for (int k=0; k<16; k++) muck(0);
}
}

void ShuffleMaster126::muck(int card) {
int slotNum, pos;
// get random slot
slotNum = NUM_SLOTS*random.genrand64_real2();
while (slots[slotNum].size() > maxCardsPerSlot) {
slotNum = NUM_SLOTS*random.genrand64_real2();
}
// insert card into random position in slot
pos = slots[slotNum].size()*random.genrand64_real2();
slots[slotNum].insert(slots[slotNum].begin()+pos,card);
}

int ShuffleMaster126::deal() {
int card;
while (buffer.size() < (1+minBufferDepth)) {
dropSlot();
}
card = buffer[0];
buffer.erase(buffer.begin());
return card;
}

void ShuffleMaster126::dropSlot() {
// get random slot
int slotNum = NUM_SLOTS*random.genrand64_real2();
// drop into buffer
buffer.insert(buffer.end(), slots[slotNum].begin(), slots[slotNum].end());
slots[slotNum].clear();
}
49 changes: 49 additions & 0 deletions baccarat7up.h
@@ -0,0 +1,49 @@
#ifndef BACCARAT_7UP_H
#define BACCARAT_7UP_H

#include <vector>
#include "mersenne64.h"

using namespace std;

#define NUM_SLOTS 40

class Hand : public vector<int> {
public:
Hand();
int getTotal();
bool isNatural();
};

class CSM {
protected:
Mersenne64 random;
vector<int> buffer;
int minBufferDepth;
vector<int> reservoir;
public:
CSM(int);
virtual int deal();
virtual void muck(int);
};

class ShuffleMaster126 : public CSM {
protected:
vector<int> slots[NUM_SLOTS];
void dropSlot();
int maxCardsPerSlot;
public:
ShuffleMaster126(int minDepth, int maxDepth);
virtual int deal();
virtual void muck(int);
};

class Rules7Up {
public:
static void deal(Hand &player, Hand &banker, CSM &shoe);
static double bankerOutcome(Hand &player, Hand &banker);
static double playerOutcome(Hand &player, Hand &banker);
static double super7s(Hand &player, Hand &banker);
};

#endif

0 comments on commit 08160bc

Please sign in to comment.