Count the copies that are accounted for
Start with green tiles. Those positions are already occupied in the answer. Yellow tiles point to additional letters elsewhere, but only up to the number of copies actually available.
If your guess contains a letter twice and the answer has it once, you can get one colored tile and one gray tile for the same letter. The gray tile helps you rule out an extra copy.
Walk through a concrete example
Suppose your guess is APPLE and the answer is AMPLE. The A, L and E match positions. The second P in APPLE lands on the answer’s P and goes green. The earlier P is gray because there is no unused P to mark.
Writing P in a general excluded-letters field would remove the real answer. Storing both tiles in the guess row preserves the difference between one copy and none.
Use the count on your next turn
If you have one confirmed P and one gray duplicate, test candidates with exactly one P before trying a word with two. A single yellow P in a guess with only one P does not settle whether the answer has another copy.
Worked example
APPLE against AMPLE
The feedback is correct, absent, correct, correct, correct. The two P positions produce different states because only one P exists in the answer.