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();
            }
        }
        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);
            }
        }
Пример #3
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;
        }
Пример #4
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;
        }
Пример #5
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;
        }
Пример #6
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;
        }