Use boost::random for random number generation.

This commit is contained in:
lotodore
2011-10-11 15:15:22 +00:00
parent 0d9bf08934
commit 32843b2100
9 changed files with 72 additions and 42 deletions
+11 -5
View File
@@ -44,8 +44,16 @@ LocalHand::LocalHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, boost:
}
// generate cards and assign to board and player
int *cardsArray = new int[2*activePlayerList->size()+5];
Tools::getRandNumber(0, 51, 2*activePlayerList->size()+5, cardsArray, 1);
const int NumCards = 52;
int cardsArray[NumCards] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51
};
Tools::ShuffleArrayNonDeterministic(cardsArray, NumCards);
int tempBoardArray[5];
int tempPlayerArray[2];
int tempPlayerAndBoardArray[7];
@@ -81,14 +89,12 @@ LocalHand::LocalHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, boost:
// set sBluff for all players --> TODO for ai-player in internet
if((*it)->getMyID() != 0) {
Tools::getRandNumber(1,100,1,&sBluff,0);
Tools::GetRand(1, 100, 1, &sBluff);
(*it)->setSBluff(sBluff);
(*it)->setSBluffStatus(0);
}
}
delete[] cardsArray;
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!! DEBUGGER !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //
if(DEBUG_MODE) {
+26 -26
View File
@@ -932,7 +932,7 @@ LocalPlayer::LocalPlayer(ConfigFile *c, int id, unsigned uniqueId, PlayerType ty
}
// Dude zuweisen
Tools::getRandNumber(3 , 5, 1, &myDude, 0);
Tools::GetRand(3, 5, 1, &myDude);
// cout << "Spieler: " << myID << " Dude: " << myDude << " Cash: " << myCash << " ActiveStatus: " << myActiveStatus << " Button: " << myButton << endl;
// Dude4 zuweisen
@@ -940,7 +940,7 @@ LocalPlayer::LocalPlayer(ConfigFile *c, int id, unsigned uniqueId, PlayerType ty
const int count = 4;
int tempArray[count];
Tools::getRandNumber(0, 2*interval, count, tempArray, 0);
Tools::GetRand(0, 2*interval, count, tempArray);
for(i=0; i<count; i++) {
myDude4 += tempArray[i];
}
@@ -1210,7 +1210,7 @@ void LocalPlayer::preflopEngine()
// cout << "Spieler " << myID << ": Dude " << myDude4 << "\t Wert " << myHoleCardsValue << "\t Niveau " << myNiveau[0] << " " << myNiveau[1] << " " << myNiveau[2] << "\t Agg " << aggValue << " " << endl;
// Check-Bluff generieren
Tools::getRandNumber(1,100,1,&cBluff,0);
Tools::GetRand(1, 100, 1, &cBluff);
// aktive oder passivie Situation ? -> im preflop nur passiv
@@ -1565,7 +1565,7 @@ void LocalPlayer::flopEngine()
// Check-Bluff generieren
Tools::getRandNumber(1,100,1,&cBluff,0);
Tools::GetRand(1, 100, 1, &cBluff);
// aktiv oder passiv?
if(currentHand->getCurrentBeRo()->getHighestSet() > 0) {
@@ -1668,7 +1668,7 @@ void LocalPlayer::flopEngine()
// Position
if(myButton == 1) {
// Position-Bluff generieren
Tools::getRandNumber(1,100,1,&pBluff,0);
Tools::GetRand(1, 100, 1, &pBluff);
if(pBluff <= 16) {
bet = (pBluff/4)*2*currentHand->getSmallBlind();
// bet zu klein
@@ -1706,7 +1706,7 @@ void LocalPlayer::flopEngine()
// Standard-Raise-Routine
else {
// raise-Betrag ermitteln
Tools::getRandNumber(1,8,1,&rand,0);
Tools::GetRand(1, 8, 1, &rand);
raise = rand*currentHand->getSmallBlind();
// raise-Betrag zu klein -> mindestens Standard-raise
// if(raise < currentHand->getCurrentBeRo()->getHighestSet()) {
@@ -1729,7 +1729,7 @@ void LocalPlayer::flopEngine()
// cout << "sBLUFF!" << endl;
Tools::getRandNumber(1,8,1,&rand,0);
Tools::GetRand(1, 8, 1, &rand);
bet = rand*currentHand->getSmallBlind();
// bet zu klein
if(bet < 2*currentHand->getSmallBlind()) {
@@ -2267,7 +2267,7 @@ void LocalPlayer::turnEngine()
if(individualHighestSet > myCash) individualHighestSet = myCash;
// Check-Bluff generieren
Tools::getRandNumber(1,100,1,&cBluff,0);
Tools::GetRand(1, 100, 1, &cBluff);
// aktiv oder passiv?
if(currentHand->getCurrentBeRo()->getHighestSet() > 0) {
@@ -2369,7 +2369,7 @@ void LocalPlayer::turnEngine()
// Position
if(myButton == 1) {
// Position-Bluff generieren
Tools::getRandNumber(1,100,1,&pBluff,0);
Tools::GetRand(1, 100, 1, &pBluff);
if(pBluff <= 16) {
bet = (pBluff/4)*2*currentHand->getSmallBlind();
// bet zu klein
@@ -2406,7 +2406,7 @@ void LocalPlayer::turnEngine()
// Standard-Raise-Routine
else {
// raise-Betrag ermitteln
Tools::getRandNumber(1,8,1,&rand,0);
Tools::GetRand(1, 8, 1, &rand);
raise = rand*currentHand->getSmallBlind();
// raise-Betrag zu klein -> mindestens Standard-raise
// if(raise < currentHand->getCurrentBeRo()->getHighestSet()) {
@@ -2429,7 +2429,7 @@ void LocalPlayer::turnEngine()
// cout << "sBLUFF!" << endl;
Tools::getRandNumber(1,8,1,&rand,0);
Tools::GetRand(1, 8, 1, &rand);
bet = rand*currentHand->getSmallBlind();
// bet zu klein
if(bet < 2*currentHand->getSmallBlind()) {
@@ -2877,7 +2877,7 @@ void LocalPlayer::riverEngine()
// Position
if(myButton == 1) {
// Position-Bluff generieren
Tools::getRandNumber(1,100,1,&pBluff,0);
Tools::GetRand(1, 100, 1, &pBluff);
if(pBluff <= 20) {
bet = (pBluff/4)*2*currentHand->getSmallBlind();
// bet zu klein
@@ -2918,7 +2918,7 @@ void LocalPlayer::riverEngine()
// Standard-Raise-Routine
else {
// raise-Betrag ermitteln
Tools::getRandNumber(1,8,1,&rand,0);
Tools::GetRand(1, 8, 1, &rand);
raise = rand*currentHand->getSmallBlind();
// raise-Betrag zu klein -> mindestens Standard-raise
// if(raise < currentHand->getCurrentBeRo()->getHighestSet()) {
@@ -2941,7 +2941,7 @@ void LocalPlayer::riverEngine()
// cout << "sBLUFF!" << endl;
Tools::getRandNumber(1,8,1,&rand,0);
Tools::GetRand(1, 8, 1, &rand);
bet = rand*currentHand->getSmallBlind();
// bet zu klein
if(bet < 2*currentHand->getSmallBlind()) {
@@ -4450,11 +4450,11 @@ void LocalPlayer::preflopEngine3()
// Bauchgefhl (zufᅵlig)
int tempRand;
Tools::getRandNumber(1,10,1,&tempRand,0);
Tools::GetRand(1, 10, 1, &tempRand);
// bluff, checkbluff
int bluff;
Tools::getRandNumber(1,100,1,&bluff,0);
Tools::GetRand(1, 100, 1, &bluff);
// cout << "preflop-bluff " << bluff << endl;
@@ -4466,7 +4466,7 @@ void LocalPlayer::preflopEngine3()
// temp fr das Vielfache des Small Blind, sodass HighestSet zu hoch ist
int tempFold;
// tempFold = (currentHand->getPlayerArray()[0]->getMyAverageSets())/(8*currentHand->getSmallBlind());
Tools::getRandNumber(2,3,1,&tempFold,0);
Tools::GetRand(2, 3, 1, &tempFold);
// 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)) && CardsValue::holeCardsClass(myCards[0], myCards[1]) < 9 && bluff > 15) {
@@ -4677,11 +4677,11 @@ void LocalPlayer::flopEngine3()
// Bauchgefhl (zufᅵlig)
int tempRand;
Tools::getRandNumber((int)(percent*10.)-2,(int)(percent*10.)+2,1,&tempRand,0);
Tools::GetRand((int)(percent*10.)-2, (int)(percent*10.)+2, 1, &tempRand);
// bluff, checkbluff
int bluff;
Tools::getRandNumber(1,100,1,&bluff,0);
Tools::GetRand(1, 100, 1, &bluff);
// cout << "flop-bluff " << bluff << endl;
@@ -4693,7 +4693,7 @@ void LocalPlayer::flopEngine3()
// temp fr das Vielfache des Small Blind, sodass HighestSet zu hoch ist
int tempFold;
// tempFold = (currentHand->getPlayerArray()[0]->getMyAverageSets())/(8*currentHand->getSmallBlind());
Tools::getRandNumber(2,3,1,&tempFold,0);
Tools::GetRand(2, 3, 1, &tempFold);
// FOLD --> wenn potential negativ oder HighestSet zu hoch
if(( potential*setToHighest<0 || (setToHighest > tempFold * currentHand->getSmallBlind() && potential<1) || (setToHighest > 3 * tempFold * currentHand->getSmallBlind() && potential<2) || (setToHighest > 9 * tempFold * currentHand->getSmallBlind() && potential<3) || (setToHighest > 20*tempFold * currentHand->getSmallBlind() && potential<4) || (setToHighest > 40 *tempFold * currentHand->getSmallBlind() && potential<5)) && percent < 0.90 && bluff > 18) {
@@ -4843,11 +4843,11 @@ void LocalPlayer::turnEngine3()
// Bauchgefhl (zufᅵlig)
int tempRand;
Tools::getRandNumber((int)(percent*10.)-2,(int)(percent*10.)+2,1,&tempRand,0);
Tools::GetRand((int)(percent*10.)-2, (int)(percent*10.)+2, 1, &tempRand);
// bluff, checkbluff
int bluff;
Tools::getRandNumber(1,100,1,&bluff,0);
Tools::GetRand(1, 100, 1, &bluff);
// cout << "turn-bluff " << bluff << endl;
@@ -4859,7 +4859,7 @@ void LocalPlayer::turnEngine3()
// temp fr das Vielfache des Small Blind, sodass HighestSet zu hoch ist
int tempFold;
// tempFold = (currentHand->getPlayerArray()[0]->getMyAverageSets())/(7*currentHand->getSmallBlind());
Tools::getRandNumber(3,4,1,&tempFold,0);
Tools::GetRand(3, 4, 1, &tempFold);
// FOLD
// --> wenn potential negativ oder HighestSet zu hoch
@@ -5005,11 +5005,11 @@ void LocalPlayer::riverEngine3()
// Bauchgefhl (zufᅵlig)
int tempRand;
Tools::getRandNumber((int)(percent*10.)-2,(int)(percent*10.)+2,1,&tempRand,0);
Tools::GetRand((int)(percent*10.)-2, (int)(percent*10.)+2, 1, &tempRand);
// bluff, checkbluff
int bluff;
Tools::getRandNumber(1,100,1,&bluff,0);
Tools::GetRand(1, 100, 1, &bluff);
// cout << "river-bluff " << bluff << endl;
@@ -5021,7 +5021,7 @@ void LocalPlayer::riverEngine3()
// temp fr das Vielfache des Small Blind, sodass HighestSet zu hoch ist
int tempFold;
// tempFold = (currentHand->getPlayerArray()[0]->getMyAverageSets())/(6*currentHand->getSmallBlind());
Tools::getRandNumber(4,6,1,&tempFold,0);
Tools::GetRand(4, 6, 1, &tempFold);
// FOLD
// --> wenn potential negativ oder HighestSet zu hoch
+2 -3
View File
@@ -32,7 +32,6 @@
using namespace std;
#if 0 // TODO temporarily disabled until build problems are solved
boost::thread_specific_ptr<boost::random_device> g_rand_state;
struct nondet_rng : std::unary_function<unsigned, unsigned> {
@@ -92,8 +91,8 @@ void Tools::GetRandUnique(int minValue, int maxValue, unsigned count, int *out)
numCreated++;
}
}
#endif
/*
void Tools::getRandNumber(int start, int end, int howMany, int* randArray, bool different, int* bad, int countBad)
{
@@ -170,6 +169,6 @@ void Tools::getRandNumber(int start, int end, int howMany, int* randArray, bool
delete[] tempArray;
}
}
}*/
+1 -1
View File
@@ -27,7 +27,7 @@ public:
static void GetRand(int minValue, int maxValue, unsigned count, int *out);
static void GetRandUnique(int minValue, int maxValue, unsigned count, int *out);
static void getRandNumber(int, int, int, int*, bool, int* = 0, int = 0);
//static void getRandNumber(int, int, int, int*, bool, int* = 0, int = 0);
};
@@ -118,7 +118,7 @@ void internetGameLoginDialogImpl::accept()
// Generate a valid guest name.
QString guestName;
int guestId;
Tools::getRandNumber(1, 99999, 1, &guestId, false);
Tools::GetRand(1, 99999, 1, &guestId);
guestName.sprintf("Guest%05d", guestId);
myConfig->writeConfigString("MyName", guestName.toUtf8().constData());
}
+1 -1
View File
@@ -285,7 +285,7 @@ void startWindowImpl::startNewLocalGame(newGameDialogImpl *v)
StartData startData;
int tmpDealerPos = 0;
startData.numberOfPlayers = gameData.maxNumberOfPlayers;
Tools::getRandNumber(0, startData.numberOfPlayers-1, 1, &tmpDealerPos, 0);
Tools::GetRand(0, startData.numberOfPlayers-1, 1, &tmpDealerPos);
//if(DEBUG_MODE) {
// tmpDealerPos = 4;
//}
+1 -1
View File
@@ -240,7 +240,7 @@ ServerGame::InternalStartGame()
startData.numberOfPlayers = (int)playerData.size();
int tmpDealerPos = 0;
Tools::getRandNumber(0, startData.numberOfPlayers-1, 1, &tmpDealerPos, 0);
Tools::GetRand(0, startData.numberOfPlayers-1, 1, &tmpDealerPos);
// The Player Id is not continuous. Therefore, the start dealer position
// needs to be converted to a player Id, and cannot be directly generated
// as player Id.