pokerGame.java 4.59 KB
Newer Older
Emanuel Lugo committed
1

Emanuel Lugo committed
2 3
/** */

4 5
import java.util.ArrayList;
import java.util.*;
Emanuel Lugo committed
6 7 8

public class pokerGame {

Emanuel Lugo committed
9
    public String jugadas(ArrayList<Carta> mano) {
10
        String resultado;
Emanuel Lugo committed
11

12 13 14 15 16
        Collections.sort(mano, new SortbyValor());

        int contadorValor = 0;
        int contadorPalo = 0;
        int valorCarta, valorSgteCarta, aux;
Emanuel Lugo committed
17 18 19 20 21 22 23
        for (int i = 0; i < 4; i++) {
            // System.out.println(mano.get(i).getValorInt() + ": valor carta1");
            // System.out.println(mano.get(i+1).getValorInt() + ": valor carta2");
            valorCarta = mano.get(i).getValorInt(); // trae el valor entero contenido en la carta
            valorSgteCarta = mano.get(i + 1).getValorInt(); // trae el valor entero contenido en la carta siguiente
            if (mano.get(i).palo.equals(mano.get(i + 1).palo))
                contadorPalo++;
24
            aux = valorCarta + 1;
Emanuel Lugo committed
25 26
            if (aux == valorSgteCarta)
                contadorValor++;
27 28 29 30
            System.out.println("contador SECUENCIAL: " + contadorValor);
            System.out.println("contador PALOSIGUALES: " + contadorPalo);
        }

Emanuel Lugo committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
        /*
         * int contadorPalo = 0;
         * for (int i=0;i<4;i++) {
         * //System.out.println("PALO de la carta1: " +mano.get(i).getPalo());
         * //System.out.println("PALO de la carta2: " +mano.get(i+1).getPalo());
         * if (mano.get(i).palo.equals(mano.get(i+1).palo)) contadorPalo++ ; // CUENTA
         * CUANTAS CARTAS SON DEL MISMO PALO
         * System.out.println("contador PALOSIGUALES: " + contadorPalo);
         * }
         * 
         */

        if (contadorValor == 3 && mano.get(0).getValorInt() == 1 && mano.get(4).getValorInt() == 13) {
            return resultado = "ESCALERA COLOR";
        }
        if (contadorValor == 4 && contadorPalo == 4) {
47
            return resultado = "ESCALERA COLOR";
Emanuel Lugo committed
48 49 50 51 52 53 54
        } else if (contadorValor == 4) {
            return resultado = "ESCALERA";
        } else if (contadorPalo == 4) {
            return resultado = "COLOR";
        }

        // CASOS PARA POKER Y FULL
55 56
        int valoresIguales = 0;
        valoresIguales = 0;
Emanuel Lugo committed
57 58
        for (int i = 0; i < 4; i++) {
            if (mano.get(i).getValorInt() == mano.get(i + 1).getValorInt()) {
59 60
                valoresIguales++;
            }
Emanuel Lugo committed
61 62
        }

63
        if (valoresIguales == 3 && mano.get(3).getValorInt() != mano.get(4).getValorInt()) {
Emanuel Lugo committed
64 65 66 67 68 69 70 71 72 73 74 75
            return resultado = "POKER";
        } else if ((valoresIguales == 3 && mano.get(3).getValorInt() == mano.get(4).getValorInt())
                || (valoresIguales == 3 && mano.get(0).getValorInt() == mano.get(1).getValorInt())) {
            return resultado = "FULL";
        } else if ((valoresIguales == 2 && mano.get(3).getValorInt() != mano.get(4).getValorInt())
                || (valoresIguales == 2 && mano.get(0).getValorInt() != mano.get(1).getValorInt())) {
            return resultado = "TRIO";

        }

        if ((valoresIguales == 2 && mano.get(1).getValorInt() != mano.get(2).getValorInt())
                || (valoresIguales == 2 && mano.get(2).getValorInt() != mano.get(4).getValorInt())) {
Emanuel Lugo committed
76
            return resultado = "DOBLE DUO";
Emanuel Lugo committed
77 78 79
        } else if (valoresIguales == 1)
            return resultado = "DUO";

80
        return resultado = "CARTA ALTA";
Emanuel Lugo committed
81 82
    }

Emanuel Lugo committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    public static void main(String[] args) {
        pokerGame poker = new pokerGame();
        String resultado;
        int i;
        Carta carta1, carta2, carta3, carta4, carta5;
        ArrayList<Carta> mano = new ArrayList<Carta>();
        carta1 = new Carta("6S ");
        carta2 = new Carta("6C ");
        carta3 = new Carta("KD  ");
        carta4 = new Carta("AD ");
        carta5 = new Carta("AC");
        mano.add(carta1);
        mano.add(carta2);
        mano.add(carta3);
        mano.add(carta4);
        mano.add(carta5);

        /*
         * for (i = 0; i < 5; i++) {
         * System.out.println(mano.get(i).valorPalo());
         * }
         */

        for (i = 0; i < mano.size(); i++)
107
            System.out.println(mano.get(i).valorPalo());
Emanuel Lugo committed
108

Emanuel Lugo committed
109
        Collections.sort(mano, new SortbyPalo());
110

Emanuel Lugo committed
111
        System.out.println("");
112

Emanuel Lugo committed
113
        for (i = 0; i < mano.size(); i++)
114
            System.out.println(mano.get(i).valorPalo());
Emanuel Lugo committed
115

Emanuel Lugo committed
116
        Collections.sort(mano, new SortbyValor());
Emanuel Lugo committed
117

Emanuel Lugo committed
118
        System.out.println("");
Emanuel Lugo committed
119

Emanuel Lugo committed
120 121
        for (i = 0; i < mano.size(); i++)
            System.out.println(mano.get(i).valorPalo());
Emanuel Lugo committed
122

Emanuel Lugo committed
123
        Collections.sort(mano, new SortbyValor());
Emanuel Lugo committed
124

Emanuel Lugo committed
125
        System.out.println("");
Emanuel Lugo committed
126

Emanuel Lugo committed
127 128
        for (i = 0; i < mano.size(); i++)
            System.out.println(mano.get(i).valorPalo());
Emanuel Lugo committed
129

Emanuel Lugo committed
130 131
        resultado = poker.jugadas(mano);
        System.out.println(resultado);
Emanuel Lugo committed
132

Emanuel Lugo committed
133
    }
Emanuel Lugo committed
134 135

}