ionut.hulub Posted March 19, 2012 Report Posted March 19, 2012 Am facut ieri un program care joaca un anumit numar de maini (specificat de utilizator) de blackjack dupa criterii specificate de utilizator. Mai exact programul inumara cartile, ca in filmul 21, si l'am facut ca sa testez cat de bine merge sistemul. Optii un edge de 1% pe casa cu sistemul hi-lo care este incarcat in program automat(poate fi inlocuit modificand fisierele text), si am reusit sa obtin un edge de 1.5% jucand doar mainile care au "count-ul pozitiv".Ca sa modificati criteriile dupa care alege sa dea hit/stand/double/split modificati fisierul strategy.txt;Ca sa modificati cate puncte valoareaza fiecare carte modificati points.txt;Ca sa modificati cate maini sa joace si cat sa fie bankroll-ul de plecare modificati info.txt; Recomand sa nu specificati un bankroll de plecare mai mare de 10k sau pot aparea erori dupa un numar de cateva sute de mii de maini jucate.Ca sa simulati 1 milion de maini poate dura pana la 3 ore... cam 1.5h pe un sistem bun.Am incarcat arhiva cu programul compilat si mai jos sunt fisierele sursa:Download:21.rar download - 2sharedFisiere sursa:bet.h#ifndef BET_H#define BET_H#include "bankroll.h"#include "pachet.h"using namespace std;class Bet{ int betAmount; Bankroll *bankroll; Pachet *pachet;public: Bet(Bankroll *bankrollToUse, Pachet *pachetToUse) { bankroll = bankrollToUse; pachet = pachetToUse; } void start() { betAmount = bankroll->bettingUnit(); cout<<"[*]Bet is: "<<betAmount<<endl<<endl; if(pachet->count()/pachet->pacheteRamase() > 1) betAmount *= (pachet->count()/pachet->pacheteRamase()) - 1; } void doubleBet() { betAmount = betAmount*2; } int betSize() { int amount = betAmount; betAmount = 0; return amount; }};#endifbankroll.h#ifndef BANKROLL_H#define BANKROLL_Hclass Bankroll{ long long int bankroll;public: Bankroll(int amount) { bankroll = amount; } void add(int amount) { bankroll += amount; } void substract(int amount) { bankroll -= amount; } int bettingUnit() { if(bankroll > 999) return bankroll/1000; else return 1; } int value() { return bankroll; }};#endifplayer.h#ifndef PLAYER_H#define PLAYER_H#include "bet.h"#include "pachet.h"using namespace std;class Player{private: int maini[100]; int nrMaini; int suma; Pachet *pachet; Bet *bet; int carti[22]; int nrCarti;public: Player(Pachet *pachetComun, Bet *betAmount){ pachet = pachetComun; bet = betAmount; nrMaini = 0; } void playHand(int startingCardOne, int startingCardTwo, int dealerCard, int chart1[18][12], int chart2[11][12], int chart3[12][12]) { if(dealerCard == 20) dealerCard = 10; carti[0] = startingCardOne; carti[1] = startingCardTwo; bool cont, busted; int nrAsi, sumaNoua, aux; nrCarti = 2; if((carti[0] == 20 && carti[1] == 11) || (carti[0] == 11 && carti[1] == 20)) { maini[nrMaini++] = 42; cout<<"Player stops. Blackjack!"<<endl; return; } if(carti[0] == 20) carti[0] -= 10; if(carti[1] == 20) carti[1] -= 10; suma = carti[0] + carti[1]; //check if player has pair: if(carti[0] == carti[1]) switch(chart3[carti[0]][dealerCard]) { case 1: maini[nrMaini++] = suma; cout<<"Player stands at "<<suma<<endl; return; case 2: carti[nrCarti++] = pachet->dealCard(); if(carti[nrCarti-1] == 20) carti[nrCarti-1] -= 10; suma+=carti[nrCarti-1]; cout<<"Player hits a "<<carti[nrCarti-1]<<endl;break; case 3: cout<<"Player is doubling the bet!"<<endl;bet->doubleBet(); carti[nrCarti++] = pachet->dealCard(); if(carti[nrCarti-1] == 20) carti[nrCarti-1] -= 10; suma+=carti[nrCarti-1]; cout<<"Player hits a "<<carti[nrCarti-1]<<endl<<"Player stands at "<<suma<<endl;maini[nrMaini++] = suma; return; case 4: playHand(startingCardOne, pachet->dealCard(), dealerCard, chart1, chart2, chart3); playHand(startingCardTwo, pachet->dealCard(), dealerCard, chart1, chart2, chart3); return; } do{ busted = 1; nrAsi = 0; for(int i = 0; i < nrCarti; i++) if (carti[i] == 11) nrAsi++; cont = false; for (int i = 0; i < nrAsi; i++) { sumaNoua = suma - i*10; if (sumaNoua < 22) { busted = 0; switch(chart2[sumaNoua][dealerCard]) { case 1: maini[nrMaini++] = sumaNoua; cout<<"Player stands at "<<sumaNoua<<endl; return; case 2: carti[nrCarti++] = pachet->dealCard(); if(carti[nrCarti-1] == 20) carti[nrCarti-1] -= 10; suma+=carti[nrCarti-1]; cont = true; cout<<"Player hits a "<<carti[nrCarti-1]<<endl; case 3: if(nrCarti != 2) { carti[nrCarti++] = pachet->dealCard(); if(carti[nrCarti-1] == 20) carti[nrCarti-1] -= 10; suma+=carti[nrCarti-1]; cont = true; cout<<"Player hits a "<<carti[nrCarti-1]<<endl; } else { cout<<"Player is doubling the bet!"<<endl; bet->doubleBet(); carti[nrCarti++] = pachet->dealCard(); cout<<"Player hits a "<<carti[nrCarti-1]; if(carti[nrCarti-1] == 20 || (carti[nrCarti-1] == 11 && suma == 11)) carti[nrCarti-1] -= 10; suma+=carti[nrCarti-1]; cout<<endl<<"Player stands at "<<suma<<endl; maini[nrMaini++] = suma; return; } } } } if(cont) continue; suma = 0; for (int i = 0; i < nrCarti; i++) { if (carti[i] == 11) carti[i] = 1; suma += carti[i]; } if(suma < 22) { aux = suma; if(aux > 17) aux = 17; busted = 0; switch(chart1[aux][dealerCard]) { case 1: maini[nrMaini++] = suma; cout<<"Player stands at "<<suma<<endl; return; case 2: carti[nrCarti++] = pachet->dealCard(); if(carti[nrCarti-1] == 20) carti[nrCarti-1] -= 10; suma+=carti[nrCarti-1]; cout<<"Player hits a "<<carti[nrCarti-1]<<endl; break; case 3: if(nrCarti != 2) { carti[nrCarti++] = pachet->dealCard(); if(carti[nrCarti-1] == 20) carti[nrCarti-1] -= 10; suma+=carti[nrCarti-1]; cout<<"Player hits a "<<carti[nrCarti-1]<<endl; break; } else { cout<<"Player is doubling the bet!"<<endl; bet->doubleBet(); carti[nrCarti++] = pachet->dealCard(); cout<<"Player hits a "<<carti[nrCarti-1]; if(carti[nrCarti-1] == 20 || (carti[nrCarti-1] == 11 && suma == 11)) carti[nrCarti-1] -= 10; suma+=carti[nrCarti-1]; cout<<endl<<"Player stands at "<<suma<<endl; maini[nrMaini++] = suma; return; } } } else { cout<<"Player stands at "<<suma<<endl; maini[nrMaini++] = suma; } }while(!busted); } int* addr() { return maini; } int handsPlayed() { int maini = nrMaini; nrMaini = 0; return maini; }};#endifdealer.h#ifndef DEALER_H#define DEALER_H#include "pachet.h"using namespace std;class Dealer{ int suma; Pachet *pachet; int carti[22]; int nrCarti;public: Dealer(Pachet *pachetComun){ pachet = pachetComun; } int playHand(int startingCardOne, int startingCardTwo) { bool busted = 0; int nrAsi, sumaNoua; carti[0] = startingCardOne; carti[1] = startingCardTwo; nrCarti = 2; if((carti[0] == 20 && carti[1] == 11) || (carti[0] == 11 && carti[1] == 20)) { cout<<"Dealer stops. Blackjack!"<<endl; return 42; } if(carti[0] == 20) carti[0] -= 10; if(carti[1] == 20) carti[1] -= 10; suma = carti[0] + carti[1]; do{ //inumara cati asi are in mana nrAsi = 0; for (int i = 0; i < nrCarti; i++) if (carti[i] == 11) nrAsi++; busted = 1; for (int i = 0; i <= nrAsi; i++) { sumaNoua = suma - i*10; if(sumaNoua < 22) busted = 0; if(sumaNoua > 16 && sumaNoua < 22) { cout<<"Dealer stands at "<<sumaNoua<<endl; return sumaNoua; } } if(!busted) { carti[nrCarti] = pachet->dealCard(); cout<<"Dealer hits a "<<carti[nrCarti]<<endl; if(carti[nrCarti] == 20) carti[nrCarti] -= 10; suma+= carti[nrCarti++]; } }while(!busted); suma -= nrAsi * 10; cout<<"Dealer stands at "<<suma<<endl; return suma; }};#endifpachet.h#ifndef PACHET_H#define PACHET_H#include <cstdlib>#include <fstream>using namespace std;class Pachet{ int carti[312]; int nrCarti; int deadCards; int remainingCards; int hotness; int points[12];public: Pachet() { ifstream fin ("points.txt"); for (int i = 2; i < 12; i++) fin>>points[i]; for (int i = 0; i < 216; i++) carti[i] = i/24 + 2; for (int i = 216; i < 240; i++) carti[i] = 20; for (int i = 240; i < 288; i++) carti[i] = 10; for (int i = 288; i < 312; i++) carti[i] = 11; nrCarti = 311; deadCards = rand()%16 + 62; remainingCards = 312 - deadCards; hotness = 0; } //new deck: void newDeck() { for (int i = 0; i < 216; i++) carti[i] = i/24 + 2; for (int i = 216; i < 240; i++) carti[i] = 20; for (int i = 240; i < 288; i++) carti[i] = 10; for (int i = 288; i < 312; i++) carti[i] = 11; nrCarti = 311; deadCards = rand()%16 + 62; remainingCards = 312 - deadCards; hotness = 0; } //deals a card from the deck: int dealCard() { int random = rand()%nrCarti; int dealtCard; dealtCard = carti[random]; carti[random] = carti[nrCarti]; nrCarti--; remainingCards--; if (dealtCard != 20) hotness += points[dealtCard]; else hotness += points[10]; return dealtCard; } //checks if the deck is empty; int empty() { if (remainingCards<=0) return 1; else return 0; } int count() { return hotness; } int pacheteRamase() { return nrCarti/52; }};#endifGameBreakdown.cpp#include <iostream>#include <cstdlib>#include <ctime>#include <fstream>#include <stdlib.h>#include "pachet.h"#include "dealer.h"#include "player.h"#include "bankroll.h"#include "bet.h"#include "bet2.h"using namespace std;int chart1[18][12];int chart2[22][12];int chart3[12][12];int main() { ifstream fin ("strategy.txt"); ifstream fin2 ("info.txt"); int i, j; int handsToPlay; int startingBk; fin2>>handsToPlay>>startingBk; if (handsToPlay < 1) { cout<<"To few hands to paly..."<<endl; cin.get(); return 0; } if (startingBk < 1) { cout<<"Starting bankroll is to small..."<<endl; cin.get(); return 0; } //sead the random number generator: srand((unsigned)time(0)); //citire charturi: for(i = 17; i > 4; i--) for(j = 2; j < 12; j++) fin>>chart1[i][j]; for(i = 21; i > 12; i--) for (j = 2; j < 12; j++) fin>>chart2[i][j]; for(i = 11; i > 1; i--) for (j = 2; j < 12; j++) fin>>chart3[i][j]; Pachet *pachet = new Pachet(); Dealer *dealer = new Dealer(pachet); Bankroll *bankroll = new Bankroll(startingBk); Bet *bet = new Bet(bankroll, pachet); Bet2 *bet2 = new Bet2(bankroll, pachet); Player *player = new Player(pachet, bet); int *maini = player->addr(); int dealerSum, betAmount; int playerCard1, dealerCard1, playerCard2, dealerCard2; for (int k = 0; k < handsToPlay; k++) { cout<<endl<<endl<<endl<<"[**]Starting new hand..."<<endl; if(pachet->empty()) pachet->newDeck(); bet->start(); playerCard1 = pachet->dealCard();dealerCard1 = pachet->dealCard();playerCard2 = pachet->dealCard();dealerCard2 = pachet->dealCard(); //playerCard1 = 2; dealerCard1 = 4;playerCard2 = 3;dealerCard2 = 10; cout<<"[*]Dealing "<<playerCard1<<" and "<<playerCard2<<" to player."<<endl; cout<<"[*]Dealing "<<dealerCard1<<" and "<<dealerCard2<<" to dealer."<<endl<<endl; cout<<"[*]Player is playing hand: "<<endl; player->playHand(playerCard1, playerCard2, dealerCard1, chart1, chart2, chart3); cout<<endl<<"[*]Dealer is playing hand: "<<endl; dealerSum = dealer->playHand(dealerCard1, dealerCard2); betAmount = bet->betSize(); cout<<endl<<"[*]Total bet was: "<<betAmount<<endl; for(i = 0; i < player->handsPlayed(); i++) { if(maini[i] == 42) { bankroll->add(betAmount*3/2); cout<<"[*]Player wins with blackjack!"<<endl; continue; } if(dealerSum == 42) { cout<<"[*]Dealer wins with blackjack!"<<endl; bankroll->substract(betAmount); continue; } if(maini[i]<22 && (maini[i] > dealerSum || dealerSum > 21)) { cout<<"[*]Player wins!"<<endl; bankroll->add(betAmount); continue; } if(maini[i] == dealerSum || (maini[i]>21 && dealerSum > 21)) { cout<<"[*]Tie!"<<endl; continue; } cout<<"[*]Dealer wins!"<<endl; bankroll->substract(betAmount); } cout<<endl<<"[**]New bankroll is: "<<bankroll->value(); } cin.get(); return 0;}A fost compilat cu visual studio 2010.Daca aveti intrebari/nelamuriri/cerinte postati aici. Quote