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_HAND_CHANCE_PREFLOP (sizeof(handChancePreflop)/sizeof(calcHandsData))
ArrayData::ArrayData()
{
}
ArrayData::~ArrayData()
{
}
void ArrayData::getHandChancePreflop(int handCode, int** values)
{
+2 -6
View File
@@ -27,12 +27,8 @@
class ArrayData
{
public:
ArrayData();
~ArrayData();
void getHandChancePreflop(int, int**);
std::vector< std::vector<int> > getHandChancePreflop(int);
static void getHandChancePreflop(int, int**);
static std::vector< std::vector<int> > getHandChancePreflop(int);
};
#endif
+8 -19
View File
@@ -21,16 +21,7 @@
using namespace std;
CardsValue::CardsValue()
{
}
CardsValue::~CardsValue()
{
}
int CardsValue::holeCardsClass(int one, int two) const
int CardsValue::holeCardsClass(int one, int two)
{
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
@@ -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 !!!
@@ -256,9 +248,9 @@ int* CardsValue::intCodeToHoleCards(int code) const
return cards;
}
}*/
int CardsValue::cardsValue(int* cards, int* position) const
int CardsValue::cardsValue(int* cards, int* position)
{
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;
@@ -660,11 +652,8 @@ vector< vector<int> > CardsValue::calcCardsChance(GameState beRoID, int* playerC
switch(beRoID) {
case GAME_STATE_PREFLOP: {
ArrayData* myArrayData = new ArrayData;
chance = myArrayData->getHandChancePreflop(holeCardsToIntCode(playerCards));
delete myArrayData;
chance = ArrayData::getHandChancePreflop(holeCardsToIntCode(playerCards));
}
break;
+6 -10
View File
@@ -31,18 +31,14 @@
class CardsValue
{
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;
int cardsValue(int*, int*) const;
int holeCardsToIntCode(int*) const;
int* intCodeToHoleCards(int) const;
std::vector< std::vector<int> > calcCardsChance(GameState, int*, int*) const;
//int** showdown(GameState, int**, int);
static std::vector< std::vector<int> > calcCardsChance(GameState, int*, int*);
//static 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))
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 !!!!!!!!!!!!!!!!!!!!!!!!
@@ -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;
// Dude4 zuweisen
int interval = 7;
int count = 4;
const int interval = 7;
const int count = 4;
int *tempArray = new int[count];
int tempArray[count];
Tools::getRandNumber(0, 2*interval, count, tempArray, 0);
for(i=0; i<count; 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()
{
delete myCardsValue;
}
@@ -4013,7 +4006,7 @@ void LocalPlayer::calcMyOdds()
case 0: {
handCode = myCardsValue->holeCardsToIntCode(myCards);
handCode = CardsValue::holeCardsToIntCode(myCards);
// übergang solange preflopValue und flopValue noch nicht bereinigt
int players = currentHand->getActivePlayerList()->size();
@@ -4117,8 +4110,8 @@ void LocalPlayer::calcMyOdds()
tempOpponentCardsArray[1] = j;
tempOpponentCardsArray[6] = k;
tempMyCardsArray[6] = k;
tempMyCardsValue = myCardsValue->cardsValue(tempMyCardsArray,0);
tempOpponentCardsValue = myCardsValue->cardsValue(tempOpponentCardsArray,0);
tempMyCardsValue = CardsValue::cardsValue(tempMyCardsArray,0);
tempOpponentCardsValue = CardsValue::cardsValue(tempOpponentCardsArray,0);
if(tempMyCardsValue>=tempOpponentCardsValue) countMy++;
}
@@ -4171,8 +4164,8 @@ void LocalPlayer::calcMyOdds()
tempOpponentCardsArray[0] = i;
tempOpponentCardsArray[1] = j;
tempMyCardsValue = myCardsValue->cardsValue(tempMyCardsArray,0);
tempOpponentCardsValue = myCardsValue->cardsValue(tempOpponentCardsArray,0);
tempMyCardsValue = CardsValue::cardsValue(tempMyCardsArray,0);
tempOpponentCardsValue = CardsValue::cardsValue(tempOpponentCardsArray,0);
if(tempMyCardsValue>=tempOpponentCardsValue) countMy++;
}
@@ -4467,7 +4460,7 @@ void LocalPlayer::preflopEngine3()
// cout << "preflop-bluff " << bluff << endl;
// 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;
@@ -4477,7 +4470,7 @@ void LocalPlayer::preflopEngine3()
Tools::getRandNumber(2,3,1,&tempFold,0);
// 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;
} else {
// RAISE --> wenn hohes Potential
@@ -4666,8 +4659,8 @@ void LocalPlayer::flopEngine3()
tempOpponentCardsArray[6] = l;
tempMyCardsArray[5] = k;
tempMyCardsArray[6] = l;
tempMyCardsValue = myCardsValue->cardsValue(tempMyCardsArray,0);
tempOpponentCardsValue = myCardsValue->cardsValue(tempOpponentCardsArray,0);
tempMyCardsValue = CardsValue::cardsValue(tempMyCardsArray,0);
tempOpponentCardsValue = CardsValue::cardsValue(tempOpponentCardsArray,0);
if(tempMyCardsValue>=tempOpponentCardsValue) countMy++;
@@ -4835,8 +4828,8 @@ void LocalPlayer::turnEngine3()
tempOpponentCardsArray[1] = j;
tempOpponentCardsArray[6] = k;
tempMyCardsArray[6] = k;
tempMyCardsValue = myCardsValue->cardsValue(tempMyCardsArray,0);
tempOpponentCardsValue = myCardsValue->cardsValue(tempOpponentCardsArray,0);
tempMyCardsValue = CardsValue::cardsValue(tempMyCardsArray,0);
tempOpponentCardsValue = CardsValue::cardsValue(tempOpponentCardsArray,0);
if(tempMyCardsValue>=tempOpponentCardsValue) countMy++;
}
@@ -4999,8 +4992,8 @@ void LocalPlayer::riverEngine3()
tempOpponentCardsArray[0] = i;
tempOpponentCardsArray[1] = j;
tempMyCardsValue = myCardsValue->cardsValue(tempMyCardsArray,0);
tempOpponentCardsValue = myCardsValue->cardsValue(tempOpponentCardsArray,0);
tempMyCardsValue = CardsValue::cardsValue(tempMyCardsArray,0);
tempOpponentCardsValue = CardsValue::cardsValue(tempOpponentCardsArray,0);
if(tempMyCardsValue>=tempOpponentCardsValue) countMy++;
}
-3
View File
@@ -26,7 +26,6 @@
#include <string>
class CardsValue;
class ConfigFile;
class HandInterface;
@@ -286,8 +285,6 @@ private:
ConfigFile *myConfig;
HandInterface *currentHand;
CardsValue *myCardsValue;
// Konstanten
int myID;
unsigned myUniqueID;