-
-
Save sanrodari/62aed6737654f6999535 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// * verticar -> vertical | |
// * obtenerResultado en vez de imprimirResultado, además decía imprir, ese método no imprime nada. | |
// * No hay consistencia al usar descendente y en el método imprimir dizque decreciente. | |
// * Papi que es eso de horizontal descendente y ascendente. | |
// * Transversal y diagonal sinónimos, son confusos esos nombres. | |
package parcialbactraking; | |
public class ParcialBactraking { | |
private String verticalDescendente, verticalAscendente, horizontalDescendente, | |
horizontalAscendente, diagonalDescendente, diagonalAscendente, | |
transversalDescendente, transversalAscendente = ""; | |
private char matrizSopaDeLetras[][] = | |
{{'F', 'L', 'O', 'R', 'E', 'C', 'E', 'X', 'P', 'K', 'A', 'N', 'M', 'H', 'L'}, | |
{'G', 'W', 'P', 'S', 'M', 'B', 'B', 'F', 'S', 'V', 'D', 'A', 'S', 'E', 'B'}, | |
{'Y', 'R', 'J', 'Ù', 'J', 'A', 'O', 'D', 'W', 'A', 'O', 'O', 'M', 'R', 'C'}, | |
{'K', 'Q', 'A', 'L', 'Z', 'K', 'R', 'Á', 'M', 'C', 'R', 'S', 'A', 'M', 'E'}, | |
{'A', 'E', 'C', 'C', 'G', 'C', 'V', 'A', 'U', 'A', 'A', 'O', 'D', 'O', 'T'}, | |
{'Y', 'F', 'U', 'Z', 'I', 'I', 'U', 'I', 'V', 'C', 'R', 'Z', 'R', 'S', 'F'}, | |
{'U', 'V', 'I', 'N', 'D', 'A', 'I', 'I', 'M', 'I', 'F', 'B', 'E', 'A', 'A'}, | |
{'D', 'I', 'D', 'I', 'O', 'E', 'S', 'Z', 'L', 'O', 'L', 'Ñ', 'H', 'S', 'M'}, | |
{'A', 'C', 'A', 'Ñ', 'F', 'V', 'D', 'A', 'H', 'N', 'O', 'L', 'N', 'Ñ', 'I'}, | |
{'N', 'L', 'R', 'O', 'K', 'M', 'I', 'N', 'É', 'E', 'J', 'E', 'O', 'W', 'L'}, | |
{'T', 'W', 'A', 'S', 'I', 'C', 'O', 'O', 'R', 'S', 'B', 'É', 'Í', 'S', 'I'}, | |
{'E', 'V', 'K', 'Ú', 'E', 'S', 'C', 'E', 'L', 'E', 'B', 'R', 'A', 'N', 'A'}, | |
{'L', 'V', 'C', 'P', 'M', 'Q', 'E', 'M', 'E', 'J', 'O', 'R', 'P', 'R', 'U'}, | |
{'R', 'M', 'S', 'Z', 'P', 'R', 'E', 'S', 'E', 'N', 'T', 'E', 'Ñ', 'R', 'A'}, | |
{'B', 'E', 'K', 'W', 'A', 'K', 'O', 'B', 'S', 'E', 'Q', 'U', 'I', 'O', 'S'}}; | |
public static void main(String[] args) { | |
new ParcialBactraking(); | |
} | |
public ParcialBactraking() { | |
buscarCandidato(0, 0, "ESPECIAL"); | |
} | |
private void buscarCandidato(int x, int y, String palabra) { | |
if (x < matrizSopaDeLetras[0].length) { | |
if (y < matrizSopaDeLetras.length) { | |
if (palabra.charAt(0) == matrizSopaDeLetras[x][y]) { | |
asignarDirecciones(x, y, palabra, 0, 0); | |
String resultado = obtenerResultado(x, y, palabra); | |
if (!resultado.equals("vacio")) { | |
System.out.println(resultado); | |
} | |
} | |
else { | |
buscarCandidato(x, y + 1, palabra); | |
} | |
} else { | |
buscarCandidato(x + 1, 0, palabra); | |
} | |
} | |
} | |
private void asignarDirecciones(int x, int y, String comparacion, int m, int i) { | |
if (m < comparacion.length()) { | |
if (i < matrizSopaDeLetras.length) { | |
if (x + i < matrizSopaDeLetras.length) { | |
verticalDescendente += matrizSopaDeLetras[x + i][y]; | |
} | |
if (x - i >= 0) { | |
verticalAscendente += matrizSopaDeLetras[x - i][y]; | |
} | |
if (y + i < matrizSopaDeLetras[0].length) { | |
horizontalDescendente += matrizSopaDeLetras[x][y + i]; | |
} | |
if (y - i >= 0) { | |
horizontalAscendente += matrizSopaDeLetras[x][y - i]; | |
} | |
if (x + i < matrizSopaDeLetras.length && y + i < matrizSopaDeLetras[0].length) { | |
diagonalDescendente += matrizSopaDeLetras[x + i][y + i]; | |
} | |
if (x - i >= 0 && y - i > 0) { | |
diagonalAscendente += matrizSopaDeLetras[x - i][y - i]; | |
} | |
if (x - i >= 0 && y + i < matrizSopaDeLetras[0].length) { | |
transversalDescendente += matrizSopaDeLetras[x - i][y + i]; | |
} | |
if (y - i >= 0 && x + i < matrizSopaDeLetras.length) { | |
transversalAscendente += matrizSopaDeLetras[x + i][y - i]; | |
} | |
asignarDirecciones(x, y, comparacion, m, i + 1); | |
} else { | |
asignarDirecciones(x, y, comparacion, m + 1, 0); | |
} | |
} | |
} | |
private String obtenerResultado(int x, int y, String comparacion) { | |
String posicion = x + "," + y; | |
if (verticalDescendente.contains(comparacion)) { | |
return "Si encontro en vertical descendente: " + posicion; | |
} | |
if (verticalAscendente.contains(comparacion)) { | |
return "Si encontro en vertical ascendente: " + posicion; | |
} | |
if (horizontalDescendente.contains(comparacion)) { | |
return "Si encontro en horizontal descendente: " + posicion; | |
} | |
if (horizontalAscendente.contains(comparacion)) { | |
return "Si encontro en horizontal ascendente: " + posicion; | |
} | |
if (diagonalAscendente.contains(comparacion)) { | |
return "Si encontro en diagonal ascendente: " + posicion; | |
} | |
if (diagonalDescendente.contains(comparacion)) { | |
return "Si encontro en diagonal descendente: " + posicion; | |
} | |
if (transversalAscendente.contains(comparacion)) { | |
return "Si encontro en transversal ascendente: " + posicion; | |
} | |
if (transversalDescendente.contains(comparacion)) { | |
return "Si encontro en transversal descendente: " + posicion; | |
} | |
return "vacio"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thwsr