vector in cardsChance

This commit is contained in:
floty
2008-12-20 16:47:02 +00:00
parent 10624d5399
commit 7ba70be3ac
6 changed files with 106 additions and 53 deletions
+35
View File
@@ -1047,3 +1047,38 @@ void ArrayData::getHandChancePreflop(int handCode, int** values) {
if (check == -1) LOG_ERROR(__FILE__ << " (" << __LINE__ << "): ERROR getHandChancePreflop - " << handCode);
}
vector< vector<int> > ArrayData::getHandChancePreflop(int handCode) {
int check = -1;
int i;
vector< vector<int> > chance(2);
vector<int> chance_0(10);
vector<int> chance_1(10);
chance[0] = chance_0;
chance[1] = chance_1;
for(i=0;i<10;i++) {
chance[0][i] = 0;
chance[1][i] = 0;
}
for (unsigned val = 0; val < NUM_HAND_CHANCE_PREFLOP; val++) {
if(handCode == handChancePreflop[val].hand) {
check = 1;
for(int i=0;i<10;i++) {
for(int j=0;j<2;j++) {
chance[j][i] = handChancePreflop[val].data[i][j];
}
}
break;
}
}
if (check == -1) LOG_ERROR(__FILE__ << " (" << __LINE__ << "): ERROR getHandChancePreflop - " << handCode);
return chance;
}
+6
View File
@@ -22,6 +22,11 @@
#include <core/loghelper.h>
#include<iostream>
#include<vector>
using namespace std;
class ArrayData{
public:
ArrayData();
@@ -29,6 +34,7 @@ public:
~ArrayData();
void getHandChancePreflop(int, int**);
vector< vector<int> > getHandChancePreflop(int);
};
#endif
+36 -32
View File
@@ -563,21 +563,25 @@ int array[7][3];
}
int** CardsValue::calcCardsChance(GameState beRoID, int* playerCards, int* boardCards)
vector< vector<int> > CardsValue::calcCardsChance(GameState beRoID, int* playerCards, int* boardCards)
{
int i,j;
int** hand = new int*[10];
int cards[7];
int sum = 0;
vector< vector<int> > chance(2);
vector<int> chance_0(10);
vector<int> chance_1(10);
chance[0] = chance_0;
chance[1] = chance_1;
for(i=0;i<10;i++) {
hand[i] = new int[2];
for(j=0;j<2;j++) {
hand[i][j] = 0;
}
chance[0][i] = 0;
chance[1][i] = 0;
}
int cards[7];
int sum = 0;
cards[0] = playerCards[0];
cards[1] = playerCards[1];
for(i=0;i<5;i++) cards[i+2] = boardCards[i];
@@ -586,7 +590,7 @@ int** CardsValue::calcCardsChance(GameState beRoID, int* playerCards, int* board
case GAME_STATE_PREFLOP: {
ArrayData* myArrayData = new ArrayData;
myArrayData->getHandChancePreflop(holeCardsToIntCode(playerCards),hand);
chance = myArrayData->getHandChancePreflop(holeCardsToIntCode(playerCards));
delete myArrayData;
@@ -599,15 +603,15 @@ int** CardsValue::calcCardsChance(GameState beRoID, int* playerCards, int* board
if(j!=cards[0] && j!=cards[1] && j!=cards[2] && j!=cards[3] && j!=cards[4]) {
cards[5] = i;
cards[6] = j;
(hand[cardsValue(cards,0)/100000000][0])++;
(chance[0][cardsValue(cards,0)/100000000])++;
sum++;
}
}
}
}
for(i=0;i<10;i++) {
if(hand[i][0] > 0) hand[i][1] = 1;
hand[i][0] = (int)(((double)hand[i][0]/(double)sum)*100.0+0.5);
if(chance[0][i] > 0) chance[1][i] = 1;
chance[0][i] = (int)(((double)chance[0][i]/(double)sum)*100.0+0.5);
}
} break;
@@ -616,42 +620,42 @@ int** CardsValue::calcCardsChance(GameState beRoID, int* playerCards, int* board
for(i=0;i<52;i++) {
if(i!=cards[0] && i!=cards[1] && i!=cards[2] && i!=cards[3] && i!=cards[4] && i!=cards[5]) {
cards[6] = i;
(hand[cardsValue(cards,0)/100000000][0])++;
(chance[0][cardsValue(cards,0)/100000000])++;
sum++;
}
}
for(i=0;i<10;i++) {
if(hand[i][0] > 0) hand[i][1] = 1;
hand[i][0] = (int)(((double)hand[i][0]/(double)sum)*100.0+0.5);
if(chance[0][i] > 0) chance[1][i] = 1;
chance[0][i] = (int)(((double)chance[0][i]/(double)sum)*100.0+0.5);
}
} break;
case GAME_STATE_RIVER: {
hand[cardsValue(cards,0)/100000000][0] = 100;
hand[cardsValue(cards,0)/100000000][1] = 1;
chance[0][cardsValue(cards,0)/100000000] = 100;
chance[1][cardsValue(cards,0)/100000000] = 1;
} break;
default: {
}
}
return hand;
return chance;
}
int** CardsValue::showdown(GameState beRoID, int** playerCards, int playerCount) {
int i,j;
int** chance = new int*[2];
for(i=0;i<10;i++) {
chance[i] = new int[2];
for(j=0;j<2;j++) {
chance[i][j] = 0;
}
}
int rand[5];
return chance;
// int i,j;
//
// int** chance = new int*[2];
//
// for(i=0;i<10;i++) {
// chance[i] = new int[2];
// for(j=0;j<2;j++) {
// chance[i][j] = 0;
// }
// }
//
// int rand[5];
//
// return chance;
}
+6 -1
View File
@@ -24,6 +24,11 @@
#include "arraydata.h"
#include "tools.h"
#include<iostream>
#include<vector>
using namespace std;
class CardsValue{
public:
CardsValue();
@@ -36,7 +41,7 @@ public:
int holeCardsToIntCode(int*);
int* intCodeToHoleCards(int);
int** calcCardsChance(GameState, int*, int*);
vector< vector<int> > calcCardsChance(GameState, int*, int*);
int** showdown(GameState, int**, int);
};