Removing several unnecessary allocations.

This commit is contained in:
lotodore
2011-02-28 22:05:44 +00:00
parent a87a12e8b0
commit 6f290be894
9 changed files with 35 additions and 76 deletions
-7
View File
@@ -1017,13 +1017,6 @@ static const calcHandsData handChancePreflop[] = {
#define NUM_FLOP_VALUES (sizeof(FlopValues)/sizeof(RoundData)) #define NUM_FLOP_VALUES (sizeof(FlopValues)/sizeof(RoundData))
#define NUM_HAND_CHANCE_PREFLOP (sizeof(handChancePreflop)/sizeof(calcHandsData)) #define NUM_HAND_CHANCE_PREFLOP (sizeof(handChancePreflop)/sizeof(calcHandsData))
ArrayData::ArrayData()
{
}
ArrayData::~ArrayData()
{
}
void ArrayData::getHandChancePreflop(int handCode, int** values) void ArrayData::getHandChancePreflop(int handCode, int** values)
{ {
+2 -6
View File
@@ -27,12 +27,8 @@
class ArrayData class ArrayData
{ {
public: public:
ArrayData(); static void getHandChancePreflop(int, int**);
static std::vector< std::vector<int> > getHandChancePreflop(int);
~ArrayData();
void getHandChancePreflop(int, int**);
std::vector< std::vector<int> > getHandChancePreflop(int);
}; };
#endif #endif
+8 -19
View File
@@ -21,16 +21,7 @@
using namespace std; using namespace std;
CardsValue::CardsValue() int CardsValue::holeCardsClass(int one, int two)
{
}
CardsValue::~CardsValue()
{
}
int CardsValue::holeCardsClass(int one, int two) const
{ {
if((one-1)%13<(two-1)%13) { if((one-1)%13<(two-1)%13) {
@@ -214,7 +205,7 @@ int CardsValue::holeCardsClass(int one, int two) const
} }
int CardsValue::holeCardsToIntCode(int* cards) const int CardsValue::holeCardsToIntCode(int* cards)
{ {
// Code der HoleCards ermitteln // Code der HoleCards ermitteln
@@ -238,7 +229,8 @@ int CardsValue::holeCardsToIntCode(int* cards) const
} }
int* CardsValue::intCodeToHoleCards(int code) const /* DO NOT USE, THIS MAY LEAK MEMORY
int* CardsValue::intCodeToHoleCards(int code)
{ {
// one possibility !!! // one possibility !!!
@@ -256,9 +248,9 @@ int* CardsValue::intCodeToHoleCards(int code) const
return cards; return cards;
} }*/
int CardsValue::cardsValue(int* cards, int* position) const int CardsValue::cardsValue(int* cards, int* position)
{ {
int array[7][3]; int array[7][3];
@@ -637,7 +629,7 @@ int CardsValue::cardsValue(int* cards, int* position) const
} }
vector< vector<int> > CardsValue::calcCardsChance(GameState beRoID, int* playerCards, int* boardCards) const vector< vector<int> > CardsValue::calcCardsChance(GameState beRoID, int* playerCards, int* boardCards)
{ {
int i,j; int i,j;
@@ -660,11 +652,8 @@ vector< vector<int> > CardsValue::calcCardsChance(GameState beRoID, int* playerC
switch(beRoID) { switch(beRoID) {
case GAME_STATE_PREFLOP: { case GAME_STATE_PREFLOP: {
ArrayData* myArrayData = new ArrayData;
chance = myArrayData->getHandChancePreflop(holeCardsToIntCode(playerCards)); chance = ArrayData::getHandChancePreflop(holeCardsToIntCode(playerCards));
delete myArrayData;
} }
break; break;
+6 -10
View File
@@ -31,18 +31,14 @@
class CardsValue class CardsValue
{ {
public: public:
CardsValue(); static int holeCardsClass(int, int);
static int cardsValue(int*, int*);
~CardsValue(); static int holeCardsToIntCode(int*);
static int* intCodeToHoleCards(int);
int holeCardsClass(int, int) const; static std::vector< std::vector<int> > calcCardsChance(GameState, int*, int*);
int cardsValue(int*, int*) const; //static int** showdown(GameState, int**, int);
int holeCardsToIntCode(int*) const;
int* intCodeToHoleCards(int) const;
std::vector< std::vector<int> > calcCardsChance(GameState, int*, int*) const;
//int** showdown(GameState, int**, int);
}; };
+17 -24
View File
@@ -847,7 +847,7 @@ static const RoundData FlopValues[] = {
#define NUM_FLOP_VALUES (sizeof(FlopValues)/sizeof(RoundData)) #define NUM_FLOP_VALUES (sizeof(FlopValues)/sizeof(RoundData))
LocalPlayer::LocalPlayer(ConfigFile *c, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) LocalPlayer::LocalPlayer(ConfigFile *c, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB)
: PlayerInterface(), myConfig(c), currentHand(0), myCardsValue(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(0), myButton(mB), myActiveStatus(aS), myStayOnTableStatus(1), myTurn(0), myCardsFlip(0), myRoundStartCash(0), lastMoneyWon(0), sBluff(0), sBluffStatus(0), myWinnerState(false), m_actionTimeoutCounter(0) : PlayerInterface(), myConfig(c), currentHand(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(0), myButton(mB), myActiveStatus(aS), myStayOnTableStatus(1), myTurn(0), myCardsFlip(0), myRoundStartCash(0), lastMoneyWon(0), sBluff(0), sBluffStatus(0), myWinnerState(false), m_actionTimeoutCounter(0)
{ {
// !!!!!!!!!!!!!!!!!!!!!!!! testing !!!!!!!!!!!!!!!!!!!!!!!! // !!!!!!!!!!!!!!!!!!!!!!!! testing !!!!!!!!!!!!!!!!!!!!!!!!
@@ -934,10 +934,10 @@ LocalPlayer::LocalPlayer(ConfigFile *c, int id, unsigned uniqueId, PlayerType ty
// cout << "Spieler: " << myID << " Dude: " << myDude << " Cash: " << myCash << " ActiveStatus: " << myActiveStatus << " Button: " << myButton << endl; // cout << "Spieler: " << myID << " Dude: " << myDude << " Cash: " << myCash << " ActiveStatus: " << myActiveStatus << " Button: " << myButton << endl;
// Dude4 zuweisen // Dude4 zuweisen
int interval = 7; const int interval = 7;
int count = 4; const int count = 4;
int *tempArray = new int[count]; int tempArray[count];
Tools::getRandNumber(0, 2*interval, count, tempArray, 0); Tools::getRandNumber(0, 2*interval, count, tempArray, 0);
for(i=0; i<count; i++) { for(i=0; i<count; i++) {
myDude4 += tempArray[i]; myDude4 += tempArray[i];
@@ -988,18 +988,11 @@ LocalPlayer::LocalPlayer(ConfigFile *c, int id, unsigned uniqueId, PlayerType ty
} }
//////////////////////////// ////////////////////////////
delete[] tempArray;
myCardsValue = new CardsValue;
} }
LocalPlayer::~LocalPlayer() LocalPlayer::~LocalPlayer()
{ {
delete myCardsValue;
} }
@@ -4013,7 +4006,7 @@ void LocalPlayer::calcMyOdds()
case 0: { case 0: {
handCode = myCardsValue->holeCardsToIntCode(myCards); handCode = CardsValue::holeCardsToIntCode(myCards);
// übergang solange preflopValue und flopValue noch nicht bereinigt // übergang solange preflopValue und flopValue noch nicht bereinigt
int players = currentHand->getActivePlayerList()->size(); int players = currentHand->getActivePlayerList()->size();
@@ -4117,8 +4110,8 @@ void LocalPlayer::calcMyOdds()
tempOpponentCardsArray[1] = j; tempOpponentCardsArray[1] = j;
tempOpponentCardsArray[6] = k; tempOpponentCardsArray[6] = k;
tempMyCardsArray[6] = k; tempMyCardsArray[6] = k;
tempMyCardsValue = myCardsValue->cardsValue(tempMyCardsArray,0); tempMyCardsValue = CardsValue::cardsValue(tempMyCardsArray,0);
tempOpponentCardsValue = myCardsValue->cardsValue(tempOpponentCardsArray,0); tempOpponentCardsValue = CardsValue::cardsValue(tempOpponentCardsArray,0);
if(tempMyCardsValue>=tempOpponentCardsValue) countMy++; if(tempMyCardsValue>=tempOpponentCardsValue) countMy++;
} }
@@ -4171,8 +4164,8 @@ void LocalPlayer::calcMyOdds()
tempOpponentCardsArray[0] = i; tempOpponentCardsArray[0] = i;
tempOpponentCardsArray[1] = j; tempOpponentCardsArray[1] = j;
tempMyCardsValue = myCardsValue->cardsValue(tempMyCardsArray,0); tempMyCardsValue = CardsValue::cardsValue(tempMyCardsArray,0);
tempOpponentCardsValue = myCardsValue->cardsValue(tempOpponentCardsArray,0); tempOpponentCardsValue = CardsValue::cardsValue(tempOpponentCardsArray,0);
if(tempMyCardsValue>=tempOpponentCardsValue) countMy++; if(tempMyCardsValue>=tempOpponentCardsValue) countMy++;
} }
@@ -4467,7 +4460,7 @@ void LocalPlayer::preflopEngine3()
// cout << "preflop-bluff " << bluff << endl; // cout << "preflop-bluff " << bluff << endl;
// Potential // Potential
int potential = 10*(4*(myCardsValue->holeCardsClass(myCards[0], myCards[1]))+1*tempRand)/50-myDude; int potential = 10*(4*(CardsValue::holeCardsClass(myCards[0], myCards[1]))+1*tempRand)/50-myDude;
int setToHighest = currentHand->getCurrentBeRo()->getHighestSet() - mySet; int setToHighest = currentHand->getCurrentBeRo()->getHighestSet() - mySet;
@@ -4477,7 +4470,7 @@ void LocalPlayer::preflopEngine3()
Tools::getRandNumber(2,3,1,&tempFold,0); Tools::getRandNumber(2,3,1,&tempFold,0);
// FOLD --> wenn Potential negativ oder HighestSet zu hoch // FOLD --> wenn Potential negativ oder HighestSet zu hoch
if( (potential*setToHighest<0 || (setToHighest > tempFold * currentHand->getSmallBlind() && potential<1) || (setToHighest > 2 * tempFold * currentHand->getSmallBlind() && potential<2) || (setToHighest > 4 * tempFold * currentHand->getSmallBlind() && potential<3) || (setToHighest > 10 * tempFold * currentHand->getSmallBlind() && potential<4)) && myCardsValue->holeCardsClass(myCards[0], myCards[1]) < 9 && bluff > 15) { if( (potential*setToHighest<0 || (setToHighest > tempFold * currentHand->getSmallBlind() && potential<1) || (setToHighest > 2 * tempFold * currentHand->getSmallBlind() && potential<2) || (setToHighest > 4 * tempFold * currentHand->getSmallBlind() && potential<3) || (setToHighest > 10 * tempFold * currentHand->getSmallBlind() && potential<4)) && CardsValue::holeCardsClass(myCards[0], myCards[1]) < 9 && bluff > 15) {
myAction=1; myAction=1;
} else { } else {
// RAISE --> wenn hohes Potential // RAISE --> wenn hohes Potential
@@ -4666,8 +4659,8 @@ void LocalPlayer::flopEngine3()
tempOpponentCardsArray[6] = l; tempOpponentCardsArray[6] = l;
tempMyCardsArray[5] = k; tempMyCardsArray[5] = k;
tempMyCardsArray[6] = l; tempMyCardsArray[6] = l;
tempMyCardsValue = myCardsValue->cardsValue(tempMyCardsArray,0); tempMyCardsValue = CardsValue::cardsValue(tempMyCardsArray,0);
tempOpponentCardsValue = myCardsValue->cardsValue(tempOpponentCardsArray,0); tempOpponentCardsValue = CardsValue::cardsValue(tempOpponentCardsArray,0);
if(tempMyCardsValue>=tempOpponentCardsValue) countMy++; if(tempMyCardsValue>=tempOpponentCardsValue) countMy++;
@@ -4835,8 +4828,8 @@ void LocalPlayer::turnEngine3()
tempOpponentCardsArray[1] = j; tempOpponentCardsArray[1] = j;
tempOpponentCardsArray[6] = k; tempOpponentCardsArray[6] = k;
tempMyCardsArray[6] = k; tempMyCardsArray[6] = k;
tempMyCardsValue = myCardsValue->cardsValue(tempMyCardsArray,0); tempMyCardsValue = CardsValue::cardsValue(tempMyCardsArray,0);
tempOpponentCardsValue = myCardsValue->cardsValue(tempOpponentCardsArray,0); tempOpponentCardsValue = CardsValue::cardsValue(tempOpponentCardsArray,0);
if(tempMyCardsValue>=tempOpponentCardsValue) countMy++; if(tempMyCardsValue>=tempOpponentCardsValue) countMy++;
} }
@@ -4999,8 +4992,8 @@ void LocalPlayer::riverEngine3()
tempOpponentCardsArray[0] = i; tempOpponentCardsArray[0] = i;
tempOpponentCardsArray[1] = j; tempOpponentCardsArray[1] = j;
tempMyCardsValue = myCardsValue->cardsValue(tempMyCardsArray,0); tempMyCardsValue = CardsValue::cardsValue(tempMyCardsArray,0);
tempOpponentCardsValue = myCardsValue->cardsValue(tempOpponentCardsArray,0); tempOpponentCardsValue = CardsValue::cardsValue(tempOpponentCardsArray,0);
if(tempMyCardsValue>=tempOpponentCardsValue) countMy++; if(tempMyCardsValue>=tempOpponentCardsValue) countMy++;
} }
-3
View File
@@ -26,7 +26,6 @@
#include <string> #include <string>
class CardsValue;
class ConfigFile; class ConfigFile;
class HandInterface; class HandInterface;
@@ -286,8 +285,6 @@ private:
ConfigFile *myConfig; ConfigFile *myConfig;
HandInterface *currentHand; HandInterface *currentHand;
CardsValue *myCardsValue;
// Konstanten // Konstanten
int myID; int myID;
unsigned myUniqueID; unsigned myUniqueID;
+1 -1
View File
@@ -23,7 +23,7 @@ using namespace std;
ClientPlayer::ClientPlayer(ConfigFile *c, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) ClientPlayer::ClientPlayer(ConfigFile *c, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB)
: PlayerInterface(), myConfig(c), currentHand(0), myCardsValue(0), myID(id), myUniqueID(uniqueId), myType(type), : PlayerInterface(), myConfig(c), currentHand(0), myID(id), myUniqueID(uniqueId), myType(type),
myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myLastRelativeSet(0), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myLastRelativeSet(0),
myAction(0), myButton(mB), myActiveStatus(aS), myStayOnTableStatus(true), myTurn(false), myCardsFlip(false), myRoundStartCash(0), myAction(0), myButton(mB), myActiveStatus(aS), myStayOnTableStatus(true), myTurn(false), myCardsFlip(false), myRoundStartCash(0),
lastMoneyWon(0), sBluff(0), sBluffStatus(false), myWinnerState(false) lastMoneyWon(0), sBluff(0), sBluffStatus(false), myWinnerState(false)
-3
View File
@@ -25,7 +25,6 @@
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include <string> #include <string>
class CardsValue;
class ConfigFile; class ConfigFile;
class HandInterface; class HandInterface;
@@ -149,8 +148,6 @@ private:
ConfigFile *myConfig; ConfigFile *myConfig;
HandInterface *currentHand; HandInterface *currentHand;
CardsValue *myCardsValue;
// Konstanten // Konstanten
const int myID; const int myID;
const unsigned myUniqueID; const unsigned myUniqueID;
+1 -3
View File
@@ -3536,8 +3536,6 @@ void gameTableImpl::refreshVotesMonitor(int currentVotes, int numVotesNeededToKi
void gameTableImpl::refreshCardsChance(GameState bero) void gameTableImpl::refreshCardsChance(GameState bero)
{ {
CardsValue myCardsValue;
if(myConfig->readConfigInt("ShowCardsChanceMonitor")) { if(myConfig->readConfigInt("ShowCardsChanceMonitor")) {
boost::shared_ptr<PlayerInterface> humanPlayer = myStartWindow->getSession()->getCurrentGame()->getSeatsList()->front(); boost::shared_ptr<PlayerInterface> humanPlayer = myStartWindow->getSession()->getCurrentGame()->getSeatsList()->front();
@@ -3548,7 +3546,7 @@ void gameTableImpl::refreshCardsChance(GameState bero)
humanPlayer->getMyCards(holeCards); humanPlayer->getMyCards(holeCards);
myStartWindow->getSession()->getCurrentGame()->getCurrentHand()->getBoard()->getMyCards(boardCards); myStartWindow->getSession()->getCurrentGame()->getCurrentHand()->getBoard()->getMyCards(boardCards);
label_chance->refreshChance(myCardsValue.calcCardsChance(bero, holeCards, boardCards)); label_chance->refreshChance(CardsValue::calcCardsChance(bero, holeCards, boardCards));
} else { } else {
label_chance->resetChance(); label_chance->resetChance();
} }