January 23rd, 2024 at 5:35:40 PM
permalink

I borrowed the Wizard's original C++ Baccarat analysis program, which he posted on a page titled "Baccarat Analysis", accompanied by a YouTube video explaining it step by step:

.

As you can see at the far bottom of my post, I have made only a few minor changes, which include taking the number of decks in the shoe as user input, and using that single piece of information to calculate everything else. I also changed `int deck_array[10]` to `int deck_array[9]`, because the array begins at index 0 and only 10 elements are required (i.e. 0 through 9).

However, the reason why I am posting this is because I have run into a problem. When I enter any non-zero integer between 2 and 27 inclusive into the input box, the program works exactly as it should. But, when I enter 1 into the input box and run the program, the output box reads:

I have tried for about 3 weeks to resolve this issue, but to no avail. To be honest, I only have less than half a year's worth of experience with programming languages, so the solution may or may not be much simpler than I think it is. Nevertheless, I would greatly appreciate any help or feedback I can get.

Thank you!

As you can see at the far bottom of my post, I have made only a few minor changes, which include taking the number of decks in the shoe as user input, and using that single piece of information to calculate everything else. I also changed `int deck_array[10]` to `int deck_array[9]`, because the array begins at index 0 and only 10 elements are required (i.e. 0 through 9).

However, the reason why I am posting this is because I have run into a problem. When I enter any non-zero integer between 2 and 27 inclusive into the input box, the program works exactly as it should. But, when I enter 1 into the input box and run the program, the output box reads:

Floating point exception

I have tried for about 3 weeks to resolve this issue, but to no avail. To be honest, I only have less than half a year's worth of experience with programming languages, so the solution may or may not be much simpler than I think it is. Nevertheless, I would greatly appreciate any help or feedback I can get.

Thank you!

#include <iostream>

#include <cstdio>

using namespace std;

int main() {

int p1, p2, p3, b1, b2, b3, ptot, btot, num_decks, deck_array[9];

std::cin >> num_decks;

deck_array[0] = 16 * num_decks;

for (int k = 1; k <= 9; k++) {

deck_array[k] = 4 * num_decks;

}

long long combin = 1, player_win = 0, banker_win = 0, tie_win = 0;

for (p1 = 0; p1 <= 9; p1++) {

combin *= deck_array[p1];

deck_array[p1]--;

for (p2 = 0; p2 <= 9; p2++) {

combin *= deck_array[p2];

deck_array[p2]--;

for (p3 = 0; p3 <= 9; p3++) {

combin *= deck_array[p3];

deck_array[p3]--;

for (b1 = 0; b1 <= 9; b1++) {

combin *= deck_array[b1];

deck_array[b1]--;

for (b2 = 0; b2 <= 9; b2++) {

combin *= deck_array[b2];

deck_array[b2]--;

for (b3 = 0; b3 <= 9; b3++) {

combin *= deck_array[b3];

ptot = (p1 + p2) % 10;

btot = (b1 + b2) % 10;

if ((ptot < 8) && (btot < 8)) {

if (ptot <= 5) {

ptot = (p1 + p2 + p3) % 10;

if ((btot <= 2) || ((btot == 3) && (p3

!= 8)) || ((btot == 4) && (p3 >= 2)

&& (p3 <= 7)) || ((btot == 5) && (p3

>= 4) && (p3 <= 7)) || ((btot == 6)

&& (p3 >= 6) && (p3 <= 7))) {

btot = (b1 + b2 + b3) % 10;

}

} else {

if (btot <= 5) {

btot = (b1 + b2 + b3) % 10;

}

}

}

if (ptot > btot) {

player_win += combin;

} else if (ptot < btot) {

banker_win += combin;

} else {

tie_win += combin;

}

combin /= deck_array[b3];

}

deck_array[b2]++;

combin /= deck_array[b2];

}

deck_array[b1]++;

combin /= deck_array[b1];

}

deck_array[p3]++;

combin /= deck_array[p3];

}

deck_array[p2]++;

combin /= deck_array[p2];

}

deck_array[p1]++;

combin /= deck_array[p1];

}

long long tot_combin = player_win + banker_win + tie_win;

printf("Player win combinations = \t%lld\n", player_win);

printf("Banker win combinations = \t%lld\n", banker_win);

printf("Tie win combinations = \t%lld\n", tie_win);

std::cout << std::endl;

double player_prob = (double)player_win / (double)tot_combin;

double banker_prob = (double)banker_win / (double)tot_combin;

double tie_prob = (double)tie_win / (double)tot_combin;

printf("Player win probability = \t%f\n", player_prob);

printf("Banker win probability = \t%f\n", banker_prob);

printf("Tie win probability = \t%f\n", tie_prob);

std::cout << std::endl;

double player_ev = player_prob - banker_prob;

double banker_ev = 0.95 * banker_prob - player_prob;

double tie_ev = 8 * tie_prob - player_prob - banker_prob;

printf("Player expected value = \t%f\n", player_ev);

printf("Banker expected value = \t%f\n", banker_ev);

printf("Tie expected value = \t%f\n", tie_ev);

return 0;

}

January 23rd, 2024 at 6:45:37 PM
permalink

I don't know why it's throwing a "floating point" error, but I can see the problem with using one deck. If exactly four of the six values of p1, p2, p3, b1, b2, and b3 are the same nonzero number, and one of them is b3, then when you decrement deck_array[ ] for each one, deck_array[b3] will be zero, and you are dividing combin by deck_array[b3], which should throw some sort of divide by zero error.

You will get the same problem if five are the same, but the error will be in a different place, as you will eventually get -1 for that deck_array element, and then you will increment it back to zero before trying to divide by it.

It is not a problem with 2 or more decks as each deck_array element begins with at least 8, and the most you subtract from any one is 6.

You are also not taking into account the possibility that you are trying to deal five or six cards of the same nonzero value from a deck that has only four of them.

You will get the same problem if five are the same, but the error will be in a different place, as you will eventually get -1 for that deck_array element, and then you will increment it back to zero before trying to divide by it.

It is not a problem with 2 or more decks as each deck_array element begins with at least 8, and the most you subtract from any one is 6.

You are also not taking into account the possibility that you are trying to deal five or six cards of the same nonzero value from a deck that has only four of them.

January 23rd, 2024 at 7:16:47 PM
permalink

Let me explain this part towards the beginning of my code:

The total number of individual cards in the shoe worth 0 points (10, J, Q, K) is equal to 16 (4 ranks and 4 suits) times the number of decks in the shoe. Additionally, for all other individual cards worth 1 point or their respective face-values (A, 2, 3, 4, 5, 6, 7, 8, 9), there are 4 (1 rank and 4 suits) times the number of decks in the shoe.

16 + (4 * 9) = 16 + 36 = 52

deck_array[0] = 16 * num_decks;

for (int k = 1; k <= 9; k++) {

deck_array[k] = 4 * num_decks;

}

The total number of individual cards in the shoe worth 0 points (10, J, Q, K) is equal to 16 (4 ranks and 4 suits) times the number of decks in the shoe. Additionally, for all other individual cards worth 1 point or their respective face-values (A, 2, 3, 4, 5, 6, 7, 8, 9), there are 4 (1 rank and 4 suits) times the number of decks in the shoe.

16 + (4 * 9) = 16 + 36 = 52

January 23rd, 2024 at 7:36:21 PM
permalink

I understand that.

What you seem to be missing is, if there is one deck, your code still has the possibility of p1, p2, p3, b1, b2, and b3 all being 1, which is impossible as you cannot deal six aces from a single deck.

(Actually, your code handles that, sort of; something like this would make combin = 0. The problem is, since you are subsequently multiplying and dividing combin by something to get the new combin values, once it gets to zero, it will always be zero.)

If you don't see the problem, then assume your loops are at the point where p1 = 0, and p2, p3, b1, b2, and b3 are all 1. What is deck_array[b3] at this point - and what happens when you get to "combin /= deck_array[b3]"?

Another thing that surprises me: I haven't done that much coding in C++ - it didn't exist in my college days - but every online C++ language definition I have seen says that if you define an array to be size 9, you should only be able to access elements 0 through 8. The only language I have seen where defining an array of size N actually includes elements from 0 to N is Visual Basic.

What C++ compiler are you running your code on?

What you seem to be missing is, if there is one deck, your code still has the possibility of p1, p2, p3, b1, b2, and b3 all being 1, which is impossible as you cannot deal six aces from a single deck.

(Actually, your code handles that, sort of; something like this would make combin = 0. The problem is, since you are subsequently multiplying and dividing combin by something to get the new combin values, once it gets to zero, it will always be zero.)

If you don't see the problem, then assume your loops are at the point where p1 = 0, and p2, p3, b1, b2, and b3 are all 1. What is deck_array[b3] at this point - and what happens when you get to "combin /= deck_array[b3]"?

Another thing that surprises me: I haven't done that much coding in C++ - it didn't exist in my college days - but every online C++ language definition I have seen says that if you define an array to be size 9, you should only be able to access elements 0 through 8. The only language I have seen where defining an array of size N actually includes elements from 0 to N is Visual Basic.

What C++ compiler are you running your code on?

January 23rd, 2024 at 9:21:01 PM
permalink

I'm using an online compiler called Programiz.

- Jump to:
DEFUNCT CASINOS Bill's Gambling Hall & Saloon MonteLago O'Sheas Sahara Western FORUM INFO Announcements Help Rules GAMBLING Betting Systems Big Wins Blackjack Craps Dice Setting Gambling with an Edge Online Gambling Other Games Poker Slots Sports Betting Table Games Trip Reports Video Poker GAMBLING OUTSIDE VEGAS Asia Atlantic City California Eastern U.S. Europe/Africa Mississippi Nevada (other) Oceania The Americas Western U.S. GAMING BUSINESS Boyd Gaming Caesars Entertainment Game Inventors Corner MGM/Mirage Other Sands Station Casinos Wynn LAS VEGAS ATTRACTIONS Deals Food and Restaurants Night Clubs Other Attractions/Entertainment Relaxation and Rejuvenation Shopping Shows Strip Clubs Thrill Seeking LAS VEGAS CASINOS Aliante Casino Aria Arizona Charlie's Casinos Bally's Barcelona Bellagio Binion's Boyd Gaming Casinos Caesars Palace Cannery Casinos Casino Royale Casuarina Circus Circus Cosmopolitan D Las Vegas El Cortez Ellis Island Excalibur Flamingo Four Queens Golden Gate Golden Nugget Hard Rock Hilton Hooters Jean/Primm Casinos Longhorn Casino Luxor M Mandalay Bay MGM Grand Mirage Monte Carlo New York, New York Palms Paris Planet Hollywood Plaza Poker Palace Quad, The Rampart Rio Riviera Silver Nugget Silver Sevens Silverton Skyline Small Casinos South Point Station Casinos Stratosphere Treasure Island Tropicana Tuscany Vegas Club Venetian and Palazzo Wynn and Encore OFF-TOPIC Adult Discussions Free Speech Zone General Discussion GLBT Corner Gripes Kiosk Off-Topic Other Casinos Religion QUESTIONS AND ANSWERS Advice All Other Casual Corner Gambling Las Vegas (other than gambling) Math