Пример #1
0
 public void SetPatterns(Pattern[] patterns)
 {
     this.patterns = new List <Pattern>();
     foreach (Pattern p in patterns)
     {
         this.patterns.Add(p);
     }
     pattern_list = new Pattern.PatternMasks();
     Pattern.ExpandGamePatterns(this.patterns, pattern_list);
 }
Пример #2
0
        public static bool check_pack(PlayerPack pack, int game, Pattern pattern)
        {
            int num_patterns;
            int num_cards;
            int pattern_index;
            int card_index;

            if (pattern.sub_patterns.Count < 1)
            {
                return(false);
            }

            CombinationIterator ci = ((pattern.mode_mod & Pattern.mode_modifications.OrderMatters) != 0)
                                ? null
                                : new CombinationIterator(pattern.sub_patterns.Count);
            bool iterator_done;

            List <BingoCardState> cards = pack.Cards[game];

            int cardsets = cards.Count;

            /*
             * this check should be done somewhere; maybe when cards are dealt for packs to games?
             *
             * if( cardsets % pattern.sub_patterns.Count != 0 )
             * {
             *      throw new Exception( "Pack is incompatible with pattern.  Mismatch integral card count" );
             * }
             */
            num_patterns = pattern.sub_patterns.Count;

            cardsets = cardsets / (num_patterns);
            if (cardsets > 1)
            {
                Log.log("Pattern-packsize mismatch");
            }

            int[] best_combination = null;
            //int[,] bests = new int[ cardsets, ci.GetCombinations() ];
            int combination = 0;

            if (pattern.pattern_masks == null)
            {
                pattern.pattern_masks = new List <Pattern.PatternMasks>();
                foreach (Pattern sub_pattern in pattern.sub_patterns)
                {
                    List <Pattern> tmplist = new List <Pattern>();
                    tmplist.Add(sub_pattern);
                    Pattern.PatternMasks masks = new Pattern.PatternMasks();
                    Pattern.ExpandGamePatterns(tmplist, masks);
                    pattern.pattern_masks.Add(masks);
                }
            }

            foreach (Pattern sub_pattern in pattern.sub_patterns)
            {
                int sub_pattern_index = pattern.sub_patterns.IndexOf(sub_pattern);
                foreach (BingoCardState card in cards)
                {
                    // get last marked cardmask
                    {
                        if (sub_pattern.algorithm == PatternDescriptionTable.match_types.CrazyMark)
                        {
                            return(card.CheckCrazy(card.marks[0], sub_pattern.repeat_count));
                        }
                        else if (sub_pattern.algorithm == PatternDescriptionTable.match_types.ExternalJavaEngine)
                        {
                            //return
                        }
                        else
                        {
                            List <int> patterns = pattern.pattern_masks[sub_pattern_index].pattern_bitmask_list;
                            {
                                if (card.CheckPattern(card.marks[sub_pattern_index], patterns))
                                {
                                    //card.WinningGame = game;
                                    //card.WinningGameEvent = game_event;
                                    //return true;
                                }
                            }                             // end of foreach( pattern )
                        }
                    }
                }
            }

            int cardset;
            int best_away       = 75;
            int worst_card_away = 75;
            int best_cardset;

            for (cardset = 0; cardset < cardsets; cardset++)
            {
                iterator_done = false;
                while (!iterator_done)
                {
                    int[] this_order;
                    if (ci == null)
                    {
                        iterator_done = true;
                        this_order    = new int[pattern.sub_patterns.Count];
                        for (int n = 0; n < pattern.sub_patterns.Count; n++)
                        {
                            this_order[n] = n;
                        }
                    }
                    else
                    {
                        iterator_done = ci.IterateCombination(out this_order);
                    }
                    int total_away  = 0;
                    int card_offset = 0;
                    foreach (int index in this_order)
                    {
                        int card_away = cards[cardset * num_patterns + card_offset].BestAway(index);
                        if (card_away < 24 && card_away < worst_card_away)
                        {
                            worst_card_away = card_away;
                        }
                        total_away += card_away;
                        card_offset++;
                    }
                    if (total_away < best_away)
                    {
                        best_away        = total_away;
                        best_combination = (int[])this_order.Clone();
                        best_cardset     = cardset;
                    }
                    //bests[cardset, combination] = total_away;
                }
                combination++;
            }
            if (best_away > 0 && worst_card_away == 0)
            {
                worst_card_away = 1;
            }
            pack.state = pack.state ?? new List <BingoPackState>();
            if (pack.state.Count <= game)
            {
                pack.state.Add(new BingoPackState());
            }
            pack.state[game].best_away      = best_away;
            pack.state[game].best_card_away = worst_card_away;
            pack.state[game].combination    = best_combination;
            pack.state[game].group_size     = pattern.sub_patterns.Count;
            if (pack.state[game].best_away == 0)
            {
                return(true);
            }
            return(false);
        }