os dejo el codigo a ver si veis algo raro o una mejor manera de hacerlo.
me estoy basando en esto
Código:
y mi codigo es este...Teniendo un numero "x" de equipos por ejemplo 6, lo que hago disponerlos de la siguiente manera considerando a la cantidad de equipos menos 1, es decir los equipos desde el 1 hasta el 5. 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 La cantidad de columnas me lo indica la cantidad de equipos divida en dos. En este caso 3 columnas si considero 6 equipos. La cantidad de filas me lo determina la cantidad de equipos menos uno. Para el ejemplo, 5 filas. Ahora a la primer columna le agrego el equipo restante que seria el equipo numero 6. Entonces quedaria 1-6 2 3 4-6 5 1 2-6 3 4 5-6 1 2 3-6 4 5 Y por ultimo a partir de la segunda columna voy formando las demas "parejas" que faltan con los equipos de forma descendente, desde el ultimo (sin considerar al equipo 6 que ya fue agregado) hasta el primero. 1-6 2-5 3-4 4-6 5-3 1-2 2-6 3-1 4-5 5-6 1-4 2-3 3-6 4-2 5-1 De esta manera ya quedaria armado el fixture donde cada fila correspondería a la fecha y cada columna (que seria cada pareja que hay en esa fila) a los partidos. Siguiendo el ejemplo FECHA 1 1vs6 2vs5 3vs4 FECHA 2 4vs6 5vs3 1vs2 FECHA 3 2vs6 3vs1 4vs5 FECHA 4 5vs6 1vs4 2vs3 FECHA 5 3vs6 4vs2 5vs1
Código:
public void CrearCombinaciones(String equipos[]) {
// tv_calendario.setText(equipos[1] + equipos[0]); //Prueba ok
String matriz1[][] = new String[equipos.length - 1][equipos.length / 2];
String matriz2[][] = new String[equipos.length - 1][equipos.length / 2];
String matriz3[][] = new String[equipos.length - 1][equipos.length / 2];
int cont = 0;
for (int i = 0; i < equipos.length - 1; i++) {
for (int j = 0; j < equipos.length / 2; j++) {
if (cont == equipos.length - 2) {
matriz1[i][j] = Integer.toString(cont);
cont = 0;
} else {
matriz1[i][j] = Integer.toString(cont);
cont++;
}
}
}
/****************************** Primera Vuelta ***************************/
int cont2 = equipos.length - 2;
// Primera vuelta
for (int k = 0; k < equipos.length - 1; k++) {
for (int n = 0; n < equipos.length / 2; n++) {
if (n == 0) {
// Pongo el mayor que omitiamos
if (k % 2 == 0) {
// Local
matriz2[k][n] = (equipos.length - 1) + "vs"
+ matriz1[k][n] + "\n";
} else {
// Visitante
matriz2[k][n] = matriz1[k][n] + "vs"
+ (equipos.length - 1) + "\n";
}
} else {
if (cont2 == 0) {
matriz2[k][n] = matriz1[k][n] + "vs"
+ Integer.toString(cont2) + "\n";
cont2 = equipos.length - 2;
} else {
matriz2[k][n] = matriz1[k][n] + "vs"
+ Integer.toString(cont2) + "\n";
cont2--;
}
}
}
}
/****************************** Segunda Vuelta ***************************/
int cont3 = equipos.length - 2;
// Primera vuelta
for (int k = 0; k < equipos.length - 1; k++) {
for (int n = 0; n < equipos.length / 2; n++) {
if (n == 0) {
// Pongo el mayor que omitiamos
if (k % 2 == 0) {
// Visitante
matriz3[k][n] = matriz1[k][n] + "vs"
+ (equipos.length - 1) + "\n";
} else {
// Local
matriz3[k][n] = (equipos.length - 1) + "vs"
+ matriz1[k][n] + "\n";
}
} else {
if (cont3 == 0) {
matriz3[k][n] = Integer.toString(cont3) + "vs"
+ matriz1[k][n] + "\n";
cont3 = equipos.length - 2;
} else {
matriz3[k][n] = Integer.toString(cont3) + "vs"
+ matriz1[k][n] + "\n";
cont3--;
}
}
}
}
/******************** mostrarlos ***************/
String todo = "";
// Muestro la primera vuelta
for (int i = 0; i < equipos.length - 1; i++) {
for (int j = 0; j < equipos.length / 2; j++) {
todo = todo + matriz2[i][j];
}
todo = todo + "\n";
}
// Muestro la segunda vuelta
for (int i = 0; i < equipos.length - 1; i++) {
for (int j = 0; j < equipos.length / 2; j++) {
todo = todo + matriz3[i][j];
}
todo = todo + "\n";
}
tv_calendario.setText(todo);
}


