Example #1
0
        public void BindLimitation(Limitation s)
        {
            _limitation = s;
            LoadData(0,0);
            UpdateButtons();
            UpdateRaceNumbers();
            UpdateMatchingListView();

            if (!(_limitation is FullSystem))
            {
                _limitation.Parent = this;
            }
        }
Example #2
0
        public void Add(Limitation limitation)
        {
            if(null == SelectedRaceCard || null == limitation)
                return;

            int valueWeightTotal = GetTotalValue(limitation);
            int weightTotal = GetTotalWeight(limitation);

            if(!_value.ContainsKey(valueWeightTotal))
            {
                _value.Add(valueWeightTotal,0);
            }

            if(!_weight.ContainsKey(weightTotal))
            {
                _weight.Add(weightTotal,0);
            }

            _value[valueWeightTotal]++;
            _weight[weightTotal]++;
        }
Example #3
0
 public int GetTotalWeight(Limitation limitation)
 {
     if(null == SelectedRaceCard || null == limitation)
         return 0;
     int fromRace = limitation.FirstRace;
     int toRace = fromRace + limitation.Count()-1;
     int weightTotal = 0;
     for(int rn = fromRace, i=0; rn <= toRace; ++rn, ++i)
     {
         var race = SelectedRaceCard.GetRace(rn);
         if(null != race)
         {
             var horse = race.GetHorse(limitation.Selections[i]);
             if(null != horse)
             {
                 weightTotal += horse.WeightIndex;
             }
         }
     }
     return weightTotal;
 }
Example #4
0
        private void CompressMetablito(int index, int matching_index)
        {
            var theNewObj = new Limitation(NumberOfRaces, FirstRace);

            theNewObj = _metablito[index].CreateCopy();

            for (int i = index + 1; i < _metablito.Count; ++i)
            {
                int m = _metablito[i].CountIdenticalSelections(_metablito[index]);

                if (m != NumberOfRaces - 1)
                {
                    continue;
                }

                if (_metablito[i].GetRaceSelection(matching_index).IsIdentical(_metablito[index].GetRaceSelection(matching_index)))
                {
                    continue;
                }
                else
                {
                    theNewObj.GetRaceSelection(matching_index).Merge(_metablito[i].GetRaceSelection(matching_index));
                    _metablito.RemoveAt(i);
                    --i;
                }
            }

            _metablito[index] = theNewObj;
        }
Example #5
0
        public List<Limitation> ShowAllMatchesForSpecificCombination(Limitation combination)
        {
            // We need raw combintations so let's ensure that the system is
            // developed without any compression

            CountCombinations();

            var matchingCombination = new List<Limitation>();

            combination.MaxMatches = combination.CountSkippingZeros();
            combination.MinMatches = combination.CountSkippingZeros();

            foreach (Limitation systemCombination in _developedSystem)
            {
                if (combination.IsMatching(systemCombination))
                {
                    matchingCombination.Add(systemCombination);
                }
            }

            return matchingCombination;
        }
Example #6
0
        // Used to retrive the winning ticket's index, if any, for a specific
        // combination.  If the system does not contain a winning ticket
        // returns -1
        public int GetWinningTicket(Limitation combination)
        {
            // We need the number of the winning ticket, so let's ensure
            // that the system is already compressed

            Develop();

            int m = 0;

            combination.MaxMatches = combination.Count();
            combination.MinMatches = combination.Count();

            int index = -1;
            foreach (Limitation systemCombination in _developedSystem)
            {
                ++index;

                if (combination.IsMatching(systemCombination))
                {
                    return index + 1;
                }
            }

            return m;
        }
Example #7
0
 public void CopyLimitation(int groupIndex, int limitationIndex, Limitation toBeCopied)
 {
     Limitation newLimitation = toBeCopied.CreateDeepCopy();
     _group[groupIndex].SetLimitation(limitationIndex, newLimitation);
     _needsToBeSaved = true;
     _needsToBeCounted = true;
 }
Example #8
0
 public void CopyLimitation(int groupIndex, int limitationIndex, Limitation toBeCopied)
 {
     _fullSystem.CopyLimitation(groupIndex, limitationIndex, toBeCopied);
     RefreshObservers(groupIndex);
 }
        private void OnShowAllMatches(object sender, EventArgs e)
        {
            try
            {
                _matchesTextBox.Text = "";

                Limitation winningCombination = new Limitation(_fullSystem.NumberOfRaces, _fullSystem.FirstRace);
                for (int i = 0; i < _fullSystem.NumberOfRaces; ++i)
                {
                    int horseNumber = Convert.ToInt32(_winningComboGrid[0, i].Value.ToString());

                    winningCombination.GetRaceSelection(i).AddHorse(horseNumber);
                    winningCombination.GetRaceSelection(i).ToggleSelectionForHorse(horseNumber);
                }

                Cursor = Cursors.WaitCursor;

                List<Limitation> lim = _fullSystem.ShowAllMatchesForSpecificCombination(winningCombination);

                // For performance reasons load the limitations to a dataset and then
                // assign it to the grid.  Painting the grid by hand is tooooo slow (dont now exacly why)
                _grid.DataSource = GetMatchingCombinationsAsADataSet(lim).Tables[0];

                _tbMatchesCount.Text = lim.Count.ToString();

                Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #10
0
        // Maybe the following two methods can be one
        public Limitation CreateDeepCopy()
        {
            Limitation newObject = new Limitation(NumberOfRaces, _firstRace);

            newObject.CloneDeeplyValues(this);

            return newObject;
        }
Example #11
0
 public void SetLimitation(int limitationIndex, Limitation limitation)
 {
     _limitation[limitationIndex] = limitation;
 }
Example #12
0
 private void OnCopy(object sender, EventArgs e)
 {
     RaceInput._clipedLimitation = _limitation.CreateDeepCopy();
 }
Example #13
0
        public bool IsMatchingAllTheLimitations(Limitation limitation)
        {
            for (int i = 0; i < _limitation.Count; ++i)
            {
                if (((Limitation)_limitation[i]).Enabled)
                {

                    if (((Limitation)_limitation[i]).IsMatching(limitation) == false)
                    {
                        return false;
                    }
                }
            }

            return true;
        }
Example #14
0
        public int AddLimitation()
        {
            Limitation limitation = new Limitation(_parent.NumberOfRaces,_parent.FirstRace);

            limitation.CloneValues(_parent);
            return _limitation.Add(limitation);
        }
Example #15
0
        public bool IsMatching(Limitation other)
        {
            if (this.Count() != other.Count())
            {
                return false;
            }

            int count = 0;

            for (int i = 0; i < Count(); ++i)
            {
                if (((RaceSelection)_selection[i]).IsMatching(other.GetRaceSelection(i)))
                {
                    ++count;
                }
            }

            return count >= _minMatches && count <= _maxMatches;
        }
Example #16
0
        private int CountCombinations4()
        {
            ClearDevelopedSystem();

            int count = 0;
            int[] i = new int[4];

            for (i[0] = 0; i[0] < ((RaceSelection) _selection[0]).Count; ++i[0])
            {
                for (i[1] = 0; i[1] < ((RaceSelection) _selection[1]).Count; ++i[1])
                {
                    for (i[2] = 0; i[2] < ((RaceSelection) _selection[2]).Count; ++i[2])
                    {
                        for (i[3] = 0; i[3] < ((RaceSelection) _selection[3]).Count; ++i[3])
                        {
                            var limitation = new Limitation(4, FirstRace);

                            limitation.AddHorse(0, ((RaceSelection) _selection[0]).Get(i[0]));
                            limitation.AddHorse(1, ((RaceSelection) _selection[1]).Get(i[1]));
                            limitation.AddHorse(2, ((RaceSelection) _selection[2]).Get(i[2]));
                            limitation.AddHorse(3, ((RaceSelection) _selection[3]).Get(i[3]));

                            _weightStatisticsForTheFullSystem.Add(limitation);

                            int countPassingGroups = 0;

                            for (int k = 0; k < _group.Count; ++k)
                            {
                                if (_group[k].IsMatchingAllTheLimitations(limitation) == true)
                                {
                                    ++countPassingGroups;
                                }
                            }

                            bool isPassingWeights = true;

                            int value = _weightStatisticsForTheFullSystem.GetTotalValue(limitation);
                            int weight = _weightStatisticsForTheFullSystem.GetTotalWeight(limitation);

                            if (value > 0 && _valueWeightLimitationForTheFullSystem.ContainsWeight(value))
                            {
                                isPassingWeights = false;
                            }

                            if (weight > 0 && _weightWeightLimitationForTheFullSystem.ContainsWeight(weight))
                            {
                                isPassingWeights = false;
                            }

                            if (countPassingGroups >= _minNumberOfMatchingGroups &&
                                countPassingGroups <= _maxNumberOfMatchingGroups &&
                                isPassingWeights)
                            {
                                ++count;
                                _developedSystem.Add(limitation);
                                _weightStatisticsForTheDevelopedSystem.Add(limitation);
                            }
                        }
                    }
                }
            }

            return _developedSystem.Count;
        }
Example #17
0
        public void CloneValues(Limitation other)
        {
            Debug.Assert(NumberOfRaces == other.NumberOfRaces);

            _firstRace = other._firstRace;
            for (int i = 0; i < NumberOfRaces; ++i)
            {
                RaceSelection ors = other.GetRaceSelection(i);

                RaceSelection rs = new RaceSelection();

                for (int j = 0; j < ors.Count; ++j)
                {
                    rs.AddHorse(ors.Get(j));
                }

                _selection[i] = rs;
            }

            _minMatches = 0;
            _maxMatches = NumberOfRaces;
        }
Example #18
0
        private int CountCombinations5()
        {
            ClearDevelopedSystem();
            int count = 0;

            int[] i = new int[5];

            for (i[0] = 0; i[0] < ((RaceSelection) _selection[0]).Count; ++i[0])
            {
                for (i[1] = 0; i[1] < ((RaceSelection) _selection[1]).Count; ++i[1])
                {
                    for (i[2] = 0; i[2] < ((RaceSelection) _selection[2]).Count; ++i[2])
                    {
                        for (i[3] = 0; i[3] < ((RaceSelection) _selection[3]).Count; ++i[3])
                        {
                            for (i[4] = 0; i[4] < ((RaceSelection) _selection[4]).Count; ++i[4])
                            {
                                Limitation limitation = new Limitation(5, FirstRace);

                                limitation.AddHorse(0, ((RaceSelection) _selection[0]).Get(i[0]));
                                limitation.AddHorse(1, ((RaceSelection) _selection[1]).Get(i[1]));
                                limitation.AddHorse(2, ((RaceSelection) _selection[2]).Get(i[2]));
                                limitation.AddHorse(3, ((RaceSelection) _selection[3]).Get(i[3]));
                                limitation.AddHorse(4, ((RaceSelection) _selection[4]).Get(i[4]));
                                _weightStatisticsForTheFullSystem.Add(limitation);
                                int countPassingGroups = 0;

                                for (int k = 0; k < _group.Count; ++k)
                                {
                                    if (((LimitationGroup) _group[k]).IsMatchingAllTheLimitations(limitation) == true)
                                    {
                                        ++countPassingGroups;
                                    }
                                }

                                if (countPassingGroups >= _minNumberOfMatchingGroups &&
                                    countPassingGroups <= _maxNumberOfMatchingGroups)
                                {
                                    ++count;
                                    _developedSystem.Add(limitation);
                                    _weightStatisticsForTheDevelopedSystem.Add(limitation);
                                }
                            }
                        }
                    }
                }
            }

            return _developedSystem.Count;
        }
Example #19
0
        public int CountMatches(Limitation other)
        {
            if (NumberOfRaces != other.NumberOfRaces)
            {
                return -1;
            }

            int count = 0;

            for (int i = 0; i < NumberOfRaces; ++i)
            {
                if (((RaceSelection)_selection[i]).IsMatching((RaceSelection)other._selection[i]))
                {
                    ++count;
                }
            }

            return count;
        }
        private void OnSelectWinners(object sender, EventArgs e)
        {
            _grid.DataSource = null;
            _tbMatchesCount.Text = "";

            Limitation winningCombination = new Limitation(_fullSystem.NumberOfRaces, _fullSystem.FirstRace);

            for (int i = 0; i < _fullSystem.NumberOfRaces; ++i)
            {
                int horseNumber = Convert.ToInt32(_winningComboGrid[0, i].Value.ToString());

                winningCombination.GetRaceSelection(i).AddHorse(horseNumber);
                winningCombination.GetRaceSelection(i).ToggleSelectionForHorse(horseNumber);
            }

            int winningTicketIndex = _fullSystem.GetWinningTicket(winningCombination);

            if (winningTicketIndex <= 0)
            {
                _matchesTextBox.Text = "Not a winner";
            }
            else
            {
                _matchesTextBox.Text = "Winning ticket # " + winningTicketIndex.ToString();
            }
        }
Example #21
0
        public void CloneDeeplyValues(Limitation other)
        {
            Debug.Assert(NumberOfRaces == other.NumberOfRaces);

            _firstRace = other._firstRace;

            for (int i = 0; i < NumberOfRaces; ++i)
            {
                RaceSelection ors = other.GetRaceSelection(i);
                _selection[i] = ors.MakeDeepCopy();
            }

            _minMatches = other._minMatches;
            _maxMatches = other._maxMatches;
        }