I think I have encountered something like this. First you need to enlist what color (probably animation frame) are exist in current active stage. Put the list array for easier indexing access to their value. Then you can compare each color count through a loop checking.