elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Curso de javascript por TickTack


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Poker[C]
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Poker[C]  (Leído 1,724 veces)
HRSLASH

Desconectado Desconectado

Mensajes: 33



Ver Perfil
Poker[C]
« en: 21 Febrero 2011, 21:29 pm »

Hola gente del foro!! Dejo un codigo de poker al que le puse todas las funciones para determinar el punto de la mano.. Espero comentarios!! Saludos!!

Código
  1.  
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<time.h>
  5.  
  6. void shuffle(int [][13]);
  7. void deal(int [][13], const char *[], const char *[]);
  8. void bubble(int n[], int size);
  9.  
  10. main()
  11. {
  12.    srand(time(NULL));
  13.    int i, j, desk[4][13] = {0};
  14.    const char *suit[4] = {"Corazones", "Diamantes", "Trebol", "Espadas"};
  15.    const char *faces[13] = {"As", "Dos", "Tres", "Cuatro", "Cinco", "Seis", "Siete",
  16.                             "Ocho", "Nueve", "Diez", "Jack", "Reina", "Rey"};
  17.  
  18.    shuffle(desk);
  19.    deal(desk, suit, faces);
  20.  
  21.    return 0;
  22. }
  23.  
  24.  
  25.  
  26.  
  27.  
  28. void shuffle(int d[][13])
  29. {
  30.    int row, column, card;
  31.  
  32.    for (card = 1; card < 53; card++){
  33.        row = rand() % 4;
  34.        column = rand() % 13;
  35.        while (d[row][column] != 0){
  36.            row = rand() % 4;
  37.            column = rand() % 13;
  38.        }
  39.        d[row][column] = card;
  40.    }
  41. }
  42.  
  43. void deal(int d[][13], const char *s[], const char *f[])
  44. {
  45.    int deck2[4][13] = {0};
  46.    int row, column, card, pnt = 0, i;
  47.    int royalFlush(const int [][13]);
  48.    int straightFlush(const int [][13]);
  49.    int poker(const int [][13]);
  50.    int fullHouse(const int [][13]);
  51.    int flush(const int [][13]);
  52.    int straight(const int [][13]);
  53.    int threeOfAKind(const int [][13]);
  54.    int twoPair(const int [][13]);
  55.    int pair(const int [][13]);
  56.    int (*pokerArray[9])(const int) = {royalFlush, straightFlush, poker, fullHouse, flush,
  57.                                       straight, threeOfAKind, twoPair, pair};
  58.    void point(int);
  59.  
  60.  
  61.    for (card = 1; card < 6; card++){
  62.        for (row = 0; row < 4; row++){
  63.            for (column = 0; column < 13; column++){
  64.                if (d[row][column] == card){
  65.                    printf("%-6s de %-8s\n", f[column], s[row]);
  66.                    deck2[row][column] = 1;
  67.                }
  68.            }
  69.        }
  70.    }
  71.  
  72.    for (i = 0; i < 9; i++){
  73.        pnt = (*pokerArray[i])(deck2);
  74.        if (pnt != 0)
  75.            break;
  76.    }
  77.    point(pnt);
  78. }
  79.  
  80.  
  81.  
  82.  
  83.  
  84. int royalFlush(const int d2[][13])
  85. {
  86.    int i, j, k = 0, cont = 0, card[5],
  87.        royal[5] = {0, 9, 10, 11, 12};
  88.  
  89.    if (flush(d2) == 5)
  90.        for (i = 0; i < 4; i++){
  91.            for (j = 0; j < 13; j++){
  92.                if (d2[i][j] == 1){
  93.                    card[k] = j;
  94.                    k++;
  95.                }
  96.            }
  97.        }
  98.    bubble(card, 5);
  99.  
  100.    for (i = 0; i < 5; i++)
  101.        if (card[i] == royal[i])
  102.            cont++;
  103.  
  104.    if (cont == 5)
  105.        return 1;
  106.  
  107.    return 0;
  108. }
  109.  
  110. int straightFlush(const int d2[][13])
  111. {
  112.    if (flush(d2) == 5)
  113.        if (straight(d2) == 6)
  114.            return 2;
  115.  
  116.    return 0;
  117. }
  118.  
  119. int poker(const int d2[][13])
  120. {
  121.    int i, j, incr, cont;
  122.  
  123.    for (incr = 0; incr < 13; incr++){
  124.        cont = 0;
  125.        for (i = 0; i < 4; i++){
  126.            for (j = incr; j <= incr; j++){
  127.                if (d2[i][j] == 1)
  128.                cont++;
  129.            }
  130.        }
  131.        if (cont == 4)
  132.            return 3;
  133.    }
  134.    return 0;
  135. }
  136.  
  137. int fullHouse(const int d2[][13])
  138. {
  139.    if (threeOfAKind(d2) == 7)
  140.        if (pair(d2) == 9)
  141.            return 4;
  142.  
  143.    return 0;
  144. }
  145.  
  146. int flush(const int d2[][13])
  147. {
  148.    int i, j, cont;
  149.  
  150.    for (i = 0; i < 4; i++){
  151.        cont = 0;
  152.        for (j = 0; j < 13; j++){
  153.            if (d2[i][j] == 1)
  154.                cont++;
  155.        }
  156.        if (cont == 5)
  157.            return 5;
  158.    }
  159.    return 0;
  160. }
  161.  
  162. int straight(const int d2[][13])
  163. {
  164.    int i, j, k = 0, temp, num[5];
  165.  
  166.    for (i = 0; i < 4; i++){
  167.        for (j = 0; j < 13; j++){
  168.            if (d2[i][j] == 1){
  169.                num[k] = j;
  170.                k++;
  171.            }
  172.        }
  173.    }
  174.    bubble(num, 5);
  175.    temp = num[0];
  176.    for (i = 1; i < 5; i++){
  177.        if (num[i] != temp + 1)
  178.            return 0;
  179.        temp = num[i];
  180.    }
  181.    return 6;
  182. }
  183.  
  184.  
  185. int threeOfAKind(const int d2[][13])
  186. {
  187.    int i, j, incr, cont;
  188.  
  189.    for (incr = 0; incr < 13; incr++){
  190.        cont = 0;
  191.        for (i = 0; i < 4; i++){
  192.            for (j = incr; j <= incr; j++){
  193.                if (d2[i][j] == 1)
  194.                cont++;
  195.            }
  196.        }
  197.        if (cont == 3)
  198.            return 7;
  199.    }
  200.    return 0;
  201. }
  202.  
  203. int twoPair(const int d2[][13])
  204. {
  205.    int i, j, incr, cont, pairCont = 0;
  206.  
  207.    for (incr = 0; incr < 13; incr++){
  208.        cont = 0;
  209.        for (i = 0; i < 4; i++){
  210.            for (j = incr; j <= incr; j++){
  211.                if (d2[i][j] == 1)
  212.                cont++;
  213.            }
  214.        }
  215.        if (cont == 2)
  216.            pairCont++;
  217.    }
  218.    if (pairCont == 2)
  219.        return 8;
  220.  
  221.    return 0;
  222. }
  223.  
  224. int pair(const int d2[][13])
  225. {
  226.    int i, j, incr, cont;
  227.  
  228.    for (incr = 0; incr < 13; incr++){
  229.        cont = 0;
  230.        for (i = 0; i < 4; i++){
  231.            for (j = incr; j <= incr; j++){
  232.                if (d2[i][j] == 1)
  233.                cont++;
  234.            }
  235.        }
  236.        if (cont == 2)
  237.            return 9;
  238.    }
  239.    return 0;
  240. }
  241.  
  242. void point(int p)
  243. {
  244.    switch (p){
  245.            case 1:
  246.                printf("\nROYAL FLUSH\n");
  247.                break;
  248.            case 2:
  249.                printf("\nSTRAIGHT FLUSH\n");
  250.                break;
  251.            case 3:
  252.                printf("\nPOKER\n");
  253.                break;
  254.            case 4:
  255.                printf("\nFULL HOUSE\n");
  256.                break;
  257.            case 5:
  258.                printf("\nFLUSH\n");
  259.                break;
  260.            case 6:
  261.                printf("\nSTRAIGHT\n");
  262.                break;
  263.            case 7:
  264.                printf("\nTHREE OF A KIND\n");
  265.                break;
  266.            case 8:
  267.                printf("\nTWO PAIR\n");
  268.                break;
  269.            case 9:
  270.                printf("\nPAIR\n");
  271.                break;
  272.            default:
  273.                printf("\nHIGH CARD\n");
  274.    }
  275. }
  276.  
  277. void bubble(int n[], int size)
  278. {
  279.    int i, j, temp;
  280.  
  281.    for (i = 0; i < size - 1; i++){
  282.        for (j = i + 1; j < size; j++){
  283.            if (n[i] > n[j]){
  284.                temp = n[i];
  285.                n[i] = n[j];
  286.                n[j] = temp;
  287.            }
  288.        }
  289.    }
  290. }
  291.  
  292.  


En línea

La televisión es para mi el medio mas instructivo y cultural que conozco, cuando la prenden me voy a leer
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Poker Set
Diseño Gráfico
+ enrique ZP 4 2,288 Último mensaje 30 Mayo 2006, 03:02 am
por Toxico
POKER
Programación Visual Basic
txakaxt 0 1,046 Último mensaje 28 Febrero 2008, 23:23 pm
por txakaxt
duda poker
Java
koven 0 1,827 Último mensaje 11 Junio 2009, 17:05 pm
por koven
jugar al poker
Redes
gabrilocha 1 1,692 Último mensaje 28 Septiembre 2012, 22:37 pm
por WIитX
Libratus, el mejor bot de póker ya machaca a los humanos
Noticias
wolfbcn 0 1,301 Último mensaje 24 Enero 2017, 02:51 am
por wolfbcn
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines