代码不能从未知原因工作(没有错误)

时间:2017-08-10 11:23:38

标签: java

所以基本上我是一个初学者程序员,我试图用蛮力算法构建这个非常简单的soduku生成器,但由于某种原因它不起作用,它应该做的是我分为9到9像游戏中一样的9个数字的立方体,软件随机地将1-9之间的值一个接一个地设置到二维数组中,同时检查它设置的值是否在它的行中再次出现(像游戏的规则),我这样做是不可能在9个数字的同一个框中出现相同的数字(如在游戏中)

如果有人对代码有经验我会非常感谢你帮助新手

代码:

    // package whatever; // don't place package name!

    import java.util.ArrayList;
    import java.util.Arrays;

    class random_board
    {
        public static void main (String[] args) throws java.lang.Exception
        {
          //  while (pass = false){


                /*ArrayList<Integer[]> Random_Pick_List = new ArrayList<>();
         Random_Pick_List= [1;2;3;4;5;6;7;8;9];*/
            int[][] board = new int[9][9];

       int calum = 0;
     for(int r =0;r<=2;r++) {    
      int line = 0;
      for (int q =0; q<=2;q++) {   
           ArrayList<Integer> Random_Pick_List =
            new ArrayList<Integer>(Arrays.asList(1,2,3,4,5,6,7,8,9));
        int counter = 9;
        for (int i = 0 ; i<=3;i++){
            for (int j = 0 ; j<=3;j=j){
                int n= floor(Math.random() * counter);

                board[j+line][i+calum]= Random_Pick_List.get(n);
                if (board[i][0] != n && board[i][1] != n&& board[i][2] != n && board[i][3] != n && board[i][4] != n && board[i][5] != n && board[i][6] != n && board[i][7] != n && board[i][8] != n && board[0][j] != n && board[1][j] != n && board[2][j] != n && board[3][j] != n && board[4][j] != n && board[5][j] != n && board[6][j] != n && board[7][j] != n && board[8][j] != n )  
                j++;
                counter--;
                Random_Pick_List.remove(n);

            }
            }
        }

      line =line +3;
      }  
     calum=calum+3;
     //}




    //pass = board_check(board);
    //}

         for (int i =0;i<=9;i++){
            for (int j =0;j<=9;j++){
                   System.out.print(board[i][j] + " ");
        }
        System.out.println();
    }

     /* for (int i =0;i<=9;i++){
            for (int j =0;j<=9;j++){
    public boolean board_check(integer[][] board ) {
        for (int i =0;i<=9;i++){
            for (int j =0;j<=9;j++){
            int n = board[i][j];
            board[i][j]=10;
     if (board[i][0] != n && board[i][1] != n&& board[i][2] != n && board[i][3] != n && board[i][4] != n && board[i][5] != n && board[i][6] != n && board[i][7] != n && board[i][8] != n && board[0][j] != n && board[1][j] != n && board[2][j] != n && board[3][j] != n && board[4][j] != n && board[5][j] != n && board[6][j] != n && board[7][j] != n && board[8][j] != n )  
        boolean pass = true;
        }
       }
    return pass;

    }
    */
    }

        private static int floor(double d) {
            // TODO Auto-generated method stub
            return 0;
        }
    }

0 个答案:

没有答案