Implemented isLegalMove() and several helper methods.