Esempio n. 1
0
bool CDeck::AutoSapaw(int const pIdx)
{
    //This disables strategy, the player may want to choose where to sapaw
    //in order to inhibit his opponents from 'calling'

    CCardStack *Stack = PlayerHand[pIdx]->GetCardStack();

    int Idx = 0;
    //checks all the cards, performs sapaw until not able to do so
    for(VI vi = Stack->begin(); vi != Stack->end(); ++vi) {

        PlayerHand[pIdx]->SelectCard(Idx);

        CCardStack *cs = new CCardStack;

        for(int i = 0; i < 3; i++) {

            for(int j = 0; j < 6; j++) {

                SDL_PumpEvents();
                if((Sets[i][j] != NULL) && !Sets[i][j]->Empty()) {

                    cs->Clear();
                    cs->Push(PlayerHand[pIdx]->GetSelectedCards());
                    CCardStack set = *Sets[i][j];
                    cs->Push(set);

                    if(VerifySet(cs)) {

                        cs->Clear();
                        cs->Push(PlayerHand[pIdx]->PopSelectedCards());
                        cs->SetCardsFaceUp(true);

                        Sets[i][j]->Push(*cs);
                        Sets[i][j]->Sort();

                        mGame.InitDrag(cs, PlayerHand[pIdx], -1 , -1);
                        mGame.DoDrop(ValidSet[i]);

                        ValidSet[i]->Clear();
                        ValidSet[i]->Push(ExtractSet(i));
                        ValidSet[i]->InitCardCoords();

                        mGame.DrawStaticScene();

                        if(i != pIdx)
                            Nasapawan[i] = true;//CALL

                        return true;
                    }
                }
            }
        }

        PlayerHand[pIdx]->InitCardCoords(); //select a different card
        Idx++;
        delete cs;

    }//end of for loop

    PlayerHand[pIdx]->InitCardCoords();
    return false;
}
Esempio n. 2
0
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;
}