title: What is this java conditional doing?
body: <p>I made a nine game puzzle in Java. The goal is get the numbers back in order. Game board below is stored in a 2d <code>ArrayList</code>. The game looks like:</p>
  <pre class="lang-none prettyprint-override"><code>2 5 1
  3 6 7
  4 8
  </code></pre>
  <p>A valid move would 7 or 8, in which case the blank space will swap with the selected number. 6 would not be valid, nor any numbers 1 - 6 in this state. The first way I coded my <code>isValidMove</code> function was a nightmare of nested switch &amp; conditionals. I came across somebody else's code and it works perfectly for me. This is the code that replaced my nested mess:</p>
  <pre class="lang-java prettyprint-override"><code>int differenceX = Math.abs(empty1 - move1);
  int differenceY = Math.abs(empty2 - move2);
  if (differenceX &lt;= 1 &amp;&amp; differenceY &lt;= 1 &amp;&amp; !(differenceX == 1 &amp;&amp; differenceY == 1))
  {
      return true;
  }
  return false;
  </code></pre>
  <p>I understand what's happening until the <code>&amp;&amp; !(differenceX == 1 &amp;&amp; differenceY == 1))</code>.
  Checking the absolute value of the difference is 0 or 1 makes sense. It then seems to be also checking that the difference is not equal to 1. I presume this has something to do with ensuring a number like 6 isn't considered valid. Can someone please explain what is happening here? My brain hurts.</p>