title: Knight's Tour Heuristic c++
body: <p>I'm stuck. I know that I want my program to make a move, subtract one value from the possible moves of the heuristic and when a place reaches 0 or if it is touched then I don't want it to try for it. I'm trying to make the Knight's tour go for the lowest values first in the accessibility array and then try to go for the next higher number. If anyone has any insight on how I would go about doing this I'd greatly appreciate it.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  #include &lt;ctime&gt;
  #include &lt;iomanip&gt;
  
  using namespace std;
  int access[8][8] ={ {2,3,4,4,4,4,3,2},
                      {3,4,6,6,6,6,4,3},
                      {4,6,8,8,8,8,6,4},
                      {4,6,8,8,8,8,6,4},
                      {4,6,8,8,8,8,6,4},
                      {4,6,8,8,8,8,6,4},
                      {3,4,6,6,6,6,4,3},
                      {2,3,4,4,4,4,3,2}};
  
  bool boardTest(int move, int row, int col);
  bool newMove(int board[8][8], int move, int row, int col);
  bool validTest(int board[8][8], int move, int row, int col);
  void printHeuristic(int[8][8]);
  void printArray( int[8][8]);
  void knightMvt(int board[8][8], int move, int &amp;currentRow, int &amp;currentCol);
  
  int runKnight(int board[8][8], bool movesKnightTried[8], int startRow, int startCol);
  
  const int horizontal[8] = {2, 1, -1, -2, -2, -1, 1, 2};
  const int vertical[8]= {-1, -2, -2, -1, 1, 2, 2, 1};
  
  int main()
  {
      bool movesKnightTried[8] = { 0 };
      int board[8][8] = { 0 };
      printHeuristic(access);
      int currentRow = 0;
      int currentCol = 0;
      
      int startRow = 0;
      int startCol=0;
  
      int counter = runKnight(board, movesKnightTried, startRow, startCol);
      printArray(board);
  
  }
  
  int runKnight(int board[8][8], bool movesKnightTried[8], int startRow, int startCol)
  {
      int pastCounter;
      bool noValidMove = false;
      int currentRow;
      int currentCol;
      int counter = 1;
      currentRow = startRow;
      currentCol = startCol;
  
      int bestMove = -1;
      int bestAccessibility = 99;
      board[currentRow][currentCol] = counter;
      while (counter &lt; 65 &amp;&amp; noValidMove == false)
      {
  
          for (int move = 0; move&lt;8;move++)
          {
          
              if (validTest(board, move, currentRow, currentCol) &amp;&amp; 
              access[currentRow + vertical[move]][currentCol + horizontal[move]] &lt;= bestAccessibility)
              {
                  bestMove = move;
                  bestAccessibility = access[currentRow+vertical[move]][currentCol + horizontal[move]];
                  
                  knightMvt(board, move,  currentRow, currentCol);
              
                  counter++;
              
                  board[currentRow][currentCol] = counter;
              
                  break;
              
              }
              if (move == 7)
              {
                  noValidMove = true;
              }
          
          }
  
      }
      
      return 0;
  };
  
  void printArray( int board[8][8])
  {
      for (int r = 0; r &lt; 8; r++)
      {
          for (int c = 0; c &lt; 8; c++)
              cout &lt;&lt; setw(3) &lt;&lt; board[r][c] &lt;&lt; ' ';
              
          cout &lt;&lt; endl;
      }
  };
  
  void printHeuristic( int heuristic[8][8])
  {
      for (int r = 0; r &lt; 8; r++)
      {
          for (int c = 0; c &lt; 8; c++)
              cout &lt;&lt; setw(3) &lt;&lt; heuristic[r][c] &lt;&lt; ' ';
              
          cout &lt;&lt; endl;
      }
  };
  
  bool boardTest(int move, int row, int col)
  {
      if (row + vertical[move] &lt;0 || row+ vertical[move]&gt;7)
      {
          return false;
      }
      else if (col + horizontal[move]&lt;0 || col + horizontal[move]&gt;7)
      {
          return false;
      }
      else
      {
          return true;
      }
  };
  
  
  bool validTest(int board[][8], int move, int row, int col)
  {
      if(boardTest(move, row, col) &amp;&amp; newMove(board, move, row, col))
      {
          return true;
      }
      else
      {
          return false;
      }
  };
  
  
  bool newMove(int board[8][8], int move, int row, int col)
  {
      if (board[row + vertical[move]][col + horizontal[move]] == 0)
      {
          return true;
      }
      else
      {
          return false;
      }
  };
  
  void knightMvt(int board[8][8], int move, int&amp; curRow, int&amp; curCol)
  {
      curRow += vertical[move];
      curCol += horizontal[move];
  };
  </code></pre>