Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Su Do Ku
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TheFerret




PostPosted: Tue Aug 09, 2005 1:47 am   Post subject: Su Do Ku

I am trying to make a Java version of the game Su Do Ku and I can get one could get all coloums generated (not rows) but the way I currently do it is very unefficent that many times... Any ways to shorten it down and easier to get all boxes, rows, and coloums to work out right...

Java:
public class SuDoKu
{
        public static void main (String[] args)
        {
                int minNumber=1;
                int maxNumber=9;
                int[] [] board=new int [10][10];
                boolean [] vaild= new boolean [9];
                int temp;
                boolean check=false;
       
                for(int i = 0; i < 9; i++)       
            {     
                     vaild[i]=false;                   
            }   
               
                for(int i = 0; i < 8; i++)       
            {     
                     vaild[i]=false;                   
            }     
            
            for(int j = 0;j < 9; j++)
            {
                while(check==false)
                {
                 temp = (int) (Math.random() * 100) % (maxNumber-minNumber+1) + minNumber;
                                if(vaild[temp-1] == false)
                                {
                                        board[j][1]=temp;
                                        vaild[temp-1]=true;
                                        System.out.println(board[j][1]);
                                        check=true;
                                }
                        }
                        check=false;
                }
                                       
        }
}
Sponsor
Sponsor
Sponsor
sponsor
Hikaru79




PostPosted: Sat Aug 13, 2005 10:26 pm   Post subject: (No subject)

Have a look here Smile It's not really a direct answer to your question, but it should give you a few hints on how to continue.
TheFerret




PostPosted: Sun Aug 14, 2005 12:21 am   Post subject: (No subject)

It kinda helps but I am not trying to solve the puzzle, I am trying to make one...

So far, I have got:

Java:
public class SuDoKu
{
        public static void main (String[] args)
        {
                int minNumber=1;
                int maxNumber=9;
                int[] [] board=new int [10][10];
                boolean [] vaild= new boolean [9];
                int temp;
                int temp1;
                boolean check=false;
       
                for(int i = 0; i < 9; i++)       
            {     
                     vaild[i]=false;                   
            }   

            for(int i=0;i<9;i++)
            {
                for(int j = 0;j < 9; j++)
                     {
                          while(check==false)
                    {
              temp = (int) (Math.random() * 100) % (maxNumber-minNumber+1) + minNumber;
                                        if(vaild[temp-1] == false)
                                        {
                                                board[j][i]=temp;
                                                vaild[temp-1]=true;
                                        //      System.out.print(board[j][i]);
                                                check=true;
                                        }
                                }
                                check=false;
                        }
                                System.out.println();   
                        for(int a=0;a<9;a++)
                        {
                                vaild[a]=false;
                        }
                }
int value=1;

                for(int a=0;a<9;a++)
                {
                        for(int b=0;b<9;b++)
                        {
                                for(int c=0;c<9;c++)
                                {
                                        for(int d=0;d<9;d++)
                                        {
                                                while(value==1)
                                                {
                                                        if(board[a][c]==board[b][d])
                                                        {
                                                                for(int i=0;i<9;i++)
                                                {
                                              for(int j = 0;j < 9; j++)
                                                            {
                                                                 while(check==false)
                                                        {
                                            temp = (int) (Math.random() * 100) % (maxNumber-minNumber+1) + minNumber;
                                                                                        if(vaild[temp-1] == false)
                                                                                        {
                                                                                                board[j][i]=temp;
                                                                                                vaild[temp-1]=true;
                                                                                                System.out.print(board[j][i]);
                                                                                                check=true;               
                                                                                        }
                                                                                }
                                                                                check=false;
                                                                        }
                                                                        System.out.println();   
                                                                        for(int e=0;e<9;e++)
                                                                        {
                                                                                vaild[e]=false;
                                                                        }
                                                                }
                                                        }
                                                        for (int f=0;f<9;f++)
                                                        {
                                                                for(int g=0;g<9;g++)
                                                                {
                                                                        for (int h=0;h<9;h++)
                                                                        {
                                                                                for (int o=0;o<9;o++)
                                                                                {
                                                                                        if(board[f][g]!=board[h][o])
                                                                                        {
                                                                                                value=0;
                                                                                        }
                                                                                }
                                                                        }
                                                                }
                                                        }value=1;
                                                        System.out.println();
                                                }
                                        }
                                }
                        }
                }
        }
}


The first set of loops generates inital numbers and the second longer set checks it, I got it to go but it kept on going for an hour to try and generate one board...
xtreemboarder




PostPosted: Fri Apr 21, 2006 12:29 pm   Post subject: (No subject)

im sorry but that is the most confusing program i have ever seen
Andy




PostPosted: Fri Apr 21, 2006 12:31 pm   Post subject: (No subject)

holy crap.. umm dont use tabs for indenting.. use spaces, or set your editor such that when you press tab it places 4 spaces or anythign.. also follow the sun java standard of 80 characters per line
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: