- Match the type of accidentals used by the key signature.
- Use sharps when the melody is moving up, and flats when it's moving down.
- Use whatever accidentals give you a visually pleasing spacing of notes in "thirds" as represented on the staff. (As advocated here.)
- Use the accidentals that are physically compatible with other notes in the chord. (Only a concern for certain instruments, but e.g. I understand that the pedals on a harp affect many strings at once, so playing a particular combination of notes may require a clever approach to the pedals, indicated by what might otherwise look like an unnatural set of accidentals. This wouldn't apply to a piano, where G# is just a separate key from G, not a modification of the G key.) I think this is what you're going for?
Another example would be the bass side of an accordion where Db and C# imply different buttons (though not different sounds - there are duplicates) and they’re quite far away from each other.
The accident you use really depends on the context. If you're talking about chords, then you should follow the "stack of thirds" explanation that I gave above, it is how chord theory works. However, the other rules you mention also can be used depending on your situation. In a melody, you normally want to add accidents only when needed.
- Match the type of accidentals used by the key signature.
- Use sharps when the melody is moving up, and flats when it's moving down.
- Use whatever accidentals give you a visually pleasing spacing of notes in "thirds" as represented on the staff. (As advocated here.)
- Use the accidentals that are physically compatible with other notes in the chord. (Only a concern for certain instruments, but e.g. I understand that the pedals on a harp affect many strings at once, so playing a particular combination of notes may require a clever approach to the pedals, indicated by what might otherwise look like an unnatural set of accidentals. This wouldn't apply to a piano, where G# is just a separate key from G, not a modification of the G key.) I think this is what you're going for?