private boolean canCastleKingSide( int position ) {
    return ( !hasPieceMoved( pieceAt( position ) ) && !kingInCheck() && pieceTypeAt( position + 3 ) == ROOK && !hasPieceMoved( pieceAt( position + 3 ) )
             && squareEmpty( position + 1 ) && !squareAttacked( position + 1 )
             && squareEmpty( position + 2 ) && !squareAttacked( position + 2 ) );
  }