Function to test whether the source and destination squares represent a valid knight move
It looks like there may be an issue in range-checking.


You don't check for the rows and columns to be non-negative.
( &lt; 0 ) The types aren't marked as unsigned, so they might be negative.
If board is zero-based, and it seems to be, checking against numXYZ should include the boundary.
( &gt;= board.numXYZ() )


The range check becomes:

if ( r1 &lt; 0 || r1 &gt;= board.numRows() ||
     r2 &lt; 0 || r2 &gt;= board.numRows() ||
     c1 &lt; 0 || c1 &gt;= board.numCols() ||
     c2 &lt; 0 || c2 &gt;= board.numCols() ) {
  return false;
}


The jump check can be simplified. The absolute distance in one dimension must be one, and in the other must be two.

unsigned int rowdiff = abs(r1 - r2);
unsigned int coldiff = abs(c1 - c2);
if ( rowdiff == 1 &amp;&amp; coldiff == 2 || rowdiff == 2 &amp;&amp; coldiff == 1 )


Alternatively, we can note that the product of the distances must be ±2, leading to a more concise check, but that may obscure the underlying objective:

if ( abs((r1 - r2) * (c1 - c2)) != 2 ) return false;


At which point the final check is:

return board[r1][c1] == "knight" &amp;&amp; board[r2][c2] == "";