private static final int computeDirection(int from,int to){
  int dx=Position.getX(to) - Position.getX(from);
  int dy=Position.getY(to) - Position.getY(from);
  if (dx == 0) {
    if (dy == 0)     return 0;
    return (dy > 0) ? 8 : -8;
  }
  if (dy == 0)   return (dx > 0) ? 1 : -1;
  if (Math.abs(dx) == Math.abs(dy))   return ((dy > 0) ? 8 : -8) + (dx > 0 ? 1 : -1);
  if (Math.abs(dx * dy) == 2)   return dy * 8 + dx;
  return 0;
}

private static final int computeDirection ( int from , int to ) { int dx = Position . getX ( to ) - Position . getX ( from ) ; int dy = Position . getY ( to ) - Position . getY ( from ) ; if ( dx == 0 ) { if ( dy == 0 ) return 0 ; return ( dy > 0 ) ? 8 : - 8 ; } if ( dy == 0 ) return ( dx > 0 ) ? 1 : - 1 ; if ( Math . abs ( dx ) == Math . abs ( dy ) ) return ( ( dy > 0 ) ? 8 : - 8 ) + ( dx > 0 ? 1 : - 1 ) ; if ( Math . abs ( dx * dy ) == 2 ) return dy * 8 + dx ; return 0 ; }
if there is a piece type that can move from " from " to " to " , return the corresponding direction , 8 * dy + dx .
