Clase sudoku java

Páginas: 9 (2159 palabras) Publicado: 9 de noviembre de 2011
package aplicacioncita;
import java.math.*;

/**
*
* @author Jorge M
*/
public class Sudoku {
//declaramos los arreglos que contienen la info de las matrices
int m[][] = new int[9][9];
int[] m0= new int[4], m1= new int[5], m2= new int[8], m3= new int[6];
int[] m4= new int[5], m5= new int[6], m6= new int[8], m7= new int[5], m8= new int[4];
int cost=0;public Sudoku(){
//Definir valores default
m[0][0]=5;
m[0][1]=3;
m[1][0]=6;
m[2][1]=9;
m[2][2]=8;

m[0][4]=7;
m[1][3]=1;
m[1][4]=9;
m[1][5]=5;

m[2][7]=6;

m[3][0]=8;
m[4][0]=4;
m[5][0]=7;

m[3][4]=6;
m[4][3]=8;
m[4][5]=3;
m[5][4]=2;m[3][8]=3;
m[4][8]=1;
m[5][8]=6;

m[6][1]=6;

m[7][3]=4;
m[7][4]=1;
m[7][5]=9;
m[8][4]=8;

m[6][6]=2;
m[6][7]=8;
m[7][8]=5;
m[8][7]=7;
m[8][8]=9;

//Generar numeros aleatorios en los espacios vacios sin repeticiones

genRdm();
genCosto();

}//Generar numeros pseudo-aleatorios en los espacios vacios sin repeticiones
public void genRdm(){
int x;
//m0 llenar posiciones 2 4 5 6 -------------------------------------------------------------------------------------------------------
boolean b=false;
while(!b){
x = (int)Math.round(Math.random()*9);
if ( (x!=0) &&(x!=5) && (x!=3) && (x!=6) && (x!=9) && (x!=8) )
{ m[0][2]=x; b=true; }
}
b=false;
while(!b){
x = (int)Math.round(Math.random()*9);
if ( (x!=0) && (x!=5) && (x!=3) && (x!=m[0][2]) && (x!=6) && (x!=9) && (x!=8) )
{ m[1][1]=x; b=true; }
}b=false;
while(!b){
x = (int)Math.round(Math.random()*9);
if ( (x!=0) && (x!=5) && (x!=3) && (x!=m[0][2]) && (x!=6) && (x!=m[1][1]) && (x!=9) && (x!=8) )
{ m[1][2]=x; b=true; }
}
b=false;
while(!b){
x = (int)Math.round(Math.random()*9);
if ( (x!=0)&& (x!=5) && (x!=3) && (x!=m[0][2]) && (x!=6) && (x!=m[1][1]) && (x!=m[1][2]) && (x!=9) && (x!=8) )
{ m[2][0]=x; b=true; }
}
b=false;

//m1 llenar 0 2 6 7 8-------------------------------------------------------------------------------------------------------

while(!b){
x =(int)Math.round(Math.random()*9);
if ( (x!=0) && (x!=7) && (x!=1) && (x!=9) && (x!=5) )
{ m[0][3]=x; b=true; }
}
b=false;

while(!b){
x = (int)Math.round(Math.random()*9);
if ( (x!=0) && (x!=7) && (x!=1) && (x!=9) && (x!=5)&& (x!=m[0][3]) )
{ m[0][5]=x; b=true; }}
b=false;

while(!b){
x = (int)Math.round(Math.random()*9);
if ( (x!=0) && (x!=7) && (x!=1) && (x!=9) && (x!=5)&& (x!=m[0][3]) && (x!=m[0][5]) )
{ m[2][3]=x; b=true; }
}
b=false;

while(!b){
x = (int)Math.round(Math.random()*9);if ( (x!=0) && (x!=7) && (x!=1) && (x!=9) && (x!=5)&& (x!=m[0][3]) && (x!=m[0][5]) && (x!=m[2][3]) )
{ m[2][4]=x; b=true; }
}
b=false;

while(!b){
x = (int)Math.round(Math.random()*9);
if ( (x!=0) && (x!=7) && (x!=1) && (x!=9) && (x!=5)&& (x!=m[0][3]) && (x!=m[0][5]) && (x!=m[2][3]) &&...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Clases En Java
  • Clases de java
  • Las Clases En Java
  • Clase Java
  • CLASE JAVA
  • Java clase
  • Clases en java
  • Java Objetos, Clases

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS