Example #1
0
        public static Info CheckWinning(ExtendendList <Structure> lst)
        {
            // Idea: Create a structure for the first to last, then for the second to the last and ...
            // If a structure fits to the here created structure then returns the structure.
            Info toRetrun = new Info();
            // Create mainList:
            ExtendendList <Cart.cType> mainList = new ExtendendList <Cart.cType>();

            foreach (string cmr in Enum.GetNames(typeof(Class.Cart.cType)))
            {
                mainList.Add((Class.Cart.cType)Enum.Parse(typeof(Class.Cart.cType), cmr));
            }
            mainList.Reverse();
            mainList.Remove(Cart.cType.Default);

            foreach (Structure curStr in lst)
            {
                // Filter active cars.
                ExtendendList <Cart> active = new ExtendendList <Cart>();
                foreach (Cart mCart in curStr.lstCards)
                {
                    if (mCart.Active)
                    {
                        active.Add(mCart);
                    }
                }
                for (int i = 0; i <= active.Count - 1; i++)
                {
                    ExtendendList <Cart> compare = new ExtendendList <Cart>();
                    for (int j = i; j <= active.Count - 1; j++)
                    {
                        compare.Add(active[j]);
                    }
                    // Compare these lists
                    if (Structure.CompareLists(mainList, compare))
                    {
                        toRetrun.CurrentStructure = curStr;
                        Cart.GameMode currentState = Cart.GameMode.Black;

                        for (int k = 0; k <= compare.Count - 1; k++)
                        {
                            if (k == 0)
                            {
                                currentState = compare[k].GameMode_;
                            }
                            else
                            {
                                if (currentState != compare[k].GameMode_)
                                {
                                    toRetrun.OK = false;
                                    break;
                                }
                                else
                                {
                                    toRetrun.OK = true;
                                }
                            }
                        }

                        if (compare.Count > 0)
                        {
                            toRetrun.SelectedCart = compare[0];
                        }
                        return(toRetrun); // We don't go on in the loop, we want to leave here and break leaves only one loop, but there are another, so it is easier.
                    }
                }
            }
            return(toRetrun);
        }