示例#1
0
        public IList <MatchOpponents> GenerateMatches()
        {
            if (this.size <= 1)
            {
                return(null);
            }
            else if (this.size == 2)
            {
                var firstMatch = new MatchOpponents(0, 1, this.round);
                this.matches.Add(firstMatch);
                var secondMatch = new MatchOpponents(1, 0, this.round);
                this.matches.Add(secondMatch);

                return(this.matches);
            }

            int row = 0;

            if (this.hasEvenPlayers == true)
            {
                row = 1;
            }

            while (row < this.size)
            {
                this.tempMatches             = new bool[this.size, this.size];
                this.tempOpponets            = new Stack <MatchOpponents>();
                this.occupiedRowsAndCols     = new bool[this.size];
                this.hasPlayerAgainstAverage = false;
                this.hasAddedFixtureMatches  = false;
                var match = new MatchOpponents(row, 0, this.round);
                this.tempOpponets.Push(match);
                this.occupiedRowsAndCols[row] = true;
                this.occupiedRowsAndCols[0]   = true;
                this.board[row, 0]            = true;
                if (this.hasEvenPlayers == false && row == 0)
                {
                    this.hasPlayerAgainstAverage = true;
                }

                this.FindPossible(0);
                row++;
            }

            return(this.matches);
        }
示例#2
0
        private void FindPossible(int row)
        {
            if (this.hasAddedFixtureMatches || this.hasFoundAllCombinations)
            {
                return;
            }

            if (row == this.size)
            {
                this.CheckAllComminations();

                return;
            }

            int maxCol = row;

            if (this.hasEvenPlayers == true)
            {
                maxCol -= 1;
            }

            int col = 0;

            while (col <= maxCol)
            {
                if (this.tempMatches[row, col] == false && this.IsMatchAvailable(row, col))
                {
                    if (row == col)
                    {
                        this.hasPlayerAgainstAverage = true;
                    }

                    var match = new MatchOpponents(row, col, this.round);
                    this.tempOpponets.Push(match);
                    this.occupiedRowsAndCols[row] = true;
                    this.occupiedRowsAndCols[col] = true;
                    this.tempMatches[row, col]    = true;

                    if (this.tempOpponets.Count == this.tempOpponentsMaxCount)
                    {
                        this.AddTempOpponetsToFinalList();
                        this.hasAddedFixtureMatches = true;
                    }

                    this.FindPossible(row + 1);

                    if (this.hasAddedFixtureMatches || this.hasFoundAllCombinations)
                    {
                        return;
                    }

                    if (row == col)
                    {
                        this.hasPlayerAgainstAverage = false;
                    }

                    this.tempOpponets.Pop();
                    this.occupiedRowsAndCols[row] = false;
                    this.occupiedRowsAndCols[col] = false;
                    this.tempMatches[row, col]    = false;
                }

                col++;
            }

            this.FindPossible(row + 1);
        }