Exemple #1
0
    private void Start()
    {
        var cardBatch = new CardBatch
        {
            new Card(CardNo.Ace, CardType.Spades),
            new Card(CardNo.Two, CardType.Spades),
            new Card(CardNo.Three, CardType.Spades),
            new Card(CardNo.Four, CardType.Spades),
            new Card(CardNo.Three, CardType.Diamonds),
            new Card(CardNo.Four, CardType.Diamonds),
            new Card(CardNo.Five, CardType.Diamonds),
            new Card(CardNo.Ace, CardType.Diamonds),
            new Card(CardNo.Ace, CardType.Hearts),
            new Card(CardNo.Four, CardType.Hearts),
            new Card(CardNo.Four, CardType.Clubs)
        };

        var grouping = GroupingAlgorithms.GetSmartGroups(cardBatch);
        var builder  = new StringBuilder();
        var i        = 0;

        foreach (var group in grouping.Groups)
        {
            i++;
            builder.AppendLine("Group " + i + ":");
            foreach (var card in group)
            {
                builder.AppendLine(card.ToString());
            }
            builder.AppendLine();
        }
        builder.AppendLine("Ungrouped Cards:");
        foreach (var card in grouping.Ungrouped)
        {
            builder.AppendLine(card.ToString());
        }
        Debug.Log(builder.ToString());
    }
        public void SmartGroups()
        {
            var batch    = GenerateTestCase();
            var result   = GroupingAlgorithms.GetSmartGroups(batch);
            var expected = new CardGrouping
            {
                Groups =
                {
                    new List <Card>
                    {
                        new Card(CardNo.Ace, CardType.Spades),
                        new Card(CardNo.Two, CardType.Spades),
                        new Card(CardNo.Three, CardType.Spades)
                    },
                    new List <Card>
                    {
                        new Card(CardNo.Four, CardType.Spades),
                        new Card(CardNo.Four, CardType.Hearts),
                        new Card(CardNo.Four, CardType.Clubs)
                    },
                    new List <Card>
                    {
                        new Card(CardNo.Three, CardType.Diamonds),
                        new Card(CardNo.Four, CardType.Diamonds),
                        new Card(CardNo.Five, CardType.Diamonds)
                    }
                },
                Ungrouped =
                {
                    new Card(CardNo.Ace, CardType.Diamonds),
                    new Card(CardNo.Ace, CardType.Hearts)
                }
            };

            Assert.True(result.Groups.IsEquivalent(expected.Groups, false));
            Assert.True(result.Ungrouped.IsEquivalent(expected.Ungrouped));
        }
Exemple #3
0
 /// <summary>
 /// Sorts the batch by smart grouping.
 /// </summary>
 public void SortBySmartGrouping()
 {
     _cards = GroupingAlgorithms.GetSmartGroups(_cards).ToFlatList();
     OnChange?.Invoke();
 }