Как мне найти правильные вероятности для расстрела среднего игрока в блэкджеке?

Я хотел бы иметь возможность найти скорость вылетов для среднего игрока в блэкджек. Правильные значения можно найти на следующем веб-сайте: http://www.blackjackage.com/bust-out-rate.php

Чтобы добиться этого, я реализовал карту и класс колод, который отвечает за раздачу карт и перетасовку. В главном файле cards.cpp я создал отдельную функцию под названием probabilities () с порогом параметров и итерациями. Пороговое значение будет изменяться от 10 до 20, что будет определять, какого общего количества очков игрок должен достичь, прежде чем уничтожить. Итерации будут определять, сколько раз я хотел бы повторить это, чтобы найти, как часто игрок перебивает, прежде чем достигнуть порога.
Вот мои вероятности на порог:
10: 0,6577
11: 0,849
12: 0,8942
13: 0,8955
14: 0,8777
15: 0,8531
16: 0,8714
17: 0,872
18: 0,8799
19: 0,8443
20: 0,8011
По сравнению со значениями, найденными на сайте, они очень отключены. Кто-то может указать, что я делаю неправильно в моей функции вероятностей?

Основной файл:

#include "deck.h"using namespace std;

int chooseRand(int a, int b){
srand(time(NULL));
int r = rand()%2;
if(r==0) return a;
else return b;
}

int probabilities(int threshold, int iterations){
Deck deck;
deck.shuffle();
Card currentCard;
int cardVal = 0;
int cardSum = 0;
int bust = 0;
int stand = 0;

for(int i = 0; i<iterations; i++){
for(int j = 0; j<iterations && cardSum<threshold; j++){
currentCard = deck.dealCard(); //
cardVal = currentCard.getVal();
if(deck.remainingCards() < 1) deck.shuffle();
if(cardSum < threshold){
if(cardVal != 1 && cardVal != 11 && cardVal != 12 && cardVal != 13) cardSum += cardVal;
else if(cardVal == 1) cardSum += chooseRand(1,11);
else if((cardVal == 11 || cardVal == 12 || cardVal == 13) && cardSum < threshold) cardSum += 10;
}
else break;
}
if(cardSum > threshold)bust++; cardSum = 0;
}
return (float)(bust);
}

int main(){
Deck deck;
Card currentCard;
int iterations = 10000;
for(int i = 10; i<=20; i++){
cout<<i<<": "<<(float)(probabilities(i, iterations)/10000.0)<<endl;
}
return 0;
}

deck.h

#ifndef DECK_H
#define DECK_H
#include "card.h"#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;

const int NUM_CARDS_DECK = 52;

class Deck
{
public:
Deck();
Card dealCard();
void shuffle();
void printDeck() const;
int remainingCards();
private:
Card *deck; //Create a dynamically allocated array of cards
int currentCard;
int remainCardCount;

};

Deck::Deck(){
string faces[] = {"Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten", "Jack", "Queen", "King"};
string suits[] = {"Hearts", "Diamonds", "Clubs", "Spades"};
*/

int faces[] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
int suits[] = {1, 2, 3};
deck = new Card[NUM_CARDS_DECK];
currentCard = 0;
//Now fill up the card array with values
for(int i = 0; i<NUM_CARDS_DECK; i++){
deck[i] = Card(faces[i%13], suits[i/13]);
}

}

void Deck:: printDeck() const{
cout<<left;
for(int i = 0; i<NUM_CARDS_DECK; i++){
cout<<setw(19)<<deck[i].print();
if((i+1)%4 == 0){
cout<<endl;
}
}
}

void Deck::shuffle(){
currentCard = 0;
for(int i = 0; i<NUM_CARDS_DECK; i++){
int j = (rand() + time(0)) % NUM_CARDS_DECK;
Card temp = deck[i];
deck[i] = deck[j];
deck[j] = temp;
}
}

int Deck::remainingCards(){
return remainCardCount;
}

Card Deck::dealCard(){
remainCardCount = 52;
if(currentCard > NUM_CARDS_DECK){
shuffle();
remainCardCount = 0;
}
if(currentCard < NUM_CARDS_DECK){
remainCardCount = 51-currentCard;
return (deck[currentCard++]);
}
return(deck[0]);
}

#endif

card.h

#ifndef CARD_H
#define CARD_H
#include <string>
#include <iostream>

using namespace std;

class Card{
public:
Card(int cardNum, int cardSuit);
int getVal();//For blackjack
string print() const;
Card();
private:
int num;
int suit;
};

Card::Card(){}
Card::Card(int cardNum, int cardSuit){
num = cardNum;
suit = cardSuit;
}

int Card::getVal(){
return num;
}

string Card::print() const{
return (to_string(num) + "of" + to_string(suit));
}

#endif

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …