Ejemplo n.º 1
0
        public static ArchetypeResult Detect(Card[] mainboardCards, Card[] sideboardCards, ArchetypeFormat format, double minSimiliarity = 0.1)
        {
            Archetype[] archetypeData = format.Archetypes;
            Dictionary <string, ArchetypeColor> landColors = format.Lands;
            Dictionary <string, ArchetypeColor> cardColors = format.NonLands;

            ArchetypeSpecific[] specificArchetypes = archetypeData.Where(a => a is ArchetypeSpecific && !(a is ArchetypeVariant)).Select(a => a as ArchetypeSpecific).ToArray();
            ArchetypeGeneric[]  genericArchetypes  = archetypeData.Where(a => a is ArchetypeGeneric).Select(a => a as ArchetypeGeneric).ToArray();

            ArchetypeCompanion?companion = GetCompanion(mainboardCards, sideboardCards);
            ArchetypeColor     color     = GetColors(mainboardCards, sideboardCards, landColors, cardColors);

            List <ArchetypeMatch> results = new List <ArchetypeMatch>();

            foreach (ArchetypeSpecific archetype in specificArchetypes)
            {
                if (Test(mainboardCards, sideboardCards, color, archetype))
                {
                    bool isVariant = false;
                    if (archetype.Variants != null)
                    {
                        foreach (ArchetypeSpecific variant in archetype.Variants)
                        {
                            if (Test(mainboardCards, sideboardCards, color, variant))
                            {
                                isVariant = true;
                                results.Add(new ArchetypeMatch()
                                {
                                    Archetype = archetype, Variant = variant, Similarity = 1
                                });
                            }
                        }
                    }
                    if (!isVariant)
                    {
                        results.Add(new ArchetypeMatch()
                        {
                            Archetype = archetype, Variant = null, Similarity = 1
                        });
                    }
                }
            }

            if (results.Count == 0)
            {
                ArchetypeMatch genericArchetype = GetBestGenericArchetype(mainboardCards, sideboardCards, color, genericArchetypes);
                if (genericArchetype != null && genericArchetype.Similarity > minSimiliarity)
                {
                    results.Add(genericArchetype);
                }
            }

            return(new ArchetypeResult()
            {
                Matches = results.ToArray(), Color = color, Companion = companion
            });
        }
Ejemplo n.º 2
0
        private static string GetArchetype(ArchetypeMatch match, ArchetypeColor color)
        {
            string result = match.Archetype.GetName(color);

            if (match.Variant != null)
            {
                result = match.Variant.GetName(color);
            }
            return(result);
        }