所以我正在进行扑克模拟,需要能够排名。
所以我列举了卡的排名(数量)
enum Rank{ace=1, two, three, four, five, six, seven, eight, nine, ten, jack, queen, king};
一切正常,但Aces应该很高
所以我现在把它改成了
enum Rank{ two=2, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace};
所以这个模拟有一个Hand对象(五张牌),我试图按等级对它们的矢量进行排序。
我试图根据他们的手牌等级(同花顺,直线等)对(sort(vector<Hand>.begin(),vector<Hand>.end(), poker_rank)
手的矢量进行排序。
它曾经工作,现在它给我上面的错误
有很多代码,所以我不打算发布它,但任何人都有任何想法为什么更改枚举可能会导致此错误,特别是因为函数poker_rank仍然很好,一切仍然有效?
这是一切
getRank方法返回手的等级9 = straightflush 8 =四种类型7 =满屋6 =冲洗5 =直4 =三种3 =两对2 =对1 =无序
我的poker_rank
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>