所以我正在做一个扑克模拟,需要能够对手牌进行排名。
所以我将卡等级(编号)列举为
enum Rank{ace=1, two, three, four, five, six, seven, eight, nine, ten, jack, queen, king};
一切都很好,除了 A 应该很高
所以我现在把它改成
enum Rank{ two=2, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace};
所以这个模拟有一个手对象(五张牌),我试图按等级对它们的向量进行排序。我正在尝试(sort(vector<Hand>.begin(),vector<Hand>.end(), poker_rank)
根据手牌(同花顺、顺牌等)对手牌向量进行排序。它曾经可以工作,现在它给了我上面的错误
有很多代码,所以我不打算发布它,但是任何人都知道为什么更改枚举可能会导致此错误,特别是因为函数 poker_rank 仍然很好并且一切仍然有效?
这就是一切
getRank 方法返回手牌的点数 9=同花顺 8=同花顺 7=满屋 6=同花顺 5=顺子 4=同花顺 3=两对 2=对 1=无序
我的扑克等级
bool poker_rank(const Hand& first, const Hand& second){
Card midCard1 = first.getHand().at(2);
Card lastCard1 = first.getHand().back();
Card midCard2 = second.getHand().at(2);
Card lastCard2 = second.getHand().back();
if(first.getRank() > second.getRank()){
return true;
}
if(first.getRank() == second.getRank()){
if(first.getRank()==9){
return lastCard1 > lastCard2;
}
if(first.getRank()==8){
return fullFourCheck(first, second);
}
if(first.getRank()==7){
return fullFourCheck(first, second);
}
if(first.getRank()==6){
}
if(first.getRank()==5){
return straightRank(first, second);
}
if(first.getRank()==4){
}
if(first.getRank()==3){
return twoPairRank(first, second);
}
if(first.getRank()==2){
return pairRank(first, second);
}
if(first.getRank()==1){
}
}else{
return false;
}
return false;
}<code>
辅助方法
<pre>bool fullFourCheck(const Hand& first, const Hand& second){//This Works!
Card firstCard1 = first.getHand().front();
Card midCard1 = first.getHand().at(2);
Card lastCard1 = first.getHand().back();
Card firstCard2 = second.getHand().front();
Card midCard2 = second.getHand().at(2);
Card lastCard2 = second.getHand().back();
if(midCard1 > midCard2){
return true;
}
if(midCard1 == lastCard1){
if(midCard2==lastCard2){
return firstCard1 > firstCard2;
}
if(midCard2==firstCard2){
return firstCard1 > lastCard2;
}
}
if(midCard1 == firstCard1){
if(midCard2==lastCard2){
return lastCard1> firstCard2;
}
if(midCard2==firstCard2){
return lastCard1 > lastCard2;
}
}
return false;
}
bool straightRank(const Hand& first, const Hand& second){//This WORKS!
Card firstCard1 = first.getHand().front();
Card lastCard1 = first.getHand().back();
Card firstCard2 = second.getHand().front();
Card lastCard2 = second.getHand().back();
if(firstCard1.rank_==1 && firstCard2.rank_==1){
if(lastCard1.rank_==13 && lastCard2.rank_==5){
return true;
}else{
return false;
}
}
else if((firstCard1.rank_==1 && lastCard1.rank_==13)
||(firstCard2.rank_==1&&lastCard2.rank_==5)){
return true;
}
else if((firstCard1.rank_==1 && lastCard1.rank_==5)
||(firstCard2.rank_==1&&lastCard2.rank_==13)){
return false;
}
else{
return lastCard1 > lastCa`enter code here`rd2;
}
}
bool twoPairRank(const Hand& first, const Hand& second){//This WORKS!
Card firstCard1 = first.getHand().front();
Card secondCard1 = first.getHand().at(1);
Card midCard1 = first.getHand().at(2);
Card fourthCard1 = first.getHand().at(3);
Card lastCard1 = first.getHand().back();
Card firstCard2 = second.getHand().front();
Card secondCard2 = second.getHand().at(1);
Card midCard2 = second.getHand().at(2);
Card fourthCard2 = second.getHand().at(4);
Card lastCard2 = second.getHand().back();
if(secondCard1.rank_==1 && secondCard2.rank_!=1){
return true;
}
if(fourthCard1 > fourthCard2){
return true;
}
if(fourthCard1==fourthCard2){
if(secondCard1>secondCard2){
return true;
}
if(secondCard1==secondCard2){
if(midCard1==secondCard1 && midCard2==secondCard2){
return firstCard1 > firstCard2;
}
if(midCard1==secondCard1 && midCard2==fourthCard2){
return firstCard1 > lastCard2;
}
if(midCard1==fourthCard1 && midCard2==secondCard2){
return lastCard1 > firstCard1;
}
if(midCard1==fourthCard1 && midCard2==fourthCard2){
return lastCard1 > lastCard2;
}else{
return midCard1 > midCard2;
}
}
}
return false;
}
bool pairRank(const Hand& first, const Hand& second){//This WORKS!
Card pairInFirst;
Card pairInSecond;
for(int i = 0; i < first.size()-1; i++){
if(first.getHand().at(i)==first.getHand().at(i+1)){
pairInFirst = first.getHand().at(0);
break;
}
}
for(int i = 0; i < second.size()-1; i++){
if(second.getHand().at(i)==second.getHand().at(i+1)){
pairInSecond = first.getHand().at(0);
break;
}
}
vector<Card> firstTemp;
vector<Card> secondTemp;
if((pairInFirst > pairInSecond)||(pairInFirst.rank_==1 && pairInSecond.rank_!=1)){
return true;
}else if(pairInFirst==pairInSecond){
for(int i = 0; i < first.size(); i++){
if(!(first.getHand().at(i)==pairInFirst)){
firstTemp.push_back(first.getHand().at(i));
}
}
for(int i =0; i < second.size(); i++){
if(!(second.getHand().at(i)==pairInSecond)){
secondTemp.push_back(second.getHand().at(i));
}
}
}
return false;
}<code>