if the pieces start out next to eachother, you could check for adjaceceny when one is moved, if it is no longer adjacent, then move back to original position.
but if the pieces become scattered or dont start next to eachother, you would have to do a union tree or a flood fill, to check them all.
make a fill Type, each only has a position on the grid
start on any piece, by placeing a fill spot there
check all tiles within adjacency radius of the fill spot, if there is a piece on any of those tiles, with a piece \checked=false then set that piece's\checked=true and place a fill spot on that piece.
delete the origional fill spot when you check all its adjacent tiles
for each fill spot do that same thing until theres no more fill spots
youre done. you can go through each piece and if it's \checked is false then it is unconnected
but if the pieces become scattered or dont start next to eachother, you would have to do a union tree or a flood fill, to check them all.
make a fill Type, each only has a position on the grid
start on any piece, by placeing a fill spot there
check all tiles within adjacency radius of the fill spot, if there is a piece on any of those tiles, with a piece \checked=false then set that piece's\checked=true and place a fill spot on that piece.
delete the origional fill spot when you check all its adjacent tiles
for each fill spot do that same thing until theres no more fill spots
youre done. you can go through each piece and if it's \checked is false then it is unconnected