Ejemplo n.º 1
0
        public void simulate(day d)
        {
            Random rnd = new Random();

            holeResults.Clear();
            foreach (flight f in d.flights.Values)
            {
                foreach (team t in f.teams.Values)
                {
                    foreach (playingBall b in t.playingBalls.Values)
                    {
                        List <int> sims = new List <int>();
                        for (int i = 1; i <= 18; i++)
                        {
                            int r = Convert.ToInt32(1 + 10 * rnd.NextDouble());
                            if (r > 9)
                            {
                                r = 0;
                            }
                            sims.Add(r);
                        }
                        if (!holeResults.ContainsKey(b.GetPlayersString()))
                        {
                            holeResults.Add(b.GetPlayersString(), sims);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public day newDay(day.PlayMode mode)
        {
            day newDay = new day(mode, "");

            days.Add(newDay);
            days.Last().nr = days.Count;
            return(days.Last());
        }
Ejemplo n.º 3
0
        public day newDay(day.PlayMode mode)
        {
            day newDay = new day(mode, year);

            newDay.nr = days.Count + 1;

            days.Add(newDay);
            return(days.Last());
        }
Ejemplo n.º 4
0
        public day getDaybyNr(int nr)
        {
            day ret = days[nr - 1];

            if (ret.nr != nr)
            {
                throw new Exception(String.Format("could not find hole with nr {0}, holes probably wrong sorted", nr));
            }
            return(ret);
        }
Ejemplo n.º 5
0
        public List <HoleForStat> GetHoleStats(int toDayNr)
        {
            List <HoleForStat> ret = new List <HoleForStat>();

            for (int i = 1; i <= toDayNr; ++i)
            {
                day ctDay = getDaybyNr(i);
                ret.AddRange(ctDay.statHoles);
            }
            return(ret);
        }
Ejemplo n.º 6
0
 public void initialise(day d)
 {
     foreach (flight f in d.flights.Values)
     {
         foreach (team t in f.teams.Values)
         {
             foreach (Player p in t.players.Values)
             {
                 extras.Add(p.name, 0);
             }
         }
     }
 }
Ejemplo n.º 7
0
        public void initialiseflightsFromInputTeam(int dayNr, List <TeamInput> InputTeams)
        {
            #region loop through inputTeams, extract info for day
            List <dayInputTeamForPlayer> diPs = new List <dayInputTeamForPlayer>();
            foreach (TeamInput ti in InputTeams)
            {
                String ctInput = "";
                switch (dayNr)
                {
                case 1: ctInput = ti.R1; break;

                case 2: ctInput = ti.R2; break;

                case 3: ctInput = ti.R3; break;

                case 4: ctInput = ti.R4; break;

                case 5: ctInput = ti.R5; break;

                case 6: ctInput = ti.R6; break;

                case 7: ctInput = ti.R7; break;
                }
                if (!String.IsNullOrWhiteSpace(ctInput) && ctInput != "0" && ctInput.Length >= 2) //0=Abandon
                {
                    ctInput = ctInput.Trim();
                    diPs.Add(new dayInputTeamForPlayer
                    {
                        PlayerName = ti.Player,
                        FlightName = ctInput.Substring(0, 1),
                        TeamName   = ctInput.Substring(1, 1),
                        BallName   = ctInput.Remove(0, 2)
                    });
                }
            }
            #endregion

            day    ctDay    = getDaybyNr(dayNr);
            course ctCourse = ctDay.courseDefinition;
            foreach (dayInputTeamForPlayer diP in diPs)
            {
                Player P = Players.Find(x => x.name == diP.PlayerName).CloneJson();
                P.playingHcp = ctCourse.getPlayingHcp(P.initialHcp);
                ctDay.SetPlayer(diP, P);
            }
            ctDay.CalcCoupsRecu();
            ctDay.InitialiseMatchsWithTeams();
        }
Ejemplo n.º 8
0
 public void initialise(day d)
 {
     foreach (flight f in d.flights.Values)
     {
         foreach (team t in f.teams.Values)
         {
             foreach (playingBall b in t.playingBalls.Values)
             {
                 holeResults.Add(b.GetPlayersString(), new List <int>()
                 {
                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                 });
             }
         }
     }
 }
Ejemplo n.º 9
0
        public day quickCloneForDraw()
        {
            day ret = new day();

            ret.nr               = nr;
            ret.playMode         = playMode;
            ret.nbOfPlayerForDay = nbOfPlayerForDay;
            ret.isFoursome       = isFoursome;
            ret.PlayersForTheDay = PlayersForTheDay.ConvertAll <Player>(x => new Player {
                name = x.name, startNumber = x.startNumber
            });
            ret.PlayersLeftToDraw = PlayersLeftToDraw.ConvertAll <Player>(x => new Player {
                name = x.name, startNumber = x.startNumber
            });
            foreach (flight f in flights.Values)
            {
                ret.flights.Add(f.name, f.quickCloneForDraw());
            }
            return(ret);
        }
Ejemplo n.º 10
0
        public void calculate(int toDayNr)
        {
            #region 1st Loop with calc daily stbl
            ctDayOfCompetition = toDayNr;
            Hcps prHcps = null;
            for (int i = 1; i <= toDayNr; ++i)
            {
                day ctDay = getDaybyNr(i);
                ctDay.calculateStbl(); //calculate stbl for the day and every Players
                ctDay.calculateStblNewHcps(prHcps);
                prHcps = ctDay.NewHcps;
                Dictionary <string, PlayerResult> ctDailyResults = new Dictionary <string, PlayerResult>();
                List <String> sortedList = ctDay.stblPoints.getSortedPlayerList();
                foreach (Player P in Players)
                {
                    PlayerResult ctPR = new PlayerResult();
                    ctPR.PlayerName = P.name;
                    ctPR.StblDay    = ctDay.stblPoints.getStblPointsForLastHoles(P.name);
                    ctPR.shExtraDay = ctDay.getShPointsForExtra(P.name);
                    ctPR.shMatch    = ctDay.getShPointsForMatch(P.name, configForYear);
                    ctPR.shStblDay  = ctDay.getShPointsForStblDaily(P.name, configForYear);
                    int Position = sortedList.FindIndex(x => x == P.name);
                    ctPR.posStblDay = Position + 1;
                    ctDailyResults.Add(ctPR.PlayerName, ctPR);
                }
                results.Add(ctDailyResults); // stores daily scores for the day
            }
            #endregion
            #region 2nd Loop Sum up and sort for weekly stable
            for (int i = 1; i <= toDayNr; ++i)
            {
                Dictionary <String, Double> sortableScores = new Dictionary <string, Double>();
                foreach (Player P in Players)
                {
                    //loop to identify the worst day for the player (scratch it) (from begin to i)
                    int worstDay            = 1;
                    int worstDayStbl        = 1000;
                    int cntDaysValidForStbl = 0;
                    for (int j = 1; j <= i; ++j) //loop from begin to i (ctDay in the mainloop)
                    {
                        day ctDay = getDaybyNr(j);
                        if (ctDay.isFoursome)
                        {
                            continue;
                        }
                        cntDaysValidForStbl++;
                        int ctStbl = getResultsbyDayNr(j)[P.name].StblDay; // get the daily stbl
                        if (worstDayStbl > ctStbl)
                        {
                            worstDay     = j;
                            worstDayStbl = ctStbl;
                        }
                    }
                    if (cntDaysValidForStbl <= 1)
                    {
                        worstDay = -1;                                //do not scratch if there is only one day of competition valid for stbl
                    }
                    getResultsbyDayNr(i)[P.name].worstDay = worstDay; //worst day

                    //sortable score looks like 144 (sum) 0036 (stbl day4) 0033 (stbl day3) 0041 (stbl day2) 0034 (stbl day1). 0008 (position from 1st stbl)  and is used to sort out players with same sum for the week
                    Double factor          = 1;
                    Double factor_X        = 1;
                    Double sortableScore   = (100 - (double)getResultsbyDayNr(1)[P.name].posStblDay) / 1000; //initialise with position from the 1st stbl (position (not stbl) forces a position even at beginning)
                    Double sortableScore_X = (100 - (double)getResultsbyDayNr(1)[P.name].posStblDay) / 1000;
                    int    sumStbl         = 0;
                    int    sumStbl_X       = 0;
                    Double sumEff          = 0;
                    for (int j = 1; j <= i; ++j) //loop from begin to i (ctDay in the mainloop)
                    {
                        sumEff += getResultsbyDayNr(j)[P.name].shMatch + getResultsbyDayNr(j)[P.name].shStblDay + getResultsbyDayNr(j)[P.name].shExtraDay;

                        day ctDay = getDaybyNr(j);
                        if (ctDay.isFoursome)
                        {
                            continue;
                        }

                        int ctStbl = getResultsbyDayNr(j)[P.name].StblDay; // get the daily stbl

                        sumStbl       += ctStbl;                           // sum up
                        sortableScore += factor * (double)ctStbl;          //store for sort
                        factor        *= 1000;

                        //don't use the score from the worstday
                        if (j != worstDay)
                        {
                            sumStbl_X       += ctStbl;                                       // sum up
                            sortableScore_X += factor_X * (double)(ctStbl == 0 ? 1: ctStbl); //store for sort (0 is not good)
                            factor_X        *= 1000;
                        }
                    }
                    sortableScore   += factor * (double)sumStbl;          //store for sort
                    sortableScore_X += factor_X * (double)sumStbl_X;      //store for sort
                    getResultsbyDayNr(i)[P.name].shEffective = sumEff;    //sum of matchs + daily sh + extra if defined
                    getResultsbyDayNr(i)[P.name].StblWeek    = sumStbl;   //save sum for week
                    getResultsbyDayNr(i)[P.name].StblWeek_X  = sumStbl_X; //save sum for week (scratch)
                    if (configForYear.useScratch)
                    {
                        sortableScores.Add(P.name, sortableScore_X); //add sortableScore to dictionary
                    }
                    else
                    {
                        sortableScores.Add(P.name, sortableScore); //add sortableScore to dictionary
                    }
                }
                List <String> sortedList = sortableScores.OrderByDescending(kp => kp.Value).Select(kp => kp.Key).ToList();
                sortableScores.Clear();
                foreach (Player P in Players) //loop again to get Position and sh
                {
                    int Position = sortedList.FindIndex(x => x == P.name);
                    //if (!getDaybyNr(i).stblPoints.isValidForStblDay())
                    //    Position = 8; // make sure
                    getResultsbyDayNr(i)[P.name].posStblWeek = Position + 1;
                    String[] splits = configForYear.stlWeek.Replace(" ", "").Split(',');
                    double   ctSh   = 0;
                    if (splits.Length > Position)
                    {
                        Double.TryParse(splits[Position], out ctSh);
                    }
                    getResultsbyDayNr(i)[P.name].shStblWeek = ctSh;
                    getResultsbyDayNr(i)[P.name].shVirtual  = getResultsbyDayNr(i)[P.name].shEffective + ctSh;

                    #region sortable score for overall Position
                    Double sortableScore = 0;
                    Double factor        = 1;
                    sortableScore += 20 - getResultsbyDayNr(i)[P.name].posStblWeek * factor;
                    factor        *= 1000;
                    sortableScore += getResultsbyDayNr(i)[P.name].shVirtual * factor;
                    sortableScores.Add(P.name, sortableScore);
                    #endregion
                }
                sortedList.Clear();
                sortedList = sortableScores.OrderByDescending(kp => kp.Value).Select(kp => kp.Key).ToList();
                foreach (Player P in Players) //loop again to get Position and sh
                {
                    int Position = sortedList.FindIndex(x => x == P.name);
                    getResultsbyDayNr(i)[P.name].posVirtual = Position + 1;
                }
            }
            #endregion
        }