public Competition CreateCompetition(int nbTeam)
 {
     var competition = new Competition("debug", false, 0, 0, 0);
     for (int i = 0; i < nbTeam; i++)
     {
         competition.AddTeam(new Team("team-" + i, false, i + 1));
     }
     return competition;
 }
 public void AddTeam(Competition competition, Team team)
 {
     if (competition.IsLocked)
     {
         throw new CannotAddTeamInLockedCompetition();
     }
     competition.AddTeam(team);
     _competitionRepo.Save(competition);
 }
Esempio n. 3
0
        public void RefundTeam(Competition competition, Result result)
        {
            competition.Pot -= competition.BetByTeam;
            if (competition.Pot < 0)
            {
                throw new PotCannotBeNegatifException();
            }

            result.TeamWin.Gain += competition.BetByTeam;
            result.GainProcessed = true;
            _teamService.Save(result.TeamWin);
            _resultRepo.Save(result);
            _competitionRepo.Save(competition);
        }
Esempio n. 4
0
        public void AttributeGain(Competition competition, Result result)
        {
            if (result.TeamWin.WinInARow == 2)
            {
                RefundTeam(competition, result);
            }

            if (competition.AllCompetitorHavePlayedTwoTime && Math.Abs(competition.DynamicPot - 0) < 0.01)
            {
                competition.DynamicPot = competition.Pot;
                _competitionRepo.Save(competition);
            }

            RewardWinnerTeam(competition, result);
        }
Esempio n. 5
0
        public Node GetTree(Competition competition)
        {
            var tmpTeams = new List<Team>();
            tmpTeams.AddRange(competition.InitialTeams);
            var nbTeamInFirstLevel = CalculateNbTeamInFirstLevel(competition.InitialTeams.Count(), competition.Depth);
            var listTeamInFirstLevel = new List<Team>();

            for (int i = 0; i < nbTeamInFirstLevel; i++)
            {
                listTeamInFirstLevel.Add(PickATeam(tmpTeams));
            }

            var nodeTree = CreateNode(listTeamInFirstLevel, tmpTeams, competition, null, 0, competition.Depth - 1);
            AutoPlayForMissingTeam(nodeTree);
            return ApplyResultOnCompetition(competition, nodeTree);
        }
Esempio n. 6
0
        /// <summary>
        /// Avalaible only for team refund
        /// </summary>
        public void RewardWinnerTeam(Competition competition, Result result)
        {
            if (competition.DynamicPot <= 0.01 && result.DepthOfTheGame < competition.Depth - 2) return;

            competition.Pot -= competition.PriceForEachGame;
            if (competition.Pot < 0)
            {
                throw new PotCannotBeNegatifException();
            }

            result.TeamWin.Gain += competition.PriceForEachGame;
            result.GainProcessed = true;
            _teamService.Save(result.TeamWin);
            _resultRepo.Save(result);
            _competitionRepo.Save(competition);
        }
        public void AddResult(Competition competition, Team team)
        {
            var rootNode = _nodeService.GetTree(competition);
            var result = _nodeService.CreateResult(rootNode, team);

            if (!competition.IsCryingCompetion)
            {
                if (team.CanSendToCryingCompetetion)
                {
                    var cryingCompetition = GetCryingCompetition(competition);

                    if (result.TeamLoose != null)
                    {
                        AddTeamInCryingCompetition(cryingCompetition, result.TeamLoose);
                    }

                    Save(cryingCompetition);
                }
            }

            competition.Results.Add(result);
            _priceService.AttributeGain(competition, result);
            Save(competition);
        }
 private void PopulateCryingCompetition(Competition competition)
 {
     if (competition.IsCryingCompetion && !competition.InitialTeams.Any())
     {
         var mainCompetition = GetMainCompetition(competition);
         competition.NbTeamMainCompetition = mainCompetition.NumberOfTeam;
         int nbTeamToAdd = competition.NumberOfTeam;
         for (int i = 0; i < nbTeamToAdd; i++)
         {
             var team = new Team("A remplacer", true, 0);
             competition.InitialTeams.Add(team);
             _competitionRepo.Save(competition);
         }
     }
 }
Esempio n. 9
0
 public Node ApplyResultOnCompetition(Competition competition, Node nodeTree)
 {
     return competition.Results.OrderBy(x => x.Date).Aggregate(nodeTree, (current, result) => ApplyResultOnCompetition(result, current));
 }
 public void Save(Competition competition)
 {
     _competitionRepo.Save(competition);
 }
 public void Randomize(Competition competition)
 {
     competition.Shuffle();
     Save(competition);
 }
 public void Lock(Competition competition)
 {
     competition.IsLocked = true;
     Save(competition);
 }
 public bool IsTeamIsEliminated(Competition competition, Team team)
 {
     return competition.Results.Any(x => x.TeamLoose == team);
 }
 public int GetNextNumber(Competition competition)
 {
     return competition.InitialTeams.Any() ? competition.InitialTeams.Max(x => x.Number) + 1 : 1;
 }
 public Competition GetMainCompetition(Competition cryingCompetition)
 {
     return
         _competitionRepo.QueryAll().FirstOrDefault(x => x.CryingCompetitionId == cryingCompetition.Id);
 }
 public Competition CreateCompetition(string name, double price, double betByTeam, double percentOfThePot)
 {
     var competition = new Competition(name, false, price, betByTeam, percentOfThePot);
     var cryingCompetition = new Competition(name, true, 0, betByTeam, 1 - percentOfThePot);
     Save(cryingCompetition);
     competition.CryingCompetitionId = cryingCompetition.ObjectId.ToString();
     Save(competition);
     return competition;
 }
 public void CreateTeamInCompetion(Team team, Competition competition)
 {
     competition.AddTeam(team);
     Save(competition);
 }
 public void StartCompetition(Competition competition)
 {
     var cryingCompetition = GetCryingCompetition(competition);
     Randomize(competition);
     PopulateCryingCompetition(cryingCompetition);
     _priceService.AttributPot(competition);
     _priceService.AttributPot(cryingCompetition);
     Lock(competition);
 }
Esempio n. 19
0
 public void AttributPot(Competition competition)
 {
     competition.Pot = (competition.BetByTeam * competition.InitialTeams.Count) * competition.PercentOfThePot;
     _competitionRepo.Save(competition);
 }
 void AddTeamInCryingCompetition(Competition competition, Team team)
 {
     var teamToReplace = competition.InitialTeams.FirstOrDefault(x => x.IsTeamToReplace);
     if (teamToReplace == null)
     {
         throw new Exception("pas possible normalement, learn to code noob");
     }
     competition.InitialTeams.Remove(teamToReplace);
     competition.AddTeam(team);
     team.WinInARow = 0;
     _teamRepo.Save(team);
     Save(competition);
 }
 private Competition GetCryingCompetition(Competition competition)
 {
     return Find(competition.CryingCompetitionId);
 }
Esempio n. 22
0
        private Node CreateNode(List<Team> listTeamInFirstLevel, List<Team> teams, Competition competition, Node parentNode, int levelTree, int depth)
        {
            if (levelTree > depth)
                return null;
            if (!listTeamInFirstLevel.Any() && !teams.Any() && parentNode != null)
                return null;

            var node = new Node { ParentNode = parentNode, DepthOfTheTree = depth, Level = levelTree, CompetitionId = competition.Id };

            if (!listTeamInFirstLevel.Any() && teams.Any() && (levelTree == depth - 1))
            {
                var team = PickATeam(teams);
                node.TopNode = null;
                node.BottomNode = null;
                node.Team = team;

            }

            if (listTeamInFirstLevel.Any() && levelTree == depth)
            {
                var team = PickATeam(listTeamInFirstLevel);
                node.TopNode = null;
                node.BottomNode = null;
                node.Team = team;
            }

            node.TopNode = CreateNode(listTeamInFirstLevel, teams, competition, node, levelTree + 1, depth);
            node.BottomNode = CreateNode(listTeamInFirstLevel, teams, competition, node, levelTree + 1, depth);
            return node;
        }