bool CCardRegion::SuitBuilt() { if(InternalStack.Size() != 13){ return false; } for(VI vi = InternalStack.begin(); vi != InternalStack.end(); ++vi){ if(vi->Suit() != (vi+1)->Suit()){ return false; } } return true; }
bool CDeck::VerifySet(CCardStack *pStack) { pStack->Sort(); if(pStack->Size() < 3) return false; for(VI vi = pStack->begin(); vi != pStack->end(); ++vi) { if(vi == pStack->end() - 1) return true; //same ranks means valid set if(vi->Rank() != (vi + 1)->Rank()) break; //different rank, exit loop } for(VI vi = pStack->begin(); vi != pStack->end(); ++vi) { if(vi == pStack->end() - 1) break;//same suits, exit loop if( vi->Suit() != (vi + 1)->Suit() ) return false;//different suits, not a valid set } int rank; for(VI vi = pStack->begin(); vi != pStack->end(); ++vi) { if(vi == pStack->end() - 1) return true;//ascending rank, valid set rank = (vi + 1)->Rank () - vi->Rank(); if( rank != 1 ) return false;//invalid set } }
bool CDeck::FindValidSet(int const pIdx) { if(PlayerHand[pIdx]->GetNumSelectedCards() > 0) return false; //should not select any CCardStack *Stack = PlayerHand[pIdx]->GetCardStack(); int Idx = 0; for(VI vi = Stack->begin(); vi != Stack->end(); ++vi) { SDL_PumpEvents(); int Rank = vi->Rank(); int Suit = vi->Suit(); int a = PlayerHand[pIdx]->FindCard(Rank + 1, Suit); int b = PlayerHand[pIdx]->FindCard(Rank + 2, Suit); int c = PlayerHand[pIdx]->FindCard(Rank - 1, Suit); int d = PlayerHand[pIdx]->FindCard(Rank - 2, Suit); int e[3]; //cards with same suit e[0] = PlayerHand[pIdx]->FindMoreSameRank(0, Rank, Suit); if(e[0] != -1) { e[1] = PlayerHand[pIdx]->FindMoreSameRank(e[0] + 1, Rank, Suit); if(e[1] != -1) e[2] = PlayerHand[pIdx]->FindMoreSameRank(e[1] + 1, Rank, Suit); } if(a != -1 && b != -1) { PlayerHand[pIdx]->SelectCard(Idx); PlayerHand[pIdx]->SelectCard(a); PlayerHand[pIdx]->SelectCard(b); return true; } if(a != -1 && c != -1) { PlayerHand[pIdx]->SelectCard(Idx); PlayerHand[pIdx]->SelectCard(a); PlayerHand[pIdx]->SelectCard(c); return true; } if(c != -1 && d != -1) { PlayerHand[pIdx]->SelectCard(Idx); PlayerHand[pIdx]->SelectCard(c); PlayerHand[pIdx]->SelectCard(d); return true; } if(e[0] != -1 && e[1] != -1) { PlayerHand[pIdx]->SelectCard(Idx); PlayerHand[pIdx]->SelectCard(e[0]); PlayerHand[pIdx]->SelectCard(e[1]); if(e[2] != -1) PlayerHand[pIdx]->SelectCard(e[2]); return true; } Idx++; }//end of for loop return false; }