Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

Algorytm ułożenia kart w Video Poker.

Ostatnio zmodyfikowano 2011-03-31 17:43
Autor Wiadomość
Dragonit
Temat założony przez niniejszego użytkownika
Algorytm ułożenia kart w Video Poker.
» 2011-03-30 11:08:15
Witam. Głowie się już od 3 dni z napisaniem algorytmu sprawdzających ułożenie i trafienie kart w Video Pokerze.
Mam tablice gdzie przechowuję wylosowane liczby(
short int wylosowane[ 5 ]
), jest 5 rzędów kart, w każdym rzędzie znajduje się wylosowana liczba od 0 do 26.

0 - liczba nie losowana, potrzebne gdy karta obrócona
1-4 - A(4 kolory)
5-8 - K(4 kolory)
9-12 - Q(4 kolory)
13-16 - J(4 kolory)
17-20 - 10(4 kolory)
21-24 - 9(4 kolory)
25-26 - Jocker(czarny, czerwony)

Czyli jeśli mam takie wylosowane karty:
wylosowane[ 0 ] = 9
 i
wylosowane[ 1 ] = 10
 ma mi pokazać, że mam 1 parę Dam.

Nie mam pojęcia czy jest to w ogóle możliwe do wykonania nie pisząc wszystkich możliwych kombinacji(czyli z jakiś milion linijek kodu). Jeśli ktoś ma jakieś pomysły proszę o podzielenie się nimi.

EDIT: Jest jeden Jocker.

P-29968
DejaVu
» 2011-03-30 13:00:15
A co to za problem zrobić licznik do zliczania liczby takich samych kart?
P-29969
Dragonit
Temat założony przez niniejszego użytkownika
» 2011-03-30 14:27:19
Co masz na myśli? Ja muszę wiedzieć w jakich rzędach dzieje się akcja i jakie karty biorą w nich udział.
P-29972
DejaVu
» 2011-03-30 16:40:31
To napisz sobie funkcję do każdej kolejki (rzędu), która sprawdza czy jest karta danego typu. A potem:
C/C++
ile = 0;
for( int i = 0; i < 5; i++ )
     if( czyDama( rzad[ i ] ) ) ile++;

std::cout << "Masz " << ile << " dam.";
P-30002
Dragonit
Temat założony przez niniejszego użytkownika
» 2011-03-31 15:41:14
Panie Piotrze naprowadził mnie pan na dobry kierunek i udało mi się wymyślić coś takiego:

C/C++
int wylosSprawdzone[ 5 ]; // tablica liczb nie powtarzaj¹cych sie(przechowuje wylosowane liczby od 1 do 25)

struct karta
{
    unsigned short int As, Krol, Dama, Walet, Dzies, Dziew, Jocker;
   
} czyTrafiona, ileKart;

unsigned short int coTrafilo;

void SprawdzanieKart()
{
    for( unsigned short int i = 0; i < 5; i++ )
    {
        if( wylosSprawdzone[ i ] == 1 || wylosSprawdzone[ i ] == 2 ||
        wylosSprawdzone[ i ] == 3 || wylosSprawdzone[ i ] == 4 ) czyTrafiona.As = true;
        else czyTrafiona.As = false;
       
        if( wylosSprawdzone[ i ] == 5 || wylosSprawdzone[ i ] == 6 ||
        wylosSprawdzone[ i ] == 7 || wylosSprawdzone[ i ] == 8 ) czyTrafiona.Krol = true;
        else czyTrafiona.Krol = false;
       
        if( wylosSprawdzone[ i ] == 13 || wylosSprawdzone[ i ] == 14 ||
        wylosSprawdzone[ i ] == 15 || wylosSprawdzone[ i ] == 16 ) czyTrafiona.Dama = true;
        else czyTrafiona.Dama = false;
       
        if( wylosSprawdzone[ i ] == 9 || wylosSprawdzone[ i ] == 10 ||
        wylosSprawdzone[ i ] == 11 || wylosSprawdzone[ i ] == 12 ) czyTrafiona.Walet = true;
        else czyTrafiona.Walet = false;
       
        if( wylosSprawdzone[ i ] == 17 || wylosSprawdzone[ i ] == 18 ||
        wylosSprawdzone[ i ] == 19 || wylosSprawdzone[ i ] == 20 ) czyTrafiona.Dzies = true;
        else czyTrafiona.Dzies = false;
       
        if( wylosSprawdzone[ i ] == 21 || wylosSprawdzone[ i ] == 22 ||
        wylosSprawdzone[ i ] == 23 || wylosSprawdzone[ i ] == 24 ) czyTrafiona.Dziew = true;
        else czyTrafiona.Dziew = false;
       
        if( wylosSprawdzone[ i ] == 25 ) czyTrafiona.Jocker = true;
        else czyTrafiona.Jocker = false;
       
        if( czyTrafiona.As == true ) ileKart.As++;
       
        if( czyTrafiona.Krol == true ) ileKart.Krol++;
       
        if( czyTrafiona.Dama == true ) ileKart.Dama++;
       
        if( czyTrafiona.Walet == true ) ileKart.Walet++;
       
        if( czyTrafiona.Dzies == true ) ileKart.Dzies++;
       
        if( czyTrafiona.Dziew == true ) ileKart.Dziew++;
       
        if( czyTrafiona.Jocker == true ) ileKart.Jocker++;
       
    }
   
    // PIATKA
    if( ileKart.As == 4 && ileKart.Jocker == 1 ||
    ileKart.Krol == 4 && ileKart.Jocker == 1 ||
    ileKart.Dama == 4 && ileKart.Jocker == 1 ||
    ileKart.Walet == 4 && ileKart.Jocker == 1 ||
    ileKart.Dzies == 4 && ileKart.Jocker == 1 ||
    ileKart.Dziew == 4 && ileKart.Jocker == 1 ) coTrafilo = 5;
   
    // KARETA
    else if( ileKart.As == 4 ||( ileKart.As == 3 && ileKart.Jocker == 1 ) ||
    ileKart.Krol == 4 ||( ileKart.Krol == 3 && ileKart.Jocker == 1 ) ||
    ileKart.Dama == 4 ||( ileKart.Dama == 3 && ileKart.Jocker == 1 ) ||
    ileKart.Walet == 4 ||( ileKart.Walet == 3 && ileKart.Jocker == 1 ) ||
    ileKart.Dzies == 4 ||( ileKart.Dzies == 3 && ileKart.Jocker == 1 ) ||
    ileKart.Dziew == 4 ||( ileKart.Dziew == 3 && ileKart.Jocker == 1 ) ) coTrafilo = 4;
   
    // FULL
    else if( ileKart.As == 3 && ileKart.Krol == 2 ) coTrafilo = 9;
    else if( ileKart.As == 3 && ileKart.Dama == 2 ) coTrafilo = 9;
    else if( ileKart.As == 3 && ileKart.Walet == 2 ) coTrafilo = 9;
    else if( ileKart.As == 3 && ileKart.Dzies == 2 ) coTrafilo = 9;
    else if( ileKart.As == 3 && ileKart.Dziew == 2 ) coTrafilo = 9;
    else if( ileKart.Krol == 3 && ileKart.As == 2 ) coTrafilo = 9;
    else if( ileKart.Krol == 3 && ileKart.Dama == 2 ) coTrafilo = 9;
    else if( ileKart.Krol == 3 && ileKart.Walet == 2 ) coTrafilo = 9;
    else if( ileKart.Krol == 3 && ileKart.Dzies == 2 ) coTrafilo = 9;
    else if( ileKart.Krol == 3 && ileKart.Dziew == 2 ) coTrafilo = 9;
    else if( ileKart.Dama == 3 && ileKart.As == 2 ) coTrafilo = 9;
    else if( ileKart.Dama == 3 && ileKart.Krol == 2 ) coTrafilo = 9;
    else if( ileKart.Dama == 3 && ileKart.Walet == 2 ) coTrafilo = 9;
    else if( ileKart.Dama == 3 && ileKart.Dzies == 2 ) coTrafilo = 9;
    else if( ileKart.Dama == 3 && ileKart.Dziew == 2 ) coTrafilo = 9;
    else if( ileKart.Walet == 3 && ileKart.As == 2 ) coTrafilo = 9;
    else if( ileKart.Walet == 3 && ileKart.Krol == 2 ) coTrafilo = 9;
    else if( ileKart.Walet == 3 && ileKart.Dama == 2 ) coTrafilo = 9;
    else if( ileKart.Walet == 3 && ileKart.Dzies == 2 ) coTrafilo = 9;
    else if( ileKart.Walet == 3 && ileKart.Dziew == 2 ) coTrafilo = 9;
    else if( ileKart.Dzies == 3 && ileKart.As == 2 ) coTrafilo = 9;
    else if( ileKart.Dzies == 3 && ileKart.Krol == 2 ) coTrafilo = 9;
    else if( ileKart.Dzies == 3 && ileKart.Dama == 2 ) coTrafilo = 9;
    else if( ileKart.Dzies == 3 && ileKart.Walet == 2 ) coTrafilo = 9;
    else if( ileKart.Dzies == 3 && ileKart.Dziew == 2 ) coTrafilo = 9;
    else if( ileKart.Dziew == 3 && ileKart.As == 2 ) coTrafilo = 9;
    else if( ileKart.Dziew == 3 && ileKart.Krol == 2 ) coTrafilo = 9;
    else if( ileKart.Dziew == 3 && ileKart.Dama == 2 ) coTrafilo = 9;
    else if( ileKart.Dziew == 3 && ileKart.Walet == 2 ) coTrafilo = 9;
    else if( ileKart.Dziew == 3 && ileKart.Dzies == 2 ) coTrafilo = 9;
   
    else if( ileKart.As == 2 && ileKart.Jocker == 1 && ileKart.Krol == 2 ) coTrafilo = 9;
    else if( ileKart.As == 2 && ileKart.Jocker == 1 && ileKart.Dama == 2 ) coTrafilo = 9;
    else if( ileKart.As == 2 && ileKart.Jocker == 1 && ileKart.Walet == 2 ) coTrafilo = 9;
    else if( ileKart.As == 2 && ileKart.Jocker == 1 && ileKart.Dzies == 2 ) coTrafilo = 9;
    else if( ileKart.As == 2 && ileKart.Jocker == 1 && ileKart.Dziew == 2 ) coTrafilo = 9;
    else if( ileKart.Krol == 2 && ileKart.Jocker == 1 && ileKart.As == 2 ) coTrafilo = 9;
    else if( ileKart.Krol == 2 && ileKart.Jocker == 1 && ileKart.Dama == 2 ) coTrafilo = 9;
    else if( ileKart.Krol == 2 && ileKart.Jocker == 1 && ileKart.Walet == 2 ) coTrafilo = 9;
    else if( ileKart.Krol == 2 && ileKart.Jocker == 1 && ileKart.Dzies == 2 ) coTrafilo = 9;
    else if( ileKart.Krol == 2 && ileKart.Jocker == 1 && ileKart.Dziew == 2 ) coTrafilo = 9;
    else if( ileKart.Dama == 2 && ileKart.Jocker == 1 && ileKart.As == 2 ) coTrafilo = 9;
    else if( ileKart.Dama == 2 && ileKart.Jocker == 1 && ileKart.Krol == 2 ) coTrafilo = 9;
    else if( ileKart.Dama == 2 && ileKart.Jocker == 1 && ileKart.Walet == 2 ) coTrafilo = 9;
    else if( ileKart.Dama == 2 && ileKart.Jocker == 1 && ileKart.Dzies == 2 ) coTrafilo = 9;
    else if( ileKart.Dama == 2 && ileKart.Jocker == 1 && ileKart.Dziew == 2 ) coTrafilo = 9;
    else if( ileKart.Walet == 2 && ileKart.Jocker == 1 && ileKart.As == 2 ) coTrafilo = 9;
    else if( ileKart.Walet == 2 && ileKart.Jocker == 1 && ileKart.Krol == 2 ) coTrafilo = 9;
    else if( ileKart.Walet == 2 && ileKart.Jocker == 1 && ileKart.Dama == 2 ) coTrafilo = 9;
    else if( ileKart.Walet == 2 && ileKart.Jocker == 1 && ileKart.Dzies == 2 ) coTrafilo = 9;
    else if( ileKart.Walet == 2 && ileKart.Jocker == 1 && ileKart.Dziew == 2 ) coTrafilo = 9;
    else if( ileKart.Dzies == 2 && ileKart.Jocker == 1 && ileKart.As == 2 ) coTrafilo = 9;
    else if( ileKart.Dzies == 2 && ileKart.Jocker == 1 && ileKart.Krol == 2 ) coTrafilo = 9;
    else if( ileKart.Dzies == 2 && ileKart.Jocker == 1 && ileKart.Dama == 2 ) coTrafilo = 9;
    else if( ileKart.Dzies == 2 && ileKart.Jocker == 1 && ileKart.Walet == 2 ) coTrafilo = 9;
    else if( ileKart.Dzies == 2 && ileKart.Jocker == 1 && ileKart.Dziew == 2 ) coTrafilo = 9;
    else if( ileKart.Dziew == 2 && ileKart.Jocker == 1 && ileKart.As == 2 ) coTrafilo = 9;
    else if( ileKart.Dziew == 2 && ileKart.Jocker == 1 && ileKart.Krol == 2 ) coTrafilo = 9;
    else if( ileKart.Dziew == 2 && ileKart.Jocker == 1 && ileKart.Dama == 2 ) coTrafilo = 9;
    else if( ileKart.Dziew == 2 && ileKart.Jocker == 1 && ileKart.Walet == 2 ) coTrafilo = 9;
    else if( ileKart.Dziew == 2 && ileKart.Jocker == 1 && ileKart.Dzies == 2 ) coTrafilo = 9;
   
    // DUŻY STRIT
    else if( ileKart.As == 1 && ileKart.Krol == 1 && ileKart.Dama == 1 && ileKart.Walet == 1 &&
    ileKart.Dzies == 1 ) coTrafilo = 7;
    else if( ileKart.Jocker == 1 && ileKart.Krol == 1 && ileKart.Dama == 1 && ileKart.Walet == 1 &&
    ileKart.Dzies == 1 ) coTrafilo = 7;
    else if( ileKart.As == 1 && ileKart.Jocker == 1 && ileKart.Dama == 1 && ileKart.Walet == 1 &&
    ileKart.Dzies == 1 ) coTrafilo = 7;
    else if( ileKart.As == 1 && ileKart.Krol == 1 && ileKart.Jocker == 1 && ileKart.Walet == 1 &&
    ileKart.Dzies == 1 ) coTrafilo = 7;
    else if( ileKart.As == 1 && ileKart.Krol == 1 && ileKart.Dama == 1 && ileKart.Jocker == 1 &&
    ileKart.Dzies == 1 ) coTrafilo = 7;
    else if( ileKart.As == 1 && ileKart.Krol == 1 && ileKart.Dama == 1 && ileKart.Walet == 1 &&
    ileKart.Jocker == 1 ) coTrafilo = 7;
   
    // MAŁY STRIT
    else if( ileKart.Krol == 1 && ileKart.Dama == 1 && ileKart.Walet == 1 &&
    ileKart.Dzies == 1 && ileKart.Dziew == 1 ) coTrafilo = 6;
    else if( ileKart.Jocker == 1 && ileKart.Dama == 1 && ileKart.Walet == 1 &&
    ileKart.Dzies == 1 && ileKart.Dziew == 1 ) coTrafilo = 6;
    else if( ileKart.Krol == 1 && ileKart.Jocker == 1 && ileKart.Walet == 1 &&
    ileKart.Dzies == 1 && ileKart.Dziew == 1 ) coTrafilo = 6;
    else if( ileKart.Krol == 1 && ileKart.Dama == 1 && ileKart.Jocker == 1 &&
    ileKart.Dzies == 1 && ileKart.Dziew == 1 ) coTrafilo = 6;
    else if( ileKart.Krol == 1 && ileKart.Dama == 1 && ileKart.Walet == 1 &&
    ileKart.Jocker == 1 && ileKart.Dziew == 1 ) coTrafilo = 6;
    else if( ileKart.Krol == 1 && ileKart.Dama == 1 && ileKart.Walet == 1 &&
    ileKart.Dzies == 1 && ileKart.Jocker == 1 ) coTrafilo = 6;
    // TRÓJKA
    else if( ileKart.As == 3 ||( ileKart.As == 2 && ileKart.Jocker == 1 ) ||
    ileKart.Krol == 3 ||( ileKart.Krol == 2 && ileKart.Jocker == 1 ) ||
    ileKart.Dama == 3 ||( ileKart.Dama == 2 && ileKart.Jocker == 1 ) ||
    ileKart.Walet == 3 ||( ileKart.Walet == 2 && ileKart.Jocker == 1 ) ||
    ileKart.Dzies == 3 ||( ileKart.Dzies == 2 && ileKart.Jocker == 1 ) ||
    ileKart.Dziew == 3 ||( ileKart.Dziew == 2 && ileKart.Jocker == 1 ) ) coTrafilo = 3;
   
    // 2 PARY
    else if( ileKart.As == 2 && ileKart.Krol == 2 ) coTrafilo = 8;
    else if( ileKart.As == 2 && ileKart.Dama == 2 ) coTrafilo = 8;
    else if( ileKart.As == 2 && ileKart.Walet == 2 ) coTrafilo = 8;
    else if( ileKart.As == 2 && ileKart.Dzies == 2 ) coTrafilo = 8;
    else if( ileKart.As == 2 && ileKart.Dziew == 2 ) coTrafilo = 8;
    else if( ileKart.Krol == 2 && ileKart.Dama == 2 ) coTrafilo = 8;
    else if( ileKart.Krol == 2 && ileKart.Walet == 2 ) coTrafilo = 8;
    else if( ileKart.Krol == 2 && ileKart.Dzies == 2 ) coTrafilo = 8;
    else if( ileKart.Krol == 2 && ileKart.Dziew == 2 ) coTrafilo = 8;
    else if( ileKart.Dama == 2 && ileKart.Walet == 2 ) coTrafilo = 8;
    else if( ileKart.Dama == 2 && ileKart.Dzies == 2 ) coTrafilo = 8;
    else if( ileKart.Dama == 2 && ileKart.Dziew == 2 ) coTrafilo = 8;
    else if( ileKart.Walet == 2 && ileKart.Dzies == 2 ) coTrafilo = 8;
    else if( ileKart.Walet == 2 && ileKart.Dziew == 2 ) coTrafilo = 8;
    else if( ileKart.Dzies == 2 && ileKart.Dziew == 2 ) coTrafilo = 8;
   
    else if( ileKart.As == 1 && ileKart.Jocker == 1 && ileKart.Krol == 2 ) coTrafilo = 8;
    else if( ileKart.As == 1 && ileKart.Jocker == 1 && ileKart.Dama == 2 ) coTrafilo = 8;
    else if( ileKart.As == 1 && ileKart.Jocker == 1 && ileKart.Walet == 2 ) coTrafilo = 8;
    else if( ileKart.As == 1 && ileKart.Jocker == 1 && ileKart.Dzies == 2 ) coTrafilo = 8;
    else if( ileKart.As == 1 && ileKart.Jocker == 1 && ileKart.Dziew == 2 ) coTrafilo = 8;
    else if( ileKart.Krol == 1 && ileKart.Jocker == 1 && ileKart.As == 2 ) coTrafilo = 8;
    else if( ileKart.Krol == 1 && ileKart.Jocker == 1 && ileKart.Dama == 2 ) coTrafilo = 8;
    else if( ileKart.Krol == 1 && ileKart.Jocker == 1 && ileKart.Walet == 2 ) coTrafilo = 8;
    else if( ileKart.Krol == 1 && ileKart.Jocker == 1 && ileKart.Dzies == 2 ) coTrafilo = 8;
    else if( ileKart.Krol == 1 && ileKart.Jocker == 1 && ileKart.Dziew == 2 ) coTrafilo = 8;
    else if( ileKart.Dama == 1 && ileKart.Jocker == 1 && ileKart.As == 2 ) coTrafilo = 8;
    else if( ileKart.Dama == 1 && ileKart.Jocker == 1 && ileKart.Krol == 2 ) coTrafilo = 8;
    else if( ileKart.Dama == 1 && ileKart.Jocker == 1 && ileKart.Walet == 2 ) coTrafilo = 8;
    else if( ileKart.Dama == 1 && ileKart.Jocker == 1 && ileKart.Dzies == 2 ) coTrafilo = 8;
    else if( ileKart.Dama == 1 && ileKart.Jocker == 1 && ileKart.Dziew == 2 ) coTrafilo = 8;
    else if( ileKart.Walet == 1 && ileKart.Jocker == 1 && ileKart.As == 2 ) coTrafilo = 8;
    else if( ileKart.Walet == 1 && ileKart.Jocker == 1 && ileKart.Krol == 2 ) coTrafilo = 8;
    else if( ileKart.Walet == 1 && ileKart.Jocker == 1 && ileKart.Dama == 2 ) coTrafilo = 8;
    else if( ileKart.Walet == 1 && ileKart.Jocker == 1 && ileKart.Dzies == 2 ) coTrafilo = 8;
    else if( ileKart.Walet == 1 && ileKart.Jocker == 1 && ileKart.Dziew == 2 ) coTrafilo = 8;
    else if( ileKart.Dzies == 1 && ileKart.Jocker == 1 && ileKart.As == 2 ) coTrafilo = 8;
    else if( ileKart.Dzies == 1 && ileKart.Jocker == 1 && ileKart.Krol == 2 ) coTrafilo = 8;
    else if( ileKart.Dzies == 1 && ileKart.Jocker == 1 && ileKart.Dama == 2 ) coTrafilo = 8;
    else if( ileKart.Dzies == 1 && ileKart.Jocker == 1 && ileKart.Walet == 2 ) coTrafilo = 8;
    else if( ileKart.Dzies == 1 && ileKart.Jocker == 1 && ileKart.Dziew == 2 ) coTrafilo = 8;
    else if( ileKart.Dziew == 1 && ileKart.Jocker == 1 && ileKart.As == 2 ) coTrafilo = 8;
    else if( ileKart.Dziew == 1 && ileKart.Jocker == 1 && ileKart.Krol == 2 ) coTrafilo = 8;
    else if( ileKart.Dziew == 1 && ileKart.Jocker == 1 && ileKart.Dama == 2 ) coTrafilo = 8;
    else if( ileKart.Dziew == 1 && ileKart.Jocker == 1 && ileKart.Walet == 2 ) coTrafilo = 8;
    else if( ileKart.Dziew == 1 && ileKart.Jocker == 1 && ileKart.Dzies == 2 ) coTrafilo = 8;
   
    // 1 PARA
    else if( ileKart.As == 2 ||( ileKart.As == 1 && ileKart.Jocker == 1 ) ||
    ileKart.Krol == 2 ||( ileKart.Krol == 1 && ileKart.Jocker == 1 ) ||
    ileKart.Dama == 2 ||( ileKart.Dama == 1 && ileKart.Jocker == 1 ) ||
    ileKart.Walet == 2 ||( ileKart.Walet == 1 && ileKart.Jocker == 1 ) ||
    ileKart.Dzies == 2 ||( ileKart.Dzies == 1 && ileKart.Jocker == 1 ) ||
    ileKart.Dziew == 2 ||( ileKart.Dziew == 1 && ileKart.Jocker == 1 ) ) coTrafilo = 1;
    else coTrafilo = 0;
   
    if( coTrafilo == 0 ) cout << "\nPUSTE KARTY\n";
    else if( coTrafilo == 1 ) cout << "\nJEDNA PARA\n";
    else if( coTrafilo == 2 ) cout << "\nDWIE PARY\n";
    else if( coTrafilo == 3 ) cout << "\nTRÓJKA";
    else if( coTrafilo == 4 ) cout << "\nKARETA";
    else if( coTrafilo == 5 ) cout << "\nPI¥TKA";
    else if( coTrafilo == 6 ) cout << "\nMA£Y STRIT\n";
    else if( coTrafilo == 7 ) cout << "\nDU¯Y STRIT\n";
    else if( coTrafilo == 8 ) cout << "\nDWIE PARY\n";
    else if( coTrafilo == 9 ) cout << "\nFULL\n";
   
}
Kod sprawdzony, działa. Ale został mi jeszcze Poker(Mały strit w kolorze) i Poker królewski(Dziesiątka, Walet, Dama, Król i As w jednym kolorze) i nie mam pojęcia jak wyłuskać różnicę w kolorze poszczególnych kart. Chyba zostawię jak jest bo nic nie wymyślę twórczego. Kod się może komuś przydać dlatego wrzuciłem na forum.
P-30041
malan
» 2011-03-31 17:43:32
Mi na szybko udało się wyskrobać coś takiego:
C/C++
#include <algorithm>
#include <ctime>
#include <iostream>

const int CARDS_COUNT = 5;

struct Cards
{
    int ace;
    int king;
    int queen;
    int jack;
    int nine;
    int ten;
    int joker;
   
    void print()
    {
        std::cout << "ace: " << ace << std::endl;
        std::cout << "king: " << king << std::endl;
        std::cout << "queen: " << queen << std::endl;
        std::cout << "jack: " << jack << std::endl;
        std::cout << "nine: " << nine << std::endl;
        std::cout << "ten: " << ten << std::endl;
        std::cout << "joker: " << joker << std::endl;
    }
};

void checkCards( Cards & cards, int array[], int size );
void drawing( int array[], int size );

bool isFive( int * pointersArray[], int size = 7 );
bool isFourOfAKind( int * pointersArray[], int size = 7 );

int main()
{
    Cards cards =
    {
        0,
        0,
        0,
        0,
        0,
        0,
        0
    };
   
    int * cardsPointers[ 7 ] =
    {
        & cards.ace,
        & cards.king,
        & cards.queen,
        & cards.jack,
        & cards.nine,
        & cards.ten,
        & cards.joker
    };
   
    int drawnCards[ CARDS_COUNT ];
   
    drawing( drawnCards, CARDS_COUNT );
    checkCards( cards, drawnCards, CARDS_COUNT );
   
    cards.print();
   
    std::cout << "isFive returned " << std::boolalpha << isFive( cardsPointers ) << std::endl;
    std::cout << "isFourOfAKind returned " << std::boolalpha << isFourOfAKind( cardsPointers ) << std::endl;
}

void checkCards( Cards & cards, int array[], int size )
{
    for( int i = 0; i < size; ++i )
    {
        if( array[ i ] >= 1 && array[ i ] <= 4 ) ++cards.ace;
        else
             if( array[ i ] >= 5 && array[ i ] <= 8 ) ++cards.king;
        else
             if( array[ i ] >= 9 && array[ i ] <= 12 ) ++cards.queen;
        else
             if( array[ i ] >= 13 && array[ i ] <= 16 ) ++cards.jack;
        else
             if( array[ i ] >= 17 && array[ i ] <= 20 ) ++cards.nine;
        else
             if( array[ i ] >= 21 && array[ i ] <= 24 ) ++cards.ten;
        else
             if( array[ i ] == 25 ) ++cards.joker;
       
    }
}

void drawing( int array[], int size )
{
    srand( time( 0 ) );
   
    for( int i = 0; i < size; ++i )
    {
        array[ i ] = rand() % 26 + 0;
        //std::cout << array[i] << std::endl;
    }
}

// ========================================
// \param size Array size. Must be 7!
// ========================================
bool isFive( int * pointersArray[], int size )
{
    // Without joker.
    --size;
   
    for( int i = 0; i < size; ++i )
    {
        if( * pointersArray[ i ] == 4 && * pointersArray[ 6 ] == 1 )
             return true;
       
    }
    return false;
}

// ========================================
// \param size Array size. Must be 7!
// ========================================
bool isFourOfAKind( int * pointersArray[], int size )
{
    // Without joker.
    --size;
   
    for( int i = 0; i < size; ++i )
    {
        if( * pointersArray[ i ] == 4 ||( * pointersArray[ i ] == 3 && * pointersArray[ 6 ] == 1 ) )
             return true;
       
    }
    return false;
}
Oprogramowałem tylko "piątkę" i "karetę" na razie. Nie mam teraz zbytnio czasu żeby tłumaczyć wszystko po kolei, ale przyjrzyj się i oceń, które rozwiązanie (Twoje, czy moje) jest bardziej czytelne.
P-30055
« 1 »
  Strona 1 z 1