The same chords played on guitar and piano will sound the same or very similar and contain mostly the same notes. If you can already play piano and know the chords the jump to understanding guitar chords should be relatively simple.

Your ears should tell you when chords have to change to suit the melody and if the chords are the right fit.
There are many diff ways to use chords to fit a given melody..... what chords we choose and how we get from one to another is what melody writing is all about. The rules are simple if it sounds good then use it if not try a diff chord or change the melody to fit.