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
+15 -1
View File
@@ -339,6 +339,7 @@ win32 {
LIBS += -lboost_filesystem-mt
LIBS += -lboost_regex-mt
LIBS += -lboost_iostreams-mt
LIBS += -lboost_random-mt
LIBS += -lboost_system-mt
}
win32-g++ {
@@ -348,6 +349,7 @@ win32 {
LIBS += -lboost_filesystem-mgw45-mt-1_45.dll
LIBS += -lboost_regex-mgw45-mt-1_45
LIBS += -lboost_iostreams-mgw45-mt-1_45.dll
LIBS += -lboost_random-mgw45-mt-1_45.dll
LIBS += -lboost_system-mgw45-mt-1_45.dll
}
LIBS += \
@@ -387,6 +389,8 @@ unix:!mac {
boost_regex-mt
BOOST_SYS = boost_system \
boost_system-mt
BOOST_RANDOM = boost_random \
boost_random-mt
# searching in $PREFIX/lib and $PREFIX/lib64
# to override the default '/usr' pass PREFIX
@@ -424,6 +428,14 @@ unix:!mac {
message("Found $$lib")
BOOST_REGEX = -l$$lib
}
for(lib, BOOST_RANDOM):exists($${dir}/lib$${lib}.so*) {
message("Found $$lib")
BOOST_RANDOM = -l$$lib
}
for(lib, BOOST_RANDOM):exists($${dir}/lib$${lib}.a) {
message("Found $$lib")
BOOST_RANDOM = -l$$lib
}
for(lib, BOOST_SYS):exists($${dir}/lib$${lib}.so*) {
message("Found $$lib")
BOOST_SYS = -l$$lib
@@ -437,8 +449,9 @@ unix:!mac {
$$BOOST_FS \
$$BOOST_IOSTREAMS \
$$BOOST_REGEX \
$$BOOST_RANDOM \
$$BOOST_SYS
!count(BOOST_LIBS, 5):error("Unable to find boost libraries in PREFIX=$${PREFIX}")
!count(BOOST_LIBS, 6):error("Unable to find boost libraries in PREFIX=$${PREFIX}")
if($$system(sdl-config --version)):error("sdl-config not found in PATH - libSDL_mixer, libSDL are required!")
UNAME = $$system(uname -s)
BSD = $$find(UNAME, "BSD")
@@ -503,6 +516,7 @@ mac {
LIBS += /usr/local/lib/libboost_thread.a
LIBS += /usr/local/lib/libboost_filesystem.a
LIBS += /usr/local/lib/libboost_regex.a
LIBS += /usr/local/lib/libboost_random.a
LIBS += /usr/local/lib/libboost_system.a
LIBS += /usr/local/lib/libboost_iostreams.a
LIBS += /usr/local/lib/libgsasl.a
+14 -3
View File
@@ -140,6 +140,7 @@ win32 {
LIBS += -lboost_regex-mt
LIBS += -lboost_program_options-mt
LIBS += -lboost_iostreams-mt
LIBS += -lboost_random-mt
LIBS += -lboost_system-mt
}
win32-g++ {
@@ -150,6 +151,7 @@ win32 {
LIBS += -lboost_regex-mgw45-mt-1_45
LIBS += -lboost_program_options-mgw45-mt-1_45.dll
LIBS += -lboost_iostreams-mgw45-mt-1_45.dll
LIBS += -lboost_random-mgw45-mt-1_45.dll
LIBS += -lboost_system-mgw45-mt-1_45.dll
}
@@ -194,7 +196,7 @@ unix : !mac {
BOOST_IOSTREAMS = boost_iostreams boost_iostreams-mt
BOOST_SYS = boost_system boost_system-mt
BOOST_REGEX = boost_regex boost_regex-mt
BOOST_RANDOM = boost_random boost_random-mt
#
# searching in $PREFIX/lib and $PREFIX/lib64
@@ -243,6 +245,14 @@ unix : !mac {
message("Found $$lib")
BOOST_REGEX = -l$$lib
}
for(lib, BOOST_RANDOM):exists($${dir}/lib$${lib}.so*) {
message("Found $$lib")
BOOST_RANDOM = -l$$lib
}
for(lib, BOOST_RANDOM):exists($${dir}/lib$${lib}.a) {
message("Found $$lib")
BOOST_RANDOM = -l$$lib
}
for(lib, BOOST_SYS):exists($${dir}/lib$${lib}.so*) {
message("Found $$lib")
BOOST_SYS = -l$$lib
@@ -253,8 +263,8 @@ unix : !mac {
}
}
}
BOOST_LIBS = $$BOOST_THREAD $$BOOST_FS $$BOOST_PROGRAM_OPTIONS $$BOOST_IOSTREAMS $$BOOST_REGEX $$BOOST_SYS
!count(BOOST_LIBS, 6){
BOOST_LIBS = $$BOOST_THREAD $$BOOST_FS $$BOOST_PROGRAM_OPTIONS $$BOOST_IOSTREAMS $$BOOST_REGEX $$BOOST_RANDOM $$BOOST_SYS
!count(BOOST_LIBS, 7){
error("Unable to find boost libraries in PREFIX=$${PREFIX}")
}
@@ -304,6 +314,7 @@ mac {
LIBS += /usr/local/lib/libboost_thread.a
LIBS += /usr/local/lib/libboost_filesystem.a
LIBS += /usr/local/lib/libboost_regex.a
LIBS += /usr/local/lib/libboost_random.a
LIBS += /usr/local/lib/libboost_system.a
LIBS += /usr/local/lib/libboost_iostreams.a
LIBS += /usr/local/lib/libboost_program_options.a
+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.