How's Ralph's hiding place discovered and how's he saved at the last possible moment? When the naval officer looks at the boys, what does he see?
The part you are talking about is in Chapter 12.
Ralph's hiding place is discovered because Samneric have joined Jack's tribe. They know where Ralph is because he told them the night before. They were not going to tell, but now they are being tortured and they are unable to keep from telling.
When Samneric tell, Ralph is cornered and starts to fight back. Just when things seem hopeless, the boys are distracted by someone shouting "smoke." At that point, Ralph runs away.
When the naval officer first looks at the boys, he thinks they have been having a fun time. He thinks they have been playing, maybe playing war.