diff --git a/src/engine/local_engine/localbero.h b/src/engine/local_engine/localbero.h index 63d6f0bd..cdea8ba0 100644 --- a/src/engine/local_engine/localbero.h +++ b/src/engine/local_engine/localbero.h @@ -28,8 +28,8 @@ public: GameState getMyBeRoID() const { return myBeRoID; } - int getHighestCardsValue() const {return 0; } - void setHighestCardsValue(int theValue) {} + int getHighestCardsValue() const { std::cout << "getHighestCardsValue() in wrong BeRo" << std::endl; return 0; } + void setHighestCardsValue(int theValue) { } void resetFirstRun() { firstRun = false; } diff --git a/src/engine/local_engine/localberopostriver.cpp b/src/engine/local_engine/localberopostriver.cpp index 34d627a3..8f37025e 100644 --- a/src/engine/local_engine/localberopostriver.cpp +++ b/src/engine/local_engine/localberopostriver.cpp @@ -64,8 +64,8 @@ void LocalBeRoPostRiver::run() { // cout << "myAggressive: " << getMyHand()->getPlayerArray()[0]->getMyAggressive() << endl; // Pot-Verteilung +// getMyHand()->getBoard()->distributePot(); distributePot(); - getMyHand()->getBoard()->distributePot(); //Pot auf 0 setzen getMyHand()->getBoard()->setPot(0); diff --git a/src/engine/local_engine/localboard.cpp b/src/engine/local_engine/localboard.cpp index 01d79437..7de56d99 100755 --- a/src/engine/local_engine/localboard.cpp +++ b/src/engine/local_engine/localboard.cpp @@ -24,7 +24,7 @@ using namespace std; -LocalBoard::LocalBoard() : BoardInterface(), playerArray(0), actualHand(0), pot(0), sets(0) +LocalBoard::LocalBoard() : BoardInterface(), playerArray(0), currentHand(0), pot(0), sets(0) { } @@ -35,7 +35,7 @@ LocalBoard::~LocalBoard() void LocalBoard::setPlayer(PlayerInterface** p) { playerArray = p; } -void LocalBoard::setHand(HandInterface* br) { actualHand = br; } +void LocalBoard::setHand(HandInterface* br) { currentHand = br; } void LocalBoard::collectSets() { @@ -54,7 +54,148 @@ void LocalBoard::collectPot() { void LocalBoard::distributePot() { + size_t i,j,k; + + // filling player stes vector vector playerSets; + for(i=0; i<(size_t)MAX_NUMBER_OF_PLAYERS; i++) { + if(playerArray[i]->getMyActiveStatus()) { + playerSets.push_back(((playerArray[i]->getMyRoundStartCash())-(playerArray[i]->getMyCash()))); + } else { + playerSets.push_back(0); + } + } + + // sort player sets asc + vector playerSetsSort = playerSets; + sort(playerSetsSort.begin(), playerSetsSort.end()); + + // pot[0] = potLevel0, pot[1] = potLevel1, ... +// vector< vector > pot; + + // potLevel[0] = amount, potLevel[1] = sum, potLevel[2..n] = winner + vector potLevel; + + // temp var + int highestCardsValue; + size_t winnerCount; + size_t mod; + int winnerPointer; + bool winnerHit; + + // level loop + for(i=0; i 0) { + + // level amount + potLevel.push_back(playerSetsSort[i]); + + // level sum + potLevel.push_back((playerSetsSort.size()-i)*potLevel[0]); + + // determine level highestCardsValue + for(j=0; jgetMyCardsValueInt() > highestCardsValue && playerArray[j]->getMyActiveStatus() && playerArray[j]->getMyAction() != PLAYER_ACTION_FOLD && playerSets[j] >= potLevel[0]) { + highestCardsValue = playerArray[j]->getMyCardsValueInt(); + } + } + + // level winners + for(j=0; jgetMyCardsValueInt() && playerArray[j]->getMyActiveStatus() && playerArray[j]->getMyAction() != PLAYER_ACTION_FOLD) { + potLevel.push_back(playerArray[j]->getMyID()); + } + } + + // determine the number of level winners + winnerCount = potLevel.size()-2; + + // distribute the pot level sum to level winners + mod = (potLevel[1])%winnerCount; + // pot level sum divisible by winnerCount + if(mod == 0) { + for(j=2; jsetMyCash(playerArray[potLevel[j]]->getMyCash() + ((potLevel[1])/winnerCount)); + } + + } + // pot level sum not divisible by winnerCount + // --> distribution after smallBlind (perhaps lastActionPlayer? - TODO) + else { + + winnerPointer = currentHand->getDealerPosition(); + + for(j=0; jsetMyCash(playerArray[winnerPointer]->getMyCash() + (int)((potLevel[1])/winnerCount) + 1); + } else { + playerArray[winnerPointer]->setMyCash(playerArray[winnerPointer]->getMyCash() + (int)((potLevel[1])/winnerCount)); + } + } + } + + // reevaluate the player sets + for(j=0; j0) { + playerSets[j] -= potLevel[0]; + } + } + + // sort player sets asc + playerSetsSort = playerSets; + sort(playerSetsSort.begin(), playerSetsSort.end()); + + // pot refresh + pot -= potLevel[1]; + + // clear potLevel + potLevel.clear(); + + } + } + + + // playerSetsSort output +// for(i=0; i