示例#1
0
        public CardCombine Combine(CombineMethod method = CombineMethod.SMART)
        {
            // min combine group count 1;
            // min combine group count 5;
            Debug.Log("> Combining : " + method);

            List <CardGroup> groups = null;

            switch (method)
            {
            case CombineMethod.COMBINE123:
                groups = Group123(Sort());
                break;

            case CombineMethod.COMBINE777:
                groups = Group777(Sort());
                break;

            case CombineMethod.SMART:
                groups = Group(Sort());
                break;
            }


            CardCombine bestCombine = new CardCombine();


            int debug_iteration            = 0; //debug
            int debug_iteration_validation = 0; //debug

            for (int i = 1; i < 6; i++)
            {
                foreach (IEnumerable <CardGroup> combine in Combiner.Combinations(groups, i))
                {
                    int count = combine.Sum((group) => group.members.Count);
                    debug_iteration++;//debug
                    if (count > bestCombine.CardCount)
                    {
                        HashSet <int> slotIDs = new HashSet <int>();
                        bool          valid   = combine.All((group) => group.members.All((card) => slotIDs.Add(card.slot)));
                        debug_iteration_validation++;//debug
                        if (valid)
                        {
                            bestCombine.members = combine.ToList();
                        }
                    }
                }
            }

            Debug.Log("Iteration Count :" + debug_iteration);
            Debug.Log("Validation Iteration Count :" + debug_iteration_validation);

            return(bestCombine);
        }
示例#2
0
        public void DistrubutionTest()
        {
            Table table = new Table();

            Assert.Greater(table.decks.Length, 0);
            table.Distribute();
            foreach (Deck deck in table.decks)
            {
                int count = 0;
                for (int i = 0; i < deck.slots.Length; i++)
                {
                    if (deck.slots[i] != null)
                    {
                        count++;
                        Debug.Log(deck.slots[i].ToString());
                    }
                }
                Assert.AreEqual(count, 14);
                Debug.Log("Okey is :");
                Debug.Log(table.okey);
                Assert.AreNotEqual(table.okey, null);

                CardCombine bestCombine = deck.Combine();

                Debug.Log("# Best Combine " + bestCombine.CardCount);

                bestCombine.members.ForEach((group) =>
                {
                    Debug.Log("=== ");

                    group.members.ForEach((m) =>
                    {
                        Debug.Log("- " + m.card.ToString());
                    });
                });
            }
        }
示例#3
0
        public void CombineTest2()
        {
            Table table = new Table();

            table.decks[0].AddCard(table.GetCard(Card.GetID(Card.ColorType.YELLOW, 4)));
            table.decks[0].AddCard(table.GetCard(Card.GetID(Card.ColorType.YELLOW, 5)));
            table.decks[0].AddCard(table.GetCard(Card.GetID(Card.ColorType.YELLOW, 6)));
            table.decks[0].AddCard(table.GetCard(Card.GetID(Card.ColorType.YELLOW, 4, 1)));
            table.decks[0].AddCard(table.GetCard(Card.GetID(Card.ColorType.YELLOW, 10)));
            table.decks[0].AddCard(table.GetCard(Card.GetID(Card.ColorType.BLUE, 10)));
            table.decks[0].AddCard(table.GetCard(Card.GetID(Card.ColorType.BLUE, 11)));
            table.decks[0].AddCard(table.GetCard(Card.GetID(Card.ColorType.BLUE, 12)));
            table.decks[0].AddCard(table.GetCard(Card.GetID(Card.ColorType.RED, 1)));
            table.decks[0].AddCard(table.GetCard(Card.GetID(Card.ColorType.BLUE, 3)));
            table.decks[0].AddCard(table.GetCard(Card.GetID(Card.ColorType.RED, 5)));
            table.decks[0].AddCard(table.GetCard(Card.GetID(Card.ColorType.BLUE, 11, 1)));
            table.decks[0].AddCard(table.GetCard(Card.GetID(Card.ColorType.BLACK, 1)));
            table.decks[0].AddCard(table.GetCard(Card.GetID(Card.ColorType.YELLOW, 9)));

            table.okey = table.GetCard(Card.GetID(Card.ColorType.RED, 10));

            CardCombine bestCombine = table.decks[0].Combine();

            Debug.Log("# Best Combine " + bestCombine.CardCount);

            bestCombine.members.ForEach((group) =>
            {
                Debug.Log("=== ");

                group.members.ForEach((m) =>
                {
                    Debug.Log("- " + m.card.ToString());
                });
            });

            // Assert.True(bestCombine.CardCount == 11);
        }