Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've managed to be more concise and more clear but it still won't run... I just need a push over the edge and I'm home free. I've dumped so many wasted hours into this project:</p> <pre><code>public ArrayList&lt;Integer&gt; needAtLoc(int r, int c){ int bc=c/3;//the column within the SudokuBoard int blc; /*The two posibilities for the column within each SudokuBlock:*/ if(c&gt;=0 &amp;&amp; c&lt;3) { blc=c; } else { blc=c%3; } int br=r/3; //the row within the SudokuBoard int blr; /*The two possiblities for the row within each SudokuBlock:*/ if(r&gt;=0 &amp;&amp; r&lt;3) { blr=r; } else { blr=r%3; } ArrayList&lt;Integer&gt; needR = new ArrayList&lt;Integer&gt;(); needR=checkR(r);// needR.trimToSize(); System.out.println(needR);////////////// ArrayList&lt;Integer&gt; needC=new ArrayList&lt;Integer&gt;(); needC=checkC(c); needC.trimToSize(); System.out.println(needC);///////////// ArrayList&lt;Integer&gt; needBl=new ArrayList&lt;Integer&gt;(); needBl=this.board[br][bc].updateMissing(); //that method updates and returns an ArrayList needBl.trimToSize(); ArrayList&lt;Integer&gt; poss=new ArrayList&lt;Integer&gt;(); poss.clear(); for(Integer e: needBl){ if(needC.contains(e) &amp;&amp; needR.contains(e)){ poss.add(e); } } return poss; } //this method throws the StackOverflowError public void play(int r, int c){ int bc=c/3; //the column within the SudokuBoard int blc; /*The two posibilities for the column within each SudokuBlock:*/ if(c&gt;=0 &amp;&amp; c&lt;3) { blc=c; } else { blc=c%3; } int br=r/3; //the row within the SudokuBoard int blr; /*The two possiblities for the row within each SudokuBlock:*/ if(r&gt;=0 &amp;&amp; r&lt;3) { blr=r; } else { blr=r%3; } if(needAtLoc(r,c).size()==9){ int num=1+generator.nextInt(9); this.board[br][bc].setValue(blr, blc, num); if(c&lt;8){ System.out.println(this);/////////////// play(r, c+1); } else{ play(r+1, 0); } } else{ if(needAtLoc(r,c).size()==0){ //no possible moves if(c&gt;0){ bc=(c-1)/3; if(c&gt;0 &amp;&amp; c&lt;4) { blc=c-1; } else { blc = (c-1) % 3; } this.board[br][bc].setValue(blr, blc, 0); play(r, c-1); } else{ blc=0; bc=0; if(r==0){ blr=0; br=0; this.board[br][bc].setValue(blr, blc, 0); play(r,c); } else{ br=(r-1)/3; if(r&gt;0 &amp;&amp; r&lt;4) {blr=r-1;} else {blr=(r-1)%3;} this.board[br][bc].setValue(blr, blc, 0); play(r-1, 8); } } } else{//if there are possible moves int num=needAtLoc(r,c).remove(generator.nextInt(needAtLoc(r,c).size())); this.board[br][bc].setValue(blr, blc, num); System.out.println(this);////////////// if(r==8 &amp;&amp; c==8){ return; } else{ if(c&lt;8){ play(r, c+1); } else{ play(r+1, 0); } } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload