Código
#include<stdio.h> #include<stdlib.h> #include<time.h> void shuffle(int [][13]); void deal(int [][13], const char *[], const char *[]); void bubble(int n[], int size); main() { int i, j, desk[4][13] = {0}; const char *suit[4] = {"Corazones", "Diamantes", "Trebol", "Espadas"}; const char *faces[13] = {"As", "Dos", "Tres", "Cuatro", "Cinco", "Seis", "Siete", "Ocho", "Nueve", "Diez", "Jack", "Reina", "Rey"}; shuffle(desk); deal(desk, suit, faces); return 0; } void shuffle(int d[][13]) { int row, column, card; for (card = 1; card < 53; card++){ while (d[row][column] != 0){ } d[row][column] = card; } } void deal(int d[][13], const char *s[], const char *f[]) { int deck2[4][13] = {0}; int row, column, card, pnt = 0, i; int royalFlush(const int [][13]); int straightFlush(const int [][13]); int poker(const int [][13]); int fullHouse(const int [][13]); int flush(const int [][13]); int straight(const int [][13]); int threeOfAKind(const int [][13]); int twoPair(const int [][13]); int pair(const int [][13]); int (*pokerArray[9])(const int) = {royalFlush, straightFlush, poker, fullHouse, flush, straight, threeOfAKind, twoPair, pair}; void point(int); for (card = 1; card < 6; card++){ for (row = 0; row < 4; row++){ for (column = 0; column < 13; column++){ if (d[row][column] == card){ deck2[row][column] = 1; } } } } for (i = 0; i < 9; i++){ pnt = (*pokerArray[i])(deck2); if (pnt != 0) break; } point(pnt); } int royalFlush(const int d2[][13]) { int i, j, k = 0, cont = 0, card[5], royal[5] = {0, 9, 10, 11, 12}; if (flush(d2) == 5) for (i = 0; i < 4; i++){ for (j = 0; j < 13; j++){ if (d2[i][j] == 1){ card[k] = j; k++; } } } bubble(card, 5); for (i = 0; i < 5; i++) if (card[i] == royal[i]) cont++; if (cont == 5) return 1; return 0; } int straightFlush(const int d2[][13]) { if (flush(d2) == 5) if (straight(d2) == 6) return 2; return 0; } int poker(const int d2[][13]) { int i, j, incr, cont; for (incr = 0; incr < 13; incr++){ cont = 0; for (i = 0; i < 4; i++){ for (j = incr; j <= incr; j++){ if (d2[i][j] == 1) cont++; } } if (cont == 4) return 3; } return 0; } int fullHouse(const int d2[][13]) { if (threeOfAKind(d2) == 7) if (pair(d2) == 9) return 4; return 0; } int flush(const int d2[][13]) { int i, j, cont; for (i = 0; i < 4; i++){ cont = 0; for (j = 0; j < 13; j++){ if (d2[i][j] == 1) cont++; } if (cont == 5) return 5; } return 0; } int straight(const int d2[][13]) { int i, j, k = 0, temp, num[5]; for (i = 0; i < 4; i++){ for (j = 0; j < 13; j++){ if (d2[i][j] == 1){ num[k] = j; k++; } } } bubble(num, 5); temp = num[0]; for (i = 1; i < 5; i++){ if (num[i] != temp + 1) return 0; temp = num[i]; } return 6; } int threeOfAKind(const int d2[][13]) { int i, j, incr, cont; for (incr = 0; incr < 13; incr++){ cont = 0; for (i = 0; i < 4; i++){ for (j = incr; j <= incr; j++){ if (d2[i][j] == 1) cont++; } } if (cont == 3) return 7; } return 0; } int twoPair(const int d2[][13]) { int i, j, incr, cont, pairCont = 0; for (incr = 0; incr < 13; incr++){ cont = 0; for (i = 0; i < 4; i++){ for (j = incr; j <= incr; j++){ if (d2[i][j] == 1) cont++; } } if (cont == 2) pairCont++; } if (pairCont == 2) return 8; return 0; } int pair(const int d2[][13]) { int i, j, incr, cont; for (incr = 0; incr < 13; incr++){ cont = 0; for (i = 0; i < 4; i++){ for (j = incr; j <= incr; j++){ if (d2[i][j] == 1) cont++; } } if (cont == 2) return 9; } return 0; } void point(int p) { switch (p){ case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break; case 7: break; case 8: break; case 9: break; default: } } void bubble(int n[], int size) { int i, j, temp; for (i = 0; i < size - 1; i++){ for (j = i + 1; j < size; j++){ if (n[i] > n[j]){ temp = n[i]; n[i] = n[j]; n[j] = temp; } } } }