Note that there are some explanatory texts on larger screens.

plurals
  1. PO'list iterator not dereferencable'
    primarykey
    data
    text
    <pre><code> #include &lt;iostream&gt; using namespace std; #include &lt;list&gt; //A queue for the working set //x,y co-ords of the square, path length so far struct square { int x; int y; int path_length; }; list&lt;square&gt; workingset; //A 2D array of ints to represent the board (duplicates list) int board[10][10]; void generatelegalmove(square node, int x_offset, int y_offset); void printboard(); void main() { //Initialises the board int i, j; for (i=0; i&lt;10; i++) { for (j=0; j&lt;10; j++) { board[i][j] = 0; } } //The goal position - a number we will never reach board[8][8] = 1337; bool goal_found = false; //Sets up initial position square temp = {3, 7, 1}; //Put initial position in working set and duplicates list workingset.push_back(temp); board[3][7] = 1; //Loop (until a goal is found) while(!goal_found) { //Get the head node from the working set square nodetocheck = workingset.front(); //Exit if the goal has been found if(board[nodetocheck.x][nodetocheck.y] == 1337) { goal_found = true; break; } //Generate the legal moves generatelegalmove(nodetocheck, -1, 0); //One square to the left generatelegalmove(nodetocheck, 0, -1); //One square up generatelegalmove(nodetocheck, 1, 0); //One square to the right generatelegalmove(nodetocheck, 0, 1); //One square down if(!workingset.empty()) { //workingset.pop_front(); } //End Loop } //Print the Board printboard(); while(true); //Trace back and print Trace back (once implemented) //Print other info } void generatelegalmove(square node, int x_offset, int y_offset) { node.x = node.x + x_offset; node.y = node.y + y_offset; node.path_length = node.path_length+1; //Is this square on the board if((node.x &gt;= 0) &amp;&amp; (node.x &lt; 10) &amp;&amp; (node.y &gt;= 0) &amp;&amp; (node.y &lt; 10) &amp;&amp; //Is this square empty (board[node.x][node.y] == 0)) { workingset.push_back(node); board[node.x][node.y] = node.path_length; //Add to working set //Add to duplicates list } //(If a graphical animation is added, do it here, by printing the new board after each one, then sleeping for a few seconds) } </code></pre> <p>I get the runtime error 'list iterator not dereferencable'.</p> <p>I'm assuming this is to do with <code>workingset.pop_front()</code> being called from within the while loop, but I'm not sure what I should do to remedy this.</p> <p>Each loop, I want to get the node from the front of the list, work with it a little, then remove that node from the list. </p> <p>This is the code for generatelegalmove() - as you can see, if the new square is on the board (i.e. within the range of 0-9 in both dimensions of the array, and the square is empty) it will add this new node to the working set and the board[][] (which is effectively a duplicates list in effect) </p>
    singulars
    1. This table or related slice is empty.
    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.
 

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