diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..6e3ba12 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/Carta.java b/Carta.java index 2852040..8237e25 100644 --- a/Carta.java +++ b/Carta.java @@ -1,3 +1,5 @@ +import java.util.Objects; + public class Carta { public String valor; public String palo; diff --git a/Juego.java b/Juego.java index 6153fd4..547c07b 100644 --- a/Juego.java +++ b/Juego.java @@ -1,15 +1,128 @@ +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; public class Juego { - static List escalera= Arrays.asList("2S", "3S", "4S", "5S", "6S"); + List valores = null; public Juego() { } + public void juegosPosibles(List cartas){ + boolean siguiente = true; + if(escaleraColor(cartas)){ + siguiente =false; + System.out.println("ESCALERA COLOR"); + } + if(siguiente && escalera(cartas)){ + System.out.println("ESCALERA"); + } + } + + public boolean escalera(List cartas) { + int contador = 0; + List valores = new ArrayList<>(); + + for (Carta c : cartas) { + valores.add(extraer(c.valor)); + } + Collections.sort(valores); + valores.forEach(System.out::println); + + int[] valoresArry = pasarAArray(valores); + for (int i = 0; i < valoresArry.length - 1; i++) { + + if (valoresArry[i] > 1) { + if (valoresArry[i + 1] - valoresArry[i] != 1) { + return false; + } else { + return true; + } + } + + contador += valoresArry[i]; + if (contador == 34 && valoresArry[0] == 1) { + return true; + } + } + return false; + } + + public boolean escaleraColor(List cartas) { + boolean valor1 = true; + String valuePalo = estraerPalo(cartas); + for (int i = 0; i < cartas.size(); i++) { + if (!valuePalo.equals(cartas.get(i).palo)) { + valor1 = false; + } + } + int contador = 0; + List valores = new ArrayList<>(); + if (valor1) { + for (Carta c : cartas) { + valores.add(extraer(c.valor)); + } + Collections.sort(valores); + valores.forEach(System.out::println); + + int[] valoresArry = pasarAArray(valores); + for (int i = 0; i < valoresArry.length - 1; i++) { - public void escalera(){ + if (valoresArry[i] > 1) { + if (valoresArry[i + 1] - valoresArry[i] != 1) { + return false; + } else { + return true; + } + } + + contador += valoresArry[i]; + if (contador == 34 && valoresArry[0] == 1) { + return true; + } + } + } + + return false; + + } + + private int[] pasarAArray(List valores) { + int[] value = new int[5]; + for (int i = 0; i < valores.size(); i++) { + value[i] = valores.get(i); + } + return value; + } + + public Integer extraer(String carta) { + int valor = 0; + if (carta.equals("A")) { + return valor = 1; + } + if (carta.equals("T")) { + return valor = 10; + } + if (carta.equals("J")) { + return valor = 11; + } + if (carta.equals("Q")) { + return valor = 12; + } + if (carta.equals("K")) { + return valor = 13; + } + return Integer.valueOf(carta); + } + public String estraerPalo(List cartas) { + String value = ""; + for (Carta c : cartas) { + value = c.palo; + break; + } + return value; } } diff --git a/Main.java b/Main.java index b4b91b5..f39b1f9 100644 --- a/Main.java +++ b/Main.java @@ -1,42 +1,31 @@ +import com.sun.jdi.Value; + import java.util.*; import java.util.stream.Collectors; public class Main { public static void main(String[] args) { - Juego g = new Juego(); + Juego j = new Juego(); - boolean valor1 = true; List cartas = new ArrayList<>(); cartas = Arrays.asList( - new Carta("AS"), - new Carta("2S"), - new Carta("3S"), - new Carta("4S"), - new Carta("5S") + new Carta("7H"), + new Carta("8H"), + new Carta("9H"), + new Carta("JH"), + new Carta("TH") ); - cartas.stream().collect(Collectors.toList()); + + cartas.forEach(System.out::print); + cartas.sort(Comparator.comparing(carta -> carta.valor)); + System.out.println(); cartas.forEach(System.out::print); System.out.println(); - List carta= Arrays.asList("2S", "3S", "4S", "5S", "6S"); - for (Carta c: cartas){ - if(!c.palo.equals("S")){ - valor1=false; - } - } - for (int i = 0; i + + + \ No newline at end of file diff --git a/out/production/poker/Carta.class b/out/production/poker/Carta.class index 6098b16..22b01db 100644 Binary files a/out/production/poker/Carta.class and b/out/production/poker/Carta.class differ diff --git a/out/production/poker/Juego.class b/out/production/poker/Juego.class index 2768e94..113997e 100644 Binary files a/out/production/poker/Juego.class and b/out/production/poker/Juego.class differ diff --git a/out/production/poker/Main.class b/out/production/poker/Main.class index 99b5424..65542ef 100644 Binary files a/out/production/poker/Main.class and b/out/production/poker/Main.class differ