detemine player who need to show their cards at the end of the hand. this version is possibly buggy, because its tested marginal. additionally the lastActionPlayer is determined not correctly so far.

This commit is contained in:
floty
2010-07-22 06:03:11 +00:00
parent e743f0be85
commit aae32164ff
10 changed files with 263 additions and 80 deletions
+164 -26
View File
@@ -239,39 +239,177 @@ void LocalBoard::distributePot() {
void LocalBoard::determinePlayerNeedToShowCards() {
// all winners have to show their cards
playerNeedToShowCards = winners;
// // the player who has done the last action has to show his cards first
// playerNeedToShowCards.push_back(currentHand->getCurrentBeRo()->getLastActionPlayer());
// all winners have to show their cards
// playerNeedToShowCards = winners;
// std::_List_const_iterator<unsigned> it_c;
std::list<int*> level;
// for(it_c=winners.begin(); it_c != winners.end(); it_c++) {
// cout << (*it_c) << endl;
// }
//
// // get position und cardsValue of the player who show his cards first
// PlayerListConstIterator lastActionPlayerIt = currentHand->getActivePlayerIt(currentHand->getCurrentBeRo()->getLastActionPlayer());
// int highestCardsValueInt = (*lastActionPlayerIt)->getMyCardsValueInt();
// cout << "lastActionPlayer" << currentHand->getCurrentBeRo()->getLastActionPlayer() << endl;
//
// // search for more player who have to show their cards (perhaps not all situation are considered yet)
// PlayerListConstIterator it_c;
// for(it_c = ++lastActionPlayerIt; it_c!=activePlayerList->end(); it_c++) {
// if((*it_c)->getMyCardsValueInt() >= highestCardsValueInt) {
// playerNeedToShowCards.push_back((*it_c)->getMyUniqueID());
// highestCardsValueInt = (*it_c)->getMyCardsValueInt();
// int lastActionPlayer = ;
//
// if(lastActionPlayer == -1) {
// lastActionPlayer = 0;
// }
//
//
//
PlayerListConstIterator lastActionPlayerIt;
PlayerListConstIterator it_c;
// search lastActionPlayer
for(it_c = activePlayerList->begin(); it_c != activePlayerList->end(); it_c++) {
// cout << (*it_c)->getMyUniqueID() << ',';
if((*it_c)->getMyUniqueID() == currentHand->getCurrentBeRo()->getLastActionPlayer() && (*it_c)->getMyAction() != PLAYER_ACTION_FOLD) {
lastActionPlayerIt = it_c;
}
}
// cout << endl;
if(it_c == activePlayerList->end()) {
for(it_c = activePlayerList->begin(); it_c != activePlayerList->end(); it_c++) {
if((*it_c)->getMyAction() != PLAYER_ACTION_FOLD) {
lastActionPlayerIt = it_c;
break;
}
}
}
// the player who has done the last action has to show his cards first
playerNeedToShowCards.push_back((*lastActionPlayerIt)->getMyUniqueID());
int *level_tmp = new int[2];
// get position und cardsValue of the player who show his cards first
level_tmp[0] = (*lastActionPlayerIt)->getMyCardsValueInt();
level_tmp[1] = (*lastActionPlayerIt)->getMyRoundStartCash()-(*lastActionPlayerIt)->getMyCash();
// level_tmp = {(*lastActionPlayerIt)->getMyCardsValueInt(),(*lastActionPlayerIt)->getMyRoundStartCash()-(*lastActionPlayerIt)->getMyCash()};
// cout << level_tmp[0] << "," << level_tmp[1] << endl;
level.push_back(level_tmp);
std::_List_iterator<int*> level_it;
std::_List_iterator<int*> level_it_tmp;
std::_List_iterator<int*> next_level_it;
// PlayerListConstIterator firstAfterLastActionPlayerIt = lastActionPlayerIt;
// firstAfterLastActionPlayerIt++;
it_c = lastActionPlayerIt;
it_c++;
for(int i = 0; i < activePlayerList->size(); i++) {
if(it_c == activePlayerList->end()) it_c = activePlayerList->begin();
if((*it_c)->getMyAction() != PLAYER_ACTION_FOLD) {
// for(it_c = firstAfterLastActionPlayerIt; it_c != lastActionPlayerIt; it_c++) {
// if(it_c == lastActionPlayerIt) {
// break;
// }
// }
for(level_it = level.begin(); level_it != level.end(); level_it++) {
if((*it_c)->getMyCardsValueInt() > (*level_it)[0]) {
next_level_it = level_it;
next_level_it++;
if(next_level_it == level.end()) {
playerNeedToShowCards.push_back((*it_c)->getMyUniqueID());
level_tmp = new int[2];
level_tmp[0] = (*it_c)->getMyCardsValueInt();
level_tmp[1] = (*it_c)->getMyRoundStartCash()-(*it_c)->getMyCash();
level.push_back(level_tmp);
break;
}
} else {
if((*it_c)->getMyCardsValueInt() == (*level_it)[0]) {
next_level_it = level_it;
next_level_it++;
for(level_it_tmp = level.begin(); level_it_tmp != level.end(); level_it_tmp++) {
cout << (*level_it_tmp)[0] << "," << (*level_it_tmp)[1] << endl;
}
if(next_level_it == level.end() || (*it_c)->getMyRoundStartCash()-(*it_c)->getMyCash() > (*next_level_it)[1]) {
playerNeedToShowCards.push_back((*it_c)->getMyUniqueID());
if((*it_c)->getMyRoundStartCash()-(*it_c)->getMyCash() > (*level_it)[1]) {
(*level_it)[1] = (*it_c)->getMyRoundStartCash()-(*it_c)->getMyCash();
}
}
break;
} else {
if((*it_c)->getMyRoundStartCash()-(*it_c)->getMyCash() > (*level_it)[1]) {
playerNeedToShowCards.push_back((*it_c)->getMyUniqueID());
level_tmp = new int(2);
level_tmp[0] = (*it_c)->getMyCardsValueInt();
level_tmp[1] = (*it_c)->getMyRoundStartCash()-(*it_c)->getMyCash();
for(level_it_tmp = level.begin(); level_it_tmp != level.end(); level_it_tmp++) {
cout << (*level_it_tmp)[0] << "," << (*level_it_tmp)[1] << endl;
}
level.insert(level_it,level_tmp);
for(level_it_tmp = level.begin(); level_it_tmp != level.end(); level_it_tmp++) {
cout << (*level_it_tmp)[0] << "," << (*level_it_tmp)[1] << endl;
}
break;
}
}
}
}
}
it_c++;
}
// bool showCards;
// search for more player who have to show their cards (perhaps not all situation are considered yet)
// for(it_c = ++lastActionPlayerIt; it_c!=activePlayerList->end(); it_c++) {
//
// showCards = false;
//
//// if((*it_c)->getMyCardsValueInt() >= highestCardsValueInt) {
//// playerNeedToShowCards.push_back((*it_c)->getMyUniqueID());
//// highestCardsValueInt = (*it_c)->getMyCardsValueInt();
//// }
// }
//
// for(it_c = activePlayerList->begin(); it_c!=lastActionPlayerIt; it_c++) {
// if((*it_c)->getMyCardsValueInt() >= highestCardsValueInt) {
// playerNeedToShowCards.push_back((*it_c)->getMyUniqueID());
// highestCardsValueInt = (*it_c)->getMyCardsValueInt();
// }
//// if((*it_c)->getMyCardsValueInt() >= highestCardsValueInt) {
//// playerNeedToShowCards.push_back((*it_c)->getMyUniqueID());
//// highestCardsValueInt = (*it_c)->getMyCardsValueInt();
//// }
// }
//
// // sort and unique the list
// playerNeedToShowCards.sort();
// playerNeedToShowCards.unique();
//
// for(it_c = activePlayerList->begin(); it_c!=activePlayerList->end(); it_c++) {
// cout << (*it_c)->getMyUniqueID() << '\t';
// }
// cout << endl;
// sort and unique the list
playerNeedToShowCards.sort();
playerNeedToShowCards.unique();
std::_List_iterator<unsigned> playerNeedToShowCardsIt;
for(playerNeedToShowCardsIt = playerNeedToShowCards.begin(); playerNeedToShowCardsIt!=playerNeedToShowCards.end(); playerNeedToShowCardsIt++) {
cout << (*playerNeedToShowCardsIt) << '\t';
}
cout << endl;
}