diff --git a/Generala.java b/Generala.java index 23409f6..acec282 100644 --- a/Generala.java +++ b/Generala.java @@ -20,12 +20,7 @@ public class Generala //comprobar que sean 5 valores if(dados.length() != 5){ return "INVALIDO"; - } - - //Para comprobar los tres casos posibles de escalera - if(dados.equals("12345") || dados.equals("23456") || dados.equals("34561")){ - return "ESCALERA"; - } + } //array para tener la cantidad de apariciones de un número int[] cantidad = {0, 0, 0, 0, 0, 0}; @@ -40,6 +35,48 @@ public class Generala cantidad[index-1]++; } + boolean bandera=true; + System.out.print(cantidad[0]+"|"+cantidad[1]+"|"+cantidad[2]+"|"+cantidad[3]+"|"+cantidad[4]+"|"+cantidad[5]); + System.out.println(); + + //Comprueba la escalera 12345 + for (int i = 0; i < 5; i++) { + if(cantidad[i]!=1){ + bandera=false; + break; + } + } + if(bandera){ + return "ESCALERA"; + } + + bandera=true; + //Comprueba la escalera 23456 + for (int i = 1; i < 6; i++) { + if(cantidad[i]!=1){ + bandera=false; + break; + } + } + if(bandera){ + return "ESCALERA"; + } + + bandera=true; + //Comprueba la escalera 34561 + for (int i = 2; i < 6; i++) { + if(cantidad[i]!=1){ + bandera=false; + break; + } + } + if(cantidad[0]!=1){ + bandera=false; + } + if(bandera){ + return "ESCALERA"; + } + //calcula el máximo del vector cantidad int max = maximo(cantidad); //System.out.println(max); @@ -139,7 +176,8 @@ public class Generala System.out.println(g.jugada("23A23")); //INVALIDO System.out.println(g.jugada("55155")); //POKER */ + } -} \ No newline at end of file +}