'How do I create hints for my sorting game

I am currently working on a sorting game. The game mechanics is complete. Now as I am working on the additional features, I am stuck on creating hints for the player. I found one algorithm created in CPP, but that only works on in the tubes are all full and have a extra empty tube along side them.

Currently what I am doing, is comparing the top item of the tubes and if they meet each other the tubes gets highlighted. This approach is also not suitable because there are some scenarios that it will get stuck in between two tubes sometimes and give the same hint again and again.

public void GetHint()
{

    #region Current Hint System
    for (int i = 0; i < _holders.Count; i++)
    {
        for (int j = 0; j < _holders.Count; j++)
        {
            if (i == j) continue;

            if ((_holders[i]._liquids.Last()._renderer.color == _holders[j]._liquids.Last()._renderer.color) && (!_holders[j].IsFull))
            {
                Debug.Log("HINT AVAILABLE");
                Debug.Log($"PREVIOUS: {i}");
                Debug.Log($"NEXT: {j}");
                _holders[i].top_fromHolder.SetActive(true);
                _holders[j].bottom_toHolder.SetActive(true);

                goto LoopEnd;
            }
        }

    }

LoopEnd:
    Debug.Log("Finished with finding a hint.");

    #endregion

}

Also I am unable to figure out how to handle the use case when the player have an extra empty tube in the game. enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source