title: How do I calculate reversible id for each move on a board game?
body: <p>I try to build a 6x6 board game using pyhton. Every pieces can move 4 directions which are top, down, left and right. I am using a legacy code which is implemented for checkers. </p>
  
  <pre><code>------------------
  6 |x x - - o o |
  5 |x x - - o o |
  4 |- - - - - - |
  3 |- - - - - - |
  2 |o o - - x x |
  1 |o o - - x x |
  ------------------
     a b c d e f 
  </code></pre>
  
  <p>I have to write a function that is capable to calculate uniqe and reversible id for each movement. For example if a piece can move to all directions each movement should have different id.</p>
  
  <pre><code>def calc_move_id(x0, x1, y0, y1):
      """ Calculates move_id. 
      """
      # directions = (1, 0), (0, 1), (-1, 0), (0, -1)
      # x0, y0 -&gt; start point 
      # x1, y1 -&gt; destination point
      dx, dy = x1 - x0, y1 y0
      direction = 0
      if dx &gt; 0 and dy &lt; 1:
          direction = 0
      elif dx &lt; 1  and dy &gt; 0:
          direction = 1
      elif dx &lt; 0 and dy &lt; 1:
          direction = 2
      else:
          direction = 3
      start = int((8 * self.y0 + self.x0) / 2)  # 1d-index of black squares
      length = abs(dx)
      vector = direction + (length - 1) * 4
      move_id = (vector &lt;&lt; 5) | start
      return move_id
  
  def parse_move(move_id):
      """ @see calc_move_id() """
      start = action &amp; 31  # start/from
      action = action &gt;&gt; 5
      vector = action
      length = int(vector / 4) + 1
      direction_id = vector % 4
      direction = Move.__directions[direction_id]
      x0, y0 = (start % 4) * 2, int(start / 4)
      if y0 % 2 == 1:
          x0 += 1
      x1, y1 = x0 + direction[0] * length, y0 + direction[1] * length
      assert (
              0 &lt;= x0
              and x0 &lt; 6
              and 0 &lt;= x1
              and x1 &lt; 6
              and 0 &lt;= y0
              and y0 &lt; 6
              and 0 &lt;= y1
              and y1 &lt; 6
      ), ("Illegal action: " + str(action) + "=&gt;" + str((x0, y0, x1, y1)))
      return (x0, x1, y0, y1)
  </code></pre>
  
  <p>Above code doesn't work because its throw assertion error in parse_move function. 
  How can i achieve that ?  What should i use ? (ex. decode, encode, bitwise, bitmask implementation) </p>