Commit 38d011f7 by roshka

Mejor Jugada 1.0

parents
## Indicaciones
La carpeta 'java-e005' contiene el programa.
Para abrirlo, es necesario utilizar la aplicacion Eclipse, y abrir la carpeta desde ahi.
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-10">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>java-e005</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=10
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=10
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=10
public class Carta {
String valor;
String palo;
Carta(String completo){
this.valor = String.valueOf(completo.charAt(0));
this.palo = String.valueOf(completo.charAt(1));
}
String valorPalo(){
return this.valor + this.palo;
}
}
public class Clasificador {
final String[] jugadas = {
"Escalera Color",
"Poker",
"Full",
"Color",
"Escalera",
"Trio",
"Par doble",
"Par",
"Carta alta"
};
private Carta[] ordenarCartasValor(Carta[] mano) {
ClsOrdena compara = new ClsOrdena();
for(int i=0;i<mano.length-1;i++) {
char menor = mano[i].valorPalo().charAt(0);
int pos_menor = i;
for(int j=i+1;j<mano.length;j++) {
char actual = mano[j].valorPalo().charAt(0);
if(compara.compararValor(actual,menor) == -1) {
menor = actual;
pos_menor = j;
}
}
//Realizamos el intercambio
if(pos_menor !=i) {
Carta aux = mano[i];
mano[i] = mano[pos_menor];
mano[pos_menor] = aux;
}
}
return mano;
}
private boolean esEscaleraColor(Carta[] mano) {
//Primero comprobamos que tengan todas las cartas el mismo palo
if(esColor(mano)) {
if(this.esEscalera(mano)) {
return true;
}
}
return false;
}
private boolean esPoker(Carta[] mano) {
char[] valores = new char[5];
//Ordenamos las cartas por valor
mano = this.ordenarCartasValor(mano);
//Cargamos los valores de la mano
for(int i = 0;i<mano.length;i++) {
valores[i] = mano[i].valorPalo().charAt(0);
}
//Primer caso
if(valores[0] == valores[1]) {
if(valores[1]==valores[2]) {
if(valores[2] == valores[3]) {
return true;
}
}
}
//Segundo caso
if(valores[1] == valores[2]) {
if(valores[2]==valores[3]) {
if(valores[3] == valores[4]) {
return true;
}
}
}
return false;
}
private boolean esFull(Carta[] mano) {
char[] valores = new char[5];
//Ordenamos las cartas por valor
mano = this.ordenarCartasValor(mano);
//Cargamos los valores de la mano
for(int i = 0;i<mano.length;i++) {
valores[i] = mano[i].valorPalo().charAt(0);
}
//Existen 2 casos
//Caso 1
if(valores[0] == valores[1]) {
if(valores[1]==valores[2]) {
if(valores[3]==valores[4]) {
return true;
}
}
}
//Caso 2
if(valores[2] == valores[3]) {
if(valores[3]==valores[4]) {
if(valores[0]==valores[1]) {
return true;
}
}
}
return false;
}
private boolean esColor(Carta[] mano){
//Primero comprobamos que tengan todas las cartas el mismo palo
char palo = mano[0].valorPalo().charAt(1);
for(int i=1;i<5;i++) {
if(mano[i].valorPalo().charAt(1) != palo) {
return false;
}
}
return true;
}
private boolean esEscalera(Carta[] mano) {
ClsOrdena compara = new ClsOrdena();
boolean resultado = true;
char esR1 = 'p';
char esR2 = 'p';
//Ordenamos las cartas por valor
mano = this.ordenarCartasValor(mano);
//Obtenemos el valor de la primera carta y segunda carta
//para saber si se obtiene escalera real
esR1 = mano[0].valorPalo().charAt(0);
esR2 = mano[1].valorPalo().charAt(0);
//Existen dos casos, escalera real o no escalera real
//Caso 1: Escalera real
if(esR1 =='A' && esR2 == 'T') {
for(int i = 1;i<mano.length-1 && resultado;i++) {
if(!compara.esAnterior(mano[i+1],mano[i])) {
resultado = false;
}
}
//Caso 2: No escalera real
}else{
for(int i = 0;i<mano.length-1 && resultado;i++) {
if(!compara.esAnterior(mano[i+1],mano[i])) {
resultado = false;
}
}
}
return resultado;
}
private boolean esTrio(Carta[] mano) {
char[] valores = new char[5];
//Ordenamos las cartas por valor
mano = this.ordenarCartasValor(mano);
//Cargamos los valores de la mano
for(int i = 0;i<mano.length;i++) {
valores[i] = mano[i].valorPalo().charAt(0);
}
//Existen 3 casos
//Caso 1
if(valores[0] == valores[1]) {
if(valores[1]==valores[2]) {
return true;
}
}
//Caso 2
if(valores[1] == valores[2]) {
if(valores[2]==valores[3]) {
return true;
}
}
//Caso 3
if(valores[2] == valores[3]) {
if(valores[3]==valores[4]) {
return true;
}
}
return false;
}
private boolean esParDoble(Carta[] mano) {
char[] valores = new char[5];
//Ordenamos las cartas por valor
mano = this.ordenarCartasValor(mano);
//System.out.println("Prueba");
//for(Carta imprimir:mano) {
// System.out.print(imprimir.valorPalo()+" ");
//}
//System.out.print("\n");
//Cargamos los valores de la mano
for(int i = 0;i<mano.length;i++) {
valores[i] = mano[i].valorPalo().charAt(0);
}
//Existen 2 casos
//Caso 1
if(valores[0] == valores[1]) {
if(valores[2]==valores[3]) {
return true;
}else if(valores[3]==valores[4]) {
return true;
}
}
//Caso 2
if(valores[1] == valores[2]) {
if(valores[3]==valores[4]) {
return true;
}
}
return false;
}
private boolean esPar(Carta[] mano) {
char[] valores = new char[5];
//Ordenamos las cartas por valor
mano = this.ordenarCartasValor(mano);
//Cargamos los valores de la mano
for(int i = 0;i<mano.length;i++) {
valores[i] = mano[i].valorPalo().charAt(0);
}
//Realizamos las comprobaciones
for(int i = 0;i<mano.length-1;i++) {
if(valores[i]==valores[i+1]) {
return true;
}
}
return false;
}
/**
* Entrega el tipo de mano que tiene el jugador
* @param mano El conjunto de objeto de tipo 'Carta'
* @return El tipo de mano
*/
public int jugada(Carta[] mano)
{
//Ponemos como predeterminado que la mano es Carta Alta
int resultado = 8;
//Realizamos la comprobaciones
if(this.esEscaleraColor(mano)) {
resultado = 0;
}else if(this.esPoker(mano)) {
resultado = 1;
}else if(this.esFull(mano)) {
resultado = 2;
}else if(this.esColor(mano)) {
resultado = 3;
}else if(this.esEscalera(mano)) {
resultado = 4;
}else if(this.esTrio(mano)) {
resultado = 5;
}else if(this.esParDoble(mano)) {
resultado = 6;
}else if(this.esPar(mano)){
resultado = 7;
}
return resultado;
}
}
public class ClsOrdena {
final char valores[] = {'A','2','3','4','5','6','7','8','9','T','J','Q','K'};
final char palos[] = {'S','C','H','D'};
/**
* Comprueba si el valor de la otra carta es superior, igual o inferior al valor de
* la carta actual
* @param valorE El valor de la otra carta en formato 'char'.
* @return 0: son iguales, 1: la carta es superior a la otra carta, -1: lo contrario al valor 1
*/
//Funcion que nos permite comparar con otra carta
public int compararValor(char valor1,char valor2) {
int numValor1 = 0;
int numValor2 = 0;
//Buscamos en que posición está cada valor
//Valor1
for(int i=0;i<valores.length;i++) {
if(valor1 == valores[i]) {
numValor1 = i;
break;
}
}
//Valor2
for(int i=0;i<valores.length;i++) {
if(valor2 == valores[i]) {
numValor2 = i;
break;
}
}
//Realizamos la comparación
if(numValor1 == numValor2) {
return 0;
}else if(numValor1 > numValor2) {
return 1;
}else {
return -1;
}
}
/**
* Retorna un boolean si la otra carta es un paso superior a la carta actual
* @param otraCarta La otra carta
* @return Si es o no es cierto
*/
public boolean esAnterior(Carta carta1,Carta carta2) {
int valor1 = 0;
int valor2 = 0;
//Buscamos la posicion del valor de la otra carta
for(int i=0;i<valores.length;i++) {
if(carta1.valorPalo().charAt(0) == valores[i]) {
valor1 = i;
break;
}
}
//Buscamos la posicion del valor de esta carta
for(int i=0;i<valores.length;i++) {
if(carta2.valorPalo().charAt(0) == valores[i]) {
valor2 = i;
break;
}
}
//averiguamos si es el siguiente
if(valor1 != (valor2+1)) {
return false;
}
return true;
}
}
import java.util.*;
public class MyClass {
// este es el único método que tienen que desarrollar
// para hacerlo, pueden hacer uso de otras clases (si es necesario),
// pero la corrección del ejercicio será automática en base a este
// método que está acá
public String ganadores(List<Carta[]> jugadas){
//Imprime la cantidad de jugadas
System.out.println("Cantidad de jugadas: " + jugadas.size());
//Imprime las jugadas
int i = 1;
for (Carta[] mano : jugadas) {
System.out.println("JUGADA "+ i+ " ======================");
for (Carta c : mano) {
System.out.println(c.valorPalo());
}
i= i+1;
}
//Vamos a establecer el tipo de mano que tiene cada mano
//Cada tipo de mano le corresponde un número
int[] manos = new int[jugadas.size()];
int indice = 0;
Clasificador clasifica = new Clasificador();
for (Carta[] mano : jugadas) {
manos[indice] = clasifica.jugada(mano);
indice = indice +1;
}
//De estas manos, tengo que saber cual es el ganador
//Vamos a hallar la mayor tipo de jugada
int mejor = 8;
for(int indice1 = 0;indice1<manos.length;indice1++) {
if(manos[indice1]<mejor) {
mejor=manos[indice1];
}
}
//Ahora averiguamos cuales manos quitaron la mejor tipo de mano
ArrayList<Integer> mejoresManos= new ArrayList<>();
for(int indice1=0;indice1<manos.length;indice1++) {
if(mejor==manos[indice1]) {
mejoresManos.add(indice1);
}
}
//Ahora vamos a imprimir el ganador
if(mejoresManos.size()==1) {
return "Jugada "+(mejoresManos.get(0)+1);
//Esto es en caso que haya varias manos
}else {
//Vamos crear una lista de manos
ArrayList<Carta[]> variasManos = new ArrayList<>();
//Cargamos en la lista las mejores manos
for(int indice1=0;indice1<mejoresManos.size();indice1++) {
variasManos.add(jugadas.get(mejoresManos.get(indice1)));
}
//Utilizaremos el objeto SelectorGanador para obtener la mano ganadora
SelectorGanador manoGanador = new SelectorGanador(variasManos,mejor);
//Obtenemos la mano ganadora
Carta[] ganador = manoGanador.procesar();
//Buscamos en que jugada se uso
for(int indice1 = 0;indice1<jugadas.size();indice1++) {
if(ganador == jugadas.get(indice1)) {
return "Jugada "+(indice1 + 1);
}
}
}
return "Error";
}
public static void main(String args[]) {
int x=10;
int y=25;
int z=x+y;
MyClass mc = new MyClass();
List<Carta[]> jugadas = new ArrayList<Carta[]>();
Carta[] m1 = new Carta[5];
m1[0] = new Carta("AH");
m1[1] = new Carta("2H");
m1[2] = new Carta("4H");
m1[3] = new Carta("6H");
m1[4] = new Carta("5H");
Carta[] m2 = new Carta[5];
m2[0] = new Carta("AH");
m2[1] = new Carta("TH");
m2[2] = new Carta("KH");
m2[3] = new Carta("QH");
m2[4] = new Carta("JH");
Carta[] m3 = new Carta[5];
m3[0] = new Carta("3D");
m3[1] = new Carta("4D");
m3[2] = new Carta("5D");
m3[3] = new Carta("8D");
m3[4] = new Carta("9D");
jugadas.add(m1);
jugadas.add(m2);
jugadas.add(m3);
String ganadores = mc.ganadores(jugadas);
System.out.println("Sum of x+y = " + z);
System.out.println("Ganadores = " + ganadores);
}
}
import java.util.ArrayList;
public class SelectorGanador {
ArrayList<Carta[]> lista_p_ganadores;
int mejor;
public SelectorGanador(ArrayList<Carta[]> entrada,int mejorTipo){
this.lista_p_ganadores = entrada;
this.mejor = mejorTipo;
}
public Carta[] procesar() {
ArrayList<Carta[]> respuesta = null;
//Cada jugada tiene un proceso diferente
if(this.mejor==1) {
respuesta = this.casoPoker();
}else if(this.mejor==2) {
respuesta = this.casoFull();
}else if(this.mejor == 3) {
respuesta = this.casoColorYCartaAlta();
}else if(this.mejor == 4) {
respuesta = this.casoEscalera();
}else if(this.mejor == 5) {
respuesta = this.casoTrio();
}else if(this.mejor == 6) {
respuesta = this.casoParDoble();
}else if(this.mejor == 7) {
respuesta = this.casoPar();
}else if(this.mejor == 8){
respuesta = this.casoColorYCartaAlta();
}
//Retorna el mazo ganador
return respuesta.get(0);
}
private ArrayList<Carta[]> casoPar() {
ArrayList<Carta[]> temporal = this.lista_p_ganadores;
int pos_mejor;
ClsOrdena compara = new ClsOrdena();
for(int i = 0;i<temporal.size()-1;i++) {
Carta[] mejorTemp = temporal.get(i);
pos_mejor = i;
for(int j = i+1;j<temporal.size();j++) {
/*
* Existen tres casos
* 1- Cuando hay doble A
* 2- Cuando hay una A
* 3- Cuando no hay A
*/
//Caso uno
if(mejorTemp[0].valorPalo().charAt(0) == 'A' &&
mejorTemp[1].valorPalo().charAt(0) == 'A') {
if(temporal.get(j)[0].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[1].valorPalo().charAt(0) == 'A') {
for(int k = 2;k<mejorTemp.length;k++) {
if(compara.compararValor(mejorTemp[k].valorPalo().charAt(0),
temporal.get(j)[k].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
}else {
break;
}
}else if(temporal.get(j)[0].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[1].valorPalo().charAt(0) == 'A') {
mejorTemp = temporal.get(j);
pos_mejor = j;
//Caso dos
}else if(mejorTemp[0].valorPalo().charAt(0) == 'A') {
//Aqui puede ocurrir que la otra mano tenga tambien una A
if(temporal.get(j)[0].valorPalo().charAt(0) == 'A') {
for(int k = 1;k<mejorTemp.length;k++) {
if(compara.compararValor(mejorTemp[k].valorPalo().charAt(0),
temporal.get(j)[k].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
}else {
for(int k = 1;k<mejorTemp.length-1;k++) {
if(compara.compararValor(mejorTemp[k].valorPalo().charAt(0),
temporal.get(j)[k-1].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
}
}else if(temporal.get(j)[0].valorPalo().charAt(0) == 'A') {
for(int k = 1;k<mejorTemp.length-1;k++) {
if(compara.compararValor(mejorTemp[k-1].valorPalo().charAt(0),
temporal.get(j)[k].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
//Tercer caso
}else {
for(int k = 0;k<mejorTemp.length-1;k++) {
if(compara.compararValor(mejorTemp[k].valorPalo().charAt(0),
temporal.get(j)[k].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
}
}
//Realizamos el intercambio
if(pos_mejor != i) {
Carta[] aux = temporal.get(pos_mejor);
temporal.set(pos_mejor, temporal.get(i));
temporal.set(i, aux);
}
}
return temporal;
}
private ArrayList<Carta[]> casoParDoble() {
ArrayList<Carta[]> temporal = this.lista_p_ganadores;
int pos_mejor;
ClsOrdena compara = new ClsOrdena();
for(int i = 0;i<temporal.size()-1;i++) {
Carta[] mejorTemp = temporal.get(i);
pos_mejor = i;
for(int j = i+1;j<temporal.size();j++) {
/*Existen tres casos
1-Cuando hay un par de ases
2-Cuando hay un A
3-Cuando no hay A*/
//Primer caso
if(mejorTemp[0].valorPalo().charAt(0) == 'A' &&
mejorTemp[1].valorPalo().charAt(0) == 'A') {
//Aqui puede ocurrir que tambien la otra mano tenga un doble A
if(temporal.get(j)[0].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[1].valorPalo().charAt(0) == 'A') {
//Realizamos la comparacion carta por carta
for(int k = 2;k<mejorTemp.length;k++) {
if(compara.compararValor(mejorTemp[k].valorPalo().charAt(0),
temporal.get(j)[k].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
}else {
break;
}
}else if(temporal.get(j)[0].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[1].valorPalo().charAt(0) == 'A') {
mejorTemp = temporal.get(j);
pos_mejor = j;
//Caso dos
}else if(mejorTemp[0].valorPalo().charAt(0) == 'A') {
//Aqui puede ocurrir que la otra mano tenga tambien una A
if(temporal.get(j)[0].valorPalo().charAt(0) == 'A') {
for(int k = 1;k<mejorTemp.length;k++) {
if(compara.compararValor(mejorTemp[k].valorPalo().charAt(0),
temporal.get(j)[k].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
}else {
for(int k = 1;k<mejorTemp.length-1;k++) {
if(compara.compararValor(mejorTemp[k].valorPalo().charAt(0),
temporal.get(j)[k-1].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
}
}else if(temporal.get(j)[0].valorPalo().charAt(0) == 'A') {
//Aqui estoy ahora
for(int k = 1;k<mejorTemp.length-1;k++) {
if(compara.compararValor(mejorTemp[k-1].valorPalo().charAt(0),
temporal.get(j)[k].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
//Tercer caso
}else {
for(int k = 0;k<mejorTemp.length-1;k++) {
if(compara.compararValor(mejorTemp[k].valorPalo().charAt(0),
temporal.get(j)[k].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
}
}
//Realizamos el intercambio
if(pos_mejor != i) {
Carta[] aux = temporal.get(pos_mejor);
temporal.set(pos_mejor, temporal.get(i));
temporal.set(i, aux);
}
}
return temporal;
}
//Esto se analiza mas tarde
private ArrayList<Carta[]> casoEscalera() {
ArrayList<Carta[]> temporal = this.lista_p_ganadores;
int pos_mejor;
ClsOrdena compara = new ClsOrdena();
/* Existen
* 1- Cuando es una escalera real (esta es la mejor mano)
* 2- Cuando tienes una escalera A 2 3 4 5 (es la peor escalera)
* 3- Cualquier otra escalera
* */
for(int i = 0;i<temporal.size()-1;i++) {
Carta[] mejorTemp = temporal.get(i);
pos_mejor = i;
for(int j = i+1;j<temporal.size();j++) {
//Caso 1 (esta es la mejor mano)
if(mejorTemp[0].valorPalo().charAt(0) == 'A' && mejorTemp[1].valorPalo().charAt(0)=='T'){
break;
}else if(temporal.get(j)[0].valorPalo().charAt(0) == 'A' && mejorTemp[1].valorPalo().charAt(0)=='T'){
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
//Caso 2 (esta es la peor escalera)
if(mejorTemp[0].valorPalo().charAt(0) == 'A') {
mejorTemp = temporal.get(j);
pos_mejor = j;
}else if(temporal.get(j)[0].valorPalo().charAt(0) == 'A'){
continue;
//Caso 3: Cualquier otra escalera
}else {
for(int k = 0;k<mejorTemp.length;k++) {
if(compara.compararValor(mejorTemp[k].valorPalo().charAt(0),
temporal.get(j)[k].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
}
}
//Realizamos el intercambio
if(pos_mejor != i) {
Carta[] aux = temporal.get(pos_mejor);
temporal.set(pos_mejor, temporal.get(i));
temporal.set(i, aux);
}
}
return temporal;
}
private ArrayList<Carta[]> casoTrio() {
ArrayList<Carta[]> temporal = this.lista_p_ganadores;
//Va a ver tres casos
//1-Cuando tiene un trio con A
//2-Cuando tiene una A
//3-Cuando no tiene A
int pos_mejor;
ClsOrdena compara = new ClsOrdena();
//Ahora vamos a ordenar la lista de la mejor a la peor jugada
for(int i = 0; i<temporal.size()-1;i++) {
//Tomamos una mano
Carta[] mejorTemp = temporal.get(i);
pos_mejor = i;
//Y aqui tomamos la otra mano para comparar
for(int j = i+1;j<temporal.size();j++) {
//1-Cuando tiene un trio de A (no existe una mejor baraja de trio que esta)
if(mejorTemp[0].valorPalo().charAt(0) == 'A' &&
mejorTemp[1].valorPalo().charAt(0) == 'A' &&
mejorTemp[2].valorPalo().charAt(0) == 'A') {
if(temporal.get(j)[0].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[1].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[2].valorPalo().charAt(0) == 'A') {
for(int k = 3;k<mejorTemp.length;k++) {
if(compara.compararValor(mejorTemp[k].valorPalo().charAt(0),
temporal.get(j)[k].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
}else {
break;
}
}else if(temporal.get(j)[0].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[1].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[2].valorPalo().charAt(0) == 'A') {
mejorTemp = temporal.get(j);
pos_mejor = j;
//2-Cuando se tiene una A
}else if(mejorTemp[0].valorPalo().charAt(0) == 'A') {
//Si los dos tienen al comienzo el A
if(temporal.get(j)[0].valorPalo().charAt(0) == 'A') {
Carta mano1 = mejorTemp[1];
Carta mano2 = temporal.get(j)[1];
if(compara.compararValor(mano1.valorPalo().charAt(0),mano2.valorPalo().charAt(0))==-1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
}
}else {
Carta mano11 = mejorTemp[1];
Carta mano21 = temporal.get(j)[1];
if(compara.compararValor(mano11.valorPalo().charAt(0),mano21.valorPalo().charAt(0))==0) {
break;
}else if(compara.compararValor(mano11.valorPalo().charAt(0),mano21.valorPalo().charAt(0))==-1){
mejorTemp = temporal.get(j);
pos_mejor = j;
}
}
}else if(temporal.get(j)[0].valorPalo().charAt(0) == 'A') {
Carta mano12 = mejorTemp[1];
Carta mano22 = temporal.get(j)[1];
if(compara.compararValor(mano12.valorPalo().charAt(0),mano22.valorPalo().charAt(0))==0) {
mejorTemp = temporal.get(j);
pos_mejor = j;
}else if(compara.compararValor(mano12.valorPalo().charAt(0),mano22.valorPalo().charAt(0))==-1){
mejorTemp = temporal.get(j);
pos_mejor = j;
}
//3- Cuando no tiene A
}else {
for(int k = 0;k<mejorTemp.length;k++) {
if(compara.compararValor(mejorTemp[k].valorPalo().charAt(0),
temporal.get(j)[k].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
}
}
//Realizamos el intercambio
if(pos_mejor != i) {
Carta[] aux = temporal.get(pos_mejor);
temporal.set(pos_mejor, temporal.get(i));
temporal.set(i, aux);
}
}
//Retornamos la lista ordenada
return temporal;
}
private ArrayList<Carta[]> casoColorYCartaAlta() {
ArrayList<Carta[]> temporal = this.lista_p_ganadores;
int pos_mejor;
ClsOrdena compara = new ClsOrdena();
for(int i = 0;i<temporal.size()-1;i++) {
Carta[] mejorTemp = temporal.get(i);
pos_mejor = i;
for(int j = i+1;j<temporal.size();j++) {
//Que pasa si la primera mano contiene una A
if(mejorTemp[0].valorPalo().charAt(0) == 'A') {
//Que pasa si la otra mano tambien tiene una A
if(temporal.get(j)[0].valorPalo().charAt(0) == 'A') {
//Se realiza la comparacion con las siguientes cartas
for(int k = 1;k<mejorTemp.length;k++) {
if(compara.compararValor(mejorTemp[k].valorPalo().charAt(0),
temporal.get(j)[k].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
}else {
break;
}
}else if(temporal.get(j)[0].valorPalo().charAt(0) == 'A') {
mejorTemp = temporal.get(j);
pos_mejor = j;
}else {
for(int k = 0;k<mejorTemp.length;k++) {
if(compara.compararValor(mejorTemp[k].valorPalo().charAt(0),
temporal.get(j)[k].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
}
}
//Realizamos el intercambio
if(pos_mejor != i) {
Carta[] aux = temporal.get(pos_mejor);
temporal.set(pos_mejor, temporal.get(i));
temporal.set(i, aux);
}
}
return temporal;
}
private ArrayList<Carta[]> casoFull() {
ArrayList<Carta[]> temporal = this.lista_p_ganadores;
//Va a ver tres casos
//1-Cuando tiene un trio con A
//2-Cuando tiene un par de A
//3-Cuando no tiene A
int pos_mejor;
ClsOrdena compara = new ClsOrdena();
//Ahora vamos a ordenar la lista de la mejor a la peor jugada
for(int i = 0; i<temporal.size()-1;i++) {
//Tomamos una mano
Carta[] mejorTemp = temporal.get(i);
pos_mejor = i;
//Y aqui tomamos la otra mano para comparar
for(int j = i+1;j<temporal.size();j++) {
//1-Cuando tiene un trio de A (no existe una mejor baraja de trio que esta)
if(mejorTemp[0].valorPalo().charAt(0) == 'A' &&
mejorTemp[1].valorPalo().charAt(0) == 'A' &&
mejorTemp[2].valorPalo().charAt(0) == 'A') {
if(temporal.get(j)[0].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[1].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[2].valorPalo().charAt(0) == 'A') {
for(int k = 3;k<mejorTemp.length;k++) {
if(compara.compararValor(mejorTemp[k].valorPalo().charAt(0),
temporal.get(j)[k].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
}else {
break;
}
}else if(temporal.get(j)[0].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[1].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[2].valorPalo().charAt(0) == 'A') {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
//2-Cuando se tiene un par de A
//Si la primera mano comienza con el par de A
}else if(mejorTemp[0].valorPalo().charAt(0) == 'A' &&
mejorTemp[1].valorPalo().charAt(0) == 'A') {
//Si los dos tienen al comienzo el par de A
if(temporal.get(j)[0].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[1].valorPalo().charAt(0) == 'A') {
Carta mano1 = mejorTemp[2];
Carta mano2 = temporal.get(j)[2];
if(compara.compararValor(mano1.valorPalo().charAt(0),mano2.valorPalo().charAt(0))==-1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
}
//Caso contrario
}else {
Carta mano11 = mejorTemp[2];
Carta mano21 = temporal.get(j)[2];
if(compara.compararValor(mano11.valorPalo().charAt(0),mano21.valorPalo().charAt(0))==0) {
continue;//Primer posible problema: brake o continue?
}else if(compara.compararValor(mano11.valorPalo().charAt(0),mano21.valorPalo().charAt(0))==-1){
mejorTemp = temporal.get(j);
pos_mejor = j;
}
}
}else if(temporal.get(j)[0].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[1].valorPalo().charAt(0) == 'A') {
Carta mano12 = mejorTemp[2];
Carta mano22 = temporal.get(j)[2];
if(compara.compararValor(mano12.valorPalo().charAt(0),mano22.valorPalo().charAt(0))==0) {
mejorTemp = temporal.get(j);
pos_mejor = j;
}else if(compara.compararValor(mano12.valorPalo().charAt(0),mano22.valorPalo().charAt(0))==-1){
mejorTemp = temporal.get(j);
pos_mejor = j;
}
//3- Cuando no tiene A
}else {
for(int k = 0;k<mejorTemp.length;k++) {
if(compara.compararValor(mejorTemp[k].valorPalo().charAt(0),
temporal.get(j)[k].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
}
}
//Realizamos el intercambio
if(pos_mejor != i) {
Carta[] aux = temporal.get(pos_mejor);
temporal.set(pos_mejor, temporal.get(i));
temporal.set(i, aux);
}
}
//Retornamos la lista ordenada
return temporal;
}
private ArrayList<Carta[]> casoPoker() {
ArrayList<Carta[]> temporal = this.lista_p_ganadores;
//Va a ver tres casos
//1-Cuando tiene un poker con A
//2-Cuando tiene una A
//3-Cuando no tiene A
int pos_mejor;
ClsOrdena compara = new ClsOrdena();
//Ahora vamos a ordenar la lista de la mejor a la peor jugada
for(int i = 0; i<temporal.size()-1;i++) {
//Tomamos una mano
Carta[] mejorTemp = temporal.get(i);
pos_mejor = i;
//Y aqui tomamos la otra mano para comparar
for(int j = i+1;j<temporal.size();j++) {
//1-Cuando tiene un poker de A (no existe una mejor baraja de poker que esta)
if(mejorTemp[0].valorPalo().charAt(0) == 'A' &&
mejorTemp[1].valorPalo().charAt(0) == 'A' &&
mejorTemp[2].valorPalo().charAt(0) == 'A' &&
mejorTemp[3].valorPalo().charAt(0) == 'A') {
if(temporal.get(j)[0].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[1].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[2].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[3].valorPalo().charAt(0) == 'A') {
//Solo comparamos la ultima carta
if(compara.compararValor(mejorTemp[4].valorPalo().charAt(0),
temporal.get(j)[4].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
}
}else {
break;
}
}else if(temporal.get(j)[0].valorPalo().charAt(0) == 'A' &&
temporal.get(j)[1].valorPalo().charAt(0) == 'A') {
mejorTemp = temporal.get(j);
pos_mejor = j;
//2-Cuando se tiene una A
//Si los dos tienen al comienzo la A
//Si la primera mano comienza con A
}else if(mejorTemp[0].valorPalo().charAt(0) == 'A') {
if(temporal.get(j)[0].valorPalo().charAt(0) == 'A') {
Carta mano1 = mejorTemp[1];
Carta mano2 = temporal.get(j)[1];
if(compara.compararValor(mano1.valorPalo().charAt(0),mano2.valorPalo().charAt(0))==-1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
}
}else {
Carta mano11 = mejorTemp[1];
Carta mano21 = temporal.get(j)[0];
if(compara.compararValor(mano11.valorPalo().charAt(0),mano21.valorPalo().charAt(0))==0) {
continue;//Primer posible problema: brake o continue?
}else if(compara.compararValor(mano11.valorPalo().charAt(0),mano21.valorPalo().charAt(0))==-1){
mejorTemp = temporal.get(j);
pos_mejor = j;
}
}
}else if(temporal.get(j)[0].valorPalo().charAt(0) == 'A') {
Carta mano12 = mejorTemp[0];
Carta mano22 = temporal.get(j)[1];
if(compara.compararValor(mano12.valorPalo().charAt(0),mano22.valorPalo().charAt(0))==0) {
mejorTemp = temporal.get(j);
pos_mejor = j;
}else if(compara.compararValor(mano12.valorPalo().charAt(0),mano22.valorPalo().charAt(0))==-1){
mejorTemp = temporal.get(j);
pos_mejor = j;
}
//3- Cuando no tiene A
}else {
for(int k = 0;k<mejorTemp.length;k++) {
if(compara.compararValor(mejorTemp[k].valorPalo().charAt(0),
temporal.get(j)[k].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
}
}
//Realizamos el intercambio
if(pos_mejor != i) {
Carta[] aux = temporal.get(pos_mejor);
temporal.set(pos_mejor, temporal.get(i));
temporal.set(i, aux);
}
}
//Retornamos la lista ordenada
return temporal;
}
public ArrayList<Carta[]> primerGrupo() {
//Almacenamos la lista
ArrayList<Carta[]> temporal = this.lista_p_ganadores;
int pos_mejor;
ClsOrdena compara = new ClsOrdena();
//Ahora vamos a ordenar la lista de la mejor a la peor jugada
for(int i = 0; i<temporal.size()-1;i++) {
Carta[] mejorTemp = temporal.get(i);
pos_mejor = i;
for(int j = i+1;j<this.lista_p_ganadores.size();j++) {
for(int k = 0;k<mejorTemp.length;k++) {
if(compara.compararValor(mejorTemp[k].valorPalo().charAt(0),
temporal.get(j)[k].valorPalo().charAt(0)) == -1) {
mejorTemp = temporal.get(j);
pos_mejor = j;
break;
}
}
}
//Realizamos el intercambio
if(pos_mejor != i) {
Carta[] aux = temporal.get(pos_mejor);
temporal.set(pos_mejor, temporal.get(i));
temporal.set(i, aux);
}
}
//Retornamos la lista ordenada
return temporal;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment