From cd75c32277ff7938e9cf4a78a9f566435945abeb Mon Sep 17 00:00:00 2001 From: Emanuel Lugo Date: Tue, 26 Apr 2022 23:42:03 -0400 Subject: [PATCH] errores resueltos en jugada --- Carta.java | 72 +++++++++++++++++++++++++++++++++++++----------------------------------- pokerGame.java | 101 +++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------- 2 files changed, 86 insertions(+), 87 deletions(-) diff --git a/Carta.java b/Carta.java index 7a1d774..ea38ab8 100644 --- a/Carta.java +++ b/Carta.java @@ -1,41 +1,46 @@ public class Carta { + public String valor; + public String palo; - public String valor; - public String palo; - - - public Carta(){ - - } - - public Carta (String completo) - { - if (completo.charAt(0) == 'A') this.valor = "1" ; - else if (completo.charAt(0) == 'T') this.valor = "10" ; - else if (completo.charAt(0) == 'J') this.valor = "11" ; - else if (completo.charAt(0) == 'Q') this.valor = "12" ; - else if (completo.charAt(0) == 'K') this.valor = "13" ; - else this.valor = String.valueOf(completo.charAt(0)); - - - - this.palo = String.valueOf(completo.charAt(1)); - } - - String valorPalo() - { - if (this.valor.equals("1")) {return "A" + " " +this.palo; - }else if (this.valor.equals("10")) {return "T" + " " +this.palo; - } else if (this.valor.equals("11")) {return "J"+ " " +this.palo; - }else if (this.valor.equals("12")) {return "Q"+ " " +this.palo; - } else if (this.valor.equals("13")) {return "K" + " " +this.palo; - }else return this.valor + " " +this.palo; - + public Carta() { + + } + + public Carta(String completo) { + if (completo.charAt(0) == 'A') + this.valor = "1"; + else if (completo.charAt(0) == 'T') + this.valor = "10"; + else if (completo.charAt(0) == 'J') + this.valor = "11"; + else if (completo.charAt(0) == 'Q') + this.valor = "12"; + else if (completo.charAt(0) == 'K') + this.valor = "13"; + else + this.valor = String.valueOf(completo.charAt(0)); + + this.palo = String.valueOf(completo.charAt(1)); } + String valorPalo() { + if (this.valor.equals("1")) { + return "A" + this.palo; + } else if (this.valor.equals("10")) { + return "T" + this.palo; + } else if (this.valor.equals("11")) { + return "J" + this.palo; + } else if (this.valor.equals("12")) { + return "Q" + this.palo; + } else if (this.valor.equals("13")) { + return "K" + this.palo; + } else + return this.valor + this.palo; - public int getValorInt () { + } + + public int getValorInt() { int aux = Integer.parseInt(this.valor); return aux; @@ -46,7 +51,4 @@ public class Carta { } - - } - diff --git a/pokerGame.java b/pokerGame.java index fe25fa4..d608d4a 100644 --- a/pokerGame.java +++ b/pokerGame.java @@ -14,6 +14,10 @@ public class pokerGame { int contadorValor = 0; int contadorPalo = 0; int valorCarta, valorSgteCarta, aux; + + // COMPROBACIÓN DE CASOS DE CARTAS EN SECUENCIA - ESCALERA COLOR - ESCALERA - + // COLOR + 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"); @@ -24,21 +28,11 @@ public class pokerGame { aux = valorCarta + 1; if (aux == valorSgteCarta) contadorValor++; - System.out.println("contador SECUENCIAL: " + contadorValor); - System.out.println("contador PALOSIGUALES: " + contadorPalo); - } - /* - * 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); - * } - * - */ + // corroborar contadores + // System.out.println("contador SECUENCIAL: " + contadorValor); + // System.out.println("contador PALOSIGUALES: " + contadorPalo); + } if (contadorValor == 3 && mano.get(0).getValorInt() == 1 && mano.get(4).getValorInt() == 13) { return resultado = "ESCALERA COLOR"; @@ -51,7 +45,7 @@ public class pokerGame { return resultado = "COLOR"; } - // CASOS PARA POKER Y FULL + // CASOS PARA POKER Y FULL - CARTAS DOBLES Y TRIOS int valoresIguales = 0; valoresIguales = 0; for (int i = 0; i < 4; i++) { @@ -60,13 +54,16 @@ public class pokerGame { } } - if (valoresIguales == 3 && mano.get(3).getValorInt() != mano.get(4).getValorInt()) { + if ((valoresIguales == 3 && mano.get(3).getValorInt() != mano.get(4).getValorInt()) + || valoresIguales == 3 && mano.get(0).getValorInt() != mano.get(1).getValorInt()) { 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())) { + } else if ((valoresIguales == 2 && mano.get(3).getValorInt() != mano.get(4).getValorInt() + && mano.get(1).getValorInt() == mano.get(3).getValorInt()) + || (valoresIguales == 2 && mano.get(0).getValorInt() != mano.get(1).getValorInt()) + && mano.get(2).getValorInt() == mano.get(4).getValorInt()) { return resultado = "TRIO"; } @@ -81,55 +78,55 @@ public class pokerGame { } public static void main(String[] args) { + Carta carta1, carta2, carta3, carta4, carta5; + ArrayList mano = new ArrayList(); pokerGame poker = new pokerGame(); String resultado; int i; - Carta carta1, carta2, carta3, carta4, carta5; - ArrayList mano = new ArrayList(); - carta1 = new Carta("6S "); - carta2 = new Carta("6C "); - carta3 = new Carta("KD "); - carta4 = new Carta("AD "); - carta5 = new Carta("AC"); + carta1 = new Carta("KS "); + carta2 = new Carta("6C "); + carta3 = new Carta("6H "); + carta4 = new Carta("6D "); + carta5 = new Carta("KC "); 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++) - System.out.println(mano.get(i).valorPalo()); - - Collections.sort(mano, new SortbyPalo()); - - System.out.println(""); - - for (i = 0; i < mano.size(); i++) - System.out.println(mano.get(i).valorPalo()); - Collections.sort(mano, new SortbyValor()); - - System.out.println(""); - + System.out.print("MANO: "); for (i = 0; i < mano.size(); i++) - System.out.println(mano.get(i).valorPalo()); - - Collections.sort(mano, new SortbyValor()); - - System.out.println(""); - - for (i = 0; i < mano.size(); i++) - System.out.println(mano.get(i).valorPalo()); + System.out.print(mano.get(i).valorPalo() + " "); + System.out.println(" "); resultado = poker.jugadas(mano); System.out.println(resultado); } } + +/* + * PARA TESTEAR + * Collections.sort(mano, new SortbyPalo()); + * + * System.out.println(""); + * + * for (i = 0; i < mano.size(); i++) + * System.out.println(mano.get(i).valorPalo()); + * + * Collections.sort(mano, new SortbyValor()); + * + * System.out.println(""); + * + * for (i = 0; i < mano.size(); i++) + * System.out.println(mano.get(i).valorPalo()); + * + * Collections.sort(mano, new SortbyValor()); + * + * System.out.println(""); + * + * for (i = 0; i < mano.size(); i++) + * System.out.println(mano.get(i).valorPalo()); + */ \ No newline at end of file -- libgit2 0.26.0