Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I can see a problem:</p> <p>It should be: </p> <pre><code>if(board.isLegal()){ if( addSquare(depth, outStream)) return true; } </code></pre> <p>Means if the whole board is solved then roll back.</p> <p><strong>EDIT</strong> think about it:</p> <p>you put 1 in the first square, it returns false. don't you want to try put 2?</p> <p><strong>EDIT2</strong> More problem: </p> <pre><code>if(i == NINE &amp;&amp; j == NINE &amp;&amp; board.getSquare(NINE, NINE) != ZERO){ cout &lt;&lt; i &lt;&lt; " " &lt;&lt; j &lt;&lt; endl; return true; } </code></pre> <p>Is this suppose to be a completion check? you check only 1 square. and in your sample it is filled! you need to check that there is no 0.</p> <p><strong>EDIT3:</strong></p> <pre><code>bool DoTheWork::addSquare(int&amp; depth, ostream&amp; outStream){ //use flag to let you know if all completed bool zeroFound = false; for(int i = ONE; i &lt;= NINE; ++i){ for(int j = ONE; j &lt;= NINE; ++j){ //cout &lt;&lt; "original" &lt;&lt; board.getSquare(i, j) &lt;&lt; "coord: " &lt;&lt; i &lt;&lt; ", " &lt;&lt; j &lt;&lt; endl; if(board.getSquare(i, j) == ZERO){ zeroFound = true; //cout &lt;&lt; "original: " &lt;&lt; board.getSquare(i, j) &lt;&lt; "coord: " &lt;&lt; i &lt;&lt; ", " &lt;&lt; j &lt;&lt; endl; for(int k = ONE; k &lt;= NINE; ++k){ board.setSquare(i, j, k); board.display(outStream); if(board.isLegal()){ if(addSquare(depth, outStream)){ return true; } else{ board.unsetSquare(i, j); } } } } } } board.display(outStream); return !zeroFound; //true in case it is full! } </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