Example #1
0
        public MatchDependency FromDTO(MatchDependencyDTO dto)
        {
            var matchDependency = new MatchDependency()
            {
                Id            = dto.Id,
                DependencyId  = dto.DependencyId,
                DependsOnDraw = dto.DependsOnDraw,
                Position      = dto.Position
            };

            return(matchDependency);
        }
Example #2
0
        public MatchDependencyDTO ToDTO(MatchDependency matchDependency)
        {
            var dto = new MatchDependencyDTO()
            {
                Id            = matchDependency.Id,
                DependencyId  = matchDependency.DependencyId,
                DependsOnDraw = matchDependency.DependsOnDraw,
                Position      = matchDependency.Position
            };

            return(dto);
        }
Example #3
0
        private int FindResultingPlayerFromMatchDependency(MatchDependency matchDependency)
        {
            var match          = _matchRepository.FindById(matchDependency.DependencyId);
            var wantedPosition = matchDependency.Position;

            if ((match.P1Won && wantedPosition == 1) || (!match.P1Won && wantedPosition == 2))
            {
                return(match.P1Id);
            }
            else
            {
                return(match.P2Id);
            }
        }
Example #4
0
        private static Match initMatch(Draw draw, MatchDependency p1Dependency, MatchDependency p2Dependency, int p1Id, int p2Id, Status status, int round, DrawCreation drawCreation)
        {
            var match = new Match()
            {
                Draw           = draw,
                DrawId         = draw.Id,
                P1DependencyId = p1Dependency == null ? 0: p1Dependency.Id,
                P2DependencyId = p2Dependency == null ? 0: p2Dependency.Id,
                P1Id           = p1Id,
                P2Id           = p2Id,
                Status         = status,
                round          = round,
                P1Games        = 0,
                P2Games        = 0,
                P1PointsArray  = drawCreation.InitPoints(),
                P2PointsArray  = drawCreation.InitPoints()
            };

            return(match);
        }
Example #5
0
 public MatchDependency Update(MatchDependency matchDependency)
 {
     _matchDependencyRepository.Update(matchDependency);
     _dbContext.SaveChanges();
     return(matchDependency);
 }
Example #6
0
 public MatchDependency Create(MatchDependency matchDependency)
 {
     _matchDependencyRepository.Insert(matchDependency);
     _dbContext.SaveChanges();
     return(matchDependency);
 }
Example #7
0
        private static void ConfigureKO(Draw draw, DrawCreation drawCreation, IMatchRepository matchRepository, IMatchDependencyRepository matchDependencyRepository)
        {
            var matches = new List <Match>();

            //Configure seeding
            var seededPlayerIds = GetSeededPlayerIds(drawCreation.playerIds.ToList(), drawCreation.playerIdsSeeded);

            while (!IsPowerOf2(seededPlayerIds.Count))
            {
                //Add byes so playerIds is power of 2
                seededPlayerIds.Add(-1);
            }

            int lastRound = Math.ILogB(seededPlayerIds.Count);
            int roundSize = seededPlayerIds.Count / 2;

            //Configure first round manually - no match dependencies - matches are open
            //Byes should be paired with top-seeded players in first round
            var opponents = seededPlayerIds.Skip(seededPlayerIds.Count / 2).ToList();

            opponents = BringByesToFront(Randomize(opponents));


            for (int i = 0; i < roundSize; i++)
            {
                //Init first round match
                var match = initMatch(draw, null, null, seededPlayerIds[i], opponents[0], Status.OPEN, 1, drawCreation);

                //Remove that opponent
                opponents.Remove(opponents[0]);
                matchRepository.Insert(match); //Insert in database to get an id
                matches.Add(match);
            }


            //Configure next rounds with match dependencies
            for (var round = 2; round <= lastRound; round++)
            {
                //Update roundSize: In round i, there are half as many mathces as in i-1
                var oldRoundSize = roundSize;
                roundSize = oldRoundSize / 2;


                //Matches from last round - this is where the dependencies will come from
                var lastRoundMatchIds = matches.Skip(matches.Count - oldRoundSize).Select(m => m.Id).ToList();

                //Last half of the lastRoundMatches ==> the ones that are "unseeded" in this round
                var opponentMatchIds = lastRoundMatchIds.Skip(oldRoundSize / 2).ToList();
                opponentMatchIds = Randomize(opponentMatchIds);

                //Add roundsize new matches for this round
                for (int i = 0; i < roundSize; i++)
                {
                    //Create the matchDependencies
                    var p1Dependency = new MatchDependency()
                    {
                        DependencyId  = lastRoundMatchIds[i], //Player 1 will come from match with higher seeded player
                        DependsOnDraw = false,
                        Position      = 1
                    };
                    matchDependencyRepository.Insert(p1Dependency);
                    var p2Dependency = new MatchDependency()
                    {
                        DependencyId  = opponentMatchIds[0], //Player 2 will be selected at random from opponents
                        DependsOnDraw = false,
                        Position      = 1
                    };
                    matchDependencyRepository.Insert(p2Dependency);


                    var match = initMatch(draw, p1Dependency, p2Dependency, 0, 0, Status.CLOSED, round, drawCreation);

                    //Remove the selected opponent-match-id
                    opponentMatchIds.Remove(opponentMatchIds[0]);
                    matchRepository.Insert(match); //Insert in database to get an id
                    matches.Add(match);
                }
            }

            draw.Matches = matches;
        }
Example #8
0
 public void Update(MatchDependency matchDependency)
 {
     _dbSet.Update(matchDependency);
 }
Example #9
0
 public void Delete(MatchDependency matchDependency)
 {
     _dbSet.Remove(matchDependency);
 }
Example #10
0
 public void Insert(MatchDependency matchDependency)
 {
     _dbSet.Add(matchDependency);
 }