예제 #1
0
        private void DumpCalculations(bool isHome, NFLGame game, int tdr, string pr, string pp, string ro, int tds,
                                      int tdd, string rd, string oppRatings, string teamRatings, int ppr, int tdp,
                                      int score, string pd, string po, int fg)
        {
            var team = isHome ? game.HomeTeamName : game.AwayTeamName;

            Announce(string.Format("team {2} Ratings : {0}-{3} opponentRatings {1}-{4}",
                                   teamRatings, oppRatings, team,
                                   Utility.RatingPts(teamRatings),
                                   Utility.RatingPts(oppRatings)));
            if (game.IsDomeGame())
            {
                Announce("Adding FG for Dome game");
            }
            if (game.IsBadWeather())
            {
                Announce("Subtracting FG for bad weather");
            }
            Announce(string.Format("PO-{1} v PD-{2}:TD passes: {0}", tdp - ppr, po, pd));
            Announce(string.Format("PP-{1} v PR-{2}:TD passes: {0}", ppr, pp, pr));
            Announce(string.Format("RO-{1} v RD-{2}:TD runs: {0}", tdr, ro, rd));
            Announce(string.Format("Field goals: {0}", fg));
            Announce(string.Format("Defensive Scores: {0}", tdd));
            Announce(string.Format("Special Team Scores: {0}", tds));
            Announce(string.Format("Total Score: {0}", score));
        }
예제 #2
0
        private string DomeBit(
            NFLGame g,
            NFLPlayer p)
        {
            var bit = " ";

            if (p.IsKicker())
            {
                if (g.IsDomeGame())
                {
                    bit = "+";
                }
                else if (g.IsBadWeather())
                {
                    bit = "-";
                }
            }
            else
            {
                if (p.ScoredLastTwo(TimeKeeper))
                {
                    bit = "*";
                }
                else if (p.ScoredLastGame(TimeKeeper))
                {
                    bit = "+";
                }
            }
            return(bit);
        }
        public Int32 PredictTDc(NFLPlayer plyr, string season, int week)
        {
            //  Predict the number of FGs this player will kick
            int tdc = 0;

            //  starters only
            if (plyr.IsStarter() && (plyr.PlayerCat == RosterLib.Constants.K_RECEIVER_CAT))
            {
                if (plyr.CurrTeam.Ratings.Equals("CCCCCC"))
                {
                    plyr.CurrTeam.SetRecord(season);
                }

                //  who are the opponents
                NflTeam opponent = plyr.CurrTeam.OpponentFor(season, week);
                if (opponent != null)
                {
                    if (opponent.Ratings.Equals("CCCCCC"))
                    {
                        opponent.SetRecord(season);                                // Incase not initialised
                    }
                    //  not on a bye
                    tdc = 1;
                    int diff = ConvertRating(plyr.CurrTeam.PoRating()) - ConvertRating(opponent.PdRating());
                    if (diff > 0)
                    {
                        tdc += 1;
                    }
                    if (diff > 2)
                    {
                        tdc += 1;
                    }
                    if (diff < -2)
                    {
                        tdc -= 1;
                    }
                }

                //  What is the Game
                NFLGame game = plyr.CurrTeam.GameFor(season, week);
                if (game != null)
                {
                    if (game.IsHome(plyr.CurrTeam.TeamCode))
                    {
                        tdc += 1;
                    }
                    if (game.IsBadWeather())
                    {
                        tdc -= 1;
                    }
                }
                tdc = plyr.IsTe() ? Convert.ToInt32(tdc * .25M) : Convert.ToInt32(tdc * .5M);
            }
            return(tdc);
        }
예제 #4
0
        public Int32 PredictTDr(NFLPlayer plyr, string season, int week)
        {
            //  Predict the number of FGs this player will kick
            int tDr = 0;

            //  starters only
            if (plyr.IsStarter() && (plyr.PlayerCat == RosterLib.Constants.K_RUNNINGBACK_CAT) && plyr.IsRusher())
            {
                if (plyr.CurrTeam.Ratings.Equals("CCCCCC"))
                {
                    plyr.CurrTeam.SetRecord(season, skipPostseason: false);
                }

                //  who are the opponents
                NflTeam opponent = plyr.CurrTeam.OpponentFor(season, week);
                if (opponent != null)
                {
                    if (opponent.Ratings.Equals("CCCCCC"))
                    {
                        opponent.SetRecord(season, skipPostseason: false);                                // Incase not initialised
                    }
                    //  not on a bye
                    tDr = 1;
                    int diff = ConvertRating(plyr.CurrTeam.RoRating()) - ConvertRating(opponent.RdRating());
                    if (diff > 1)
                    {
                        tDr += 1;
                    }
                    if (diff > 3)
                    {
                        tDr += 1;
                    }
                    if (diff < -1)
                    {
                        tDr -= 1;
                    }
                }

                //  What is the Game
                NFLGame game = plyr.CurrTeam.GameFor(season, week);
                if (game != null)
                {
                    if (game.IsHome(plyr.CurrTeam.TeamCode))
                    {
                        tDr += 1;
                    }
                    if (game.IsBadWeather())
                    {
                        tDr -= 1;
                    }
                }
            }
            return(tDr);
        }
예제 #5
0
        private string DomeBit(NFLGame g, NFLPlayer p)
        {
            var bit = " ";

            if (p.IsKicker())
            {
                if (g.IsDomeGame())
                {
                    bit = "+";
                }
                else if (g.IsBadWeather())
                {
                    bit = "-";
                }
            }
            return(bit);
        }
        public Int32 PredictSacks(
            NflTeam team,
            string season,
            int week)
        {
            //  Predict the number of Sacks the team will make
            int sacks = 0;
            //  who are the opponents
            NflTeam opponent = team.OpponentFor(
                season,
                week);

            if (opponent != null)
            {
                //  not on a bye
                sacks += 1;
                int prSacks = ConvertRating(team.PrRating());
                int ppSacks = ConvertRating(opponent.PpRating());
                sacks += (prSacks - ppSacks);
            }

            //  What is the Game
            NFLGame game = team.GameFor(season, week);

            if (game != null)
            {
                if (game.IsHome(team.TeamCode))
                {
                    sacks += 1;
                }
                if (game.IsBadWeather())
                {
                    sacks += 1;
                }
            }

            if (sacks < 0)
            {
                sacks = 0;
            }

            return(sacks);
        }
예제 #7
0
        public Int32 PredictFGs(NFLPlayer plyr, string season, int week)
        {
            //  Predict the number of FGs this player will kick
            int fg = 0;

            //  starters only
            if (plyr.IsStarter())
            {
                //  who does he play for
                NflTeam kickersTeam = plyr.CurrTeam;

                //  who are the opponents
                NflTeam opponent = kickersTeam.OpponentFor(season, week);
                if (opponent != null)
                {
                    //  not on a bye
                    fg += 1;
                    if (opponent.IsGoodDefence())
                    {
                        fg += 1;
                    }
                }

                //  What is the Game
                NFLGame game = kickersTeam.GameFor(season, week);
                if (game != null)
                {
                    if (game.IsHome(kickersTeam.TeamCode))
                    {
                        fg += 1;
                    }
                    if (game.IsDomeGame())
                    {
                        fg += 1;
                    }
                    if (game.IsBadWeather())
                    {
                        fg -= 1;
                    }
                }
            }
            return(fg);
        }
예제 #8
0
        private GameMetrics CalculateGameMetrics(
            bool isHome,
            NFLGame game,
            DateTime focusDate)
        {
            string teamRatings;
            string oppRatings;

            var gm = new GameMetrics();

            if (isHome)
            {
                oppRatings = RatingsService.GetUnitRatingsFor(
                    game.AwayNflTeam,
                    focusDate);
                teamRatings = RatingsService.GetUnitRatingsFor(
                    game.HomeNflTeam,
                    focusDate);
                //  pump up the defence ratings if its divisional game
                if (game.IsDivisionalGame())
                {
                    teamRatings = PumpIt(
                        teamRatings);
                }
                game.AwayNflTeam.Ratings = oppRatings;
                game.HomeNflTeam.Ratings = teamRatings;
            }
            else
            {
                teamRatings = RatingsService.GetUnitRatingsFor(
                    game.AwayNflTeam,
                    focusDate);
                oppRatings = RatingsService.GetUnitRatingsFor(
                    game.HomeNflTeam,
                    focusDate);
                //  pump up the defence ratings if its divisional game
                if (game.IsDivisionalGame())
                {
                    oppRatings = PumpIt(
                        oppRatings);
                }
                game.HomeNflTeam.Ratings = oppRatings;
                game.AwayNflTeam.Ratings = teamRatings;
            }

            var score = 0;

            if (string.IsNullOrEmpty(teamRatings) ||
                string.IsNullOrEmpty(oppRatings))
            {
                Announce("Ratings not found - skipping score calculation");
            }
            else
            {
                //  Part 0 - Calculate field goals
                var fg = isHome ? 2 : 1;
                if (game.IsDomeGame())
                {
                    fg++;
                }
                else
                {
                    if (game.IsBadWeather())
                    {
                        fg--;
                    }
                }

                //  Part 1 - Calculate Tdp
                var po  = teamRatings.Substring(0, 1);
                var pd  = oppRatings.Substring(5, 1);
                var tdp = TouchdownPasses(po, pd);
                var ydp = YardsPassing(po, pd);
                gm.TDp = tdp;
                gm.YDp = ydp;

                //  Part 2 - Adjust for protection
                var pp  = teamRatings.Substring(2, 1);
                var pr  = oppRatings.Substring(3, 1);
                var ppr = ProtectionAdjustment(pp, pr);

                tdp += ppr;
                if (tdp < 0)
                {
                    tdp = 0;
                }

                //  Part 3 - Calculate Tdr
                var ro  = teamRatings.Substring(1, 1);
                var rd  = oppRatings.Substring(4, 1);
                var tdr = TouchdownRuns(ro, rd);
                var ydr = YardsRushing(ro, rd);
                gm.TDp = tdp;
                gm.TDr = tdr;
                gm.YDr = ydr;

                var tdd = DefensiveScores(
                    game.IsDivisionalGame(),
                    isHome);

                var tds = SpecialTeamScores(
                    game.IsMondayNight(),
                    isHome);

                gm.TDd = tdd;
                gm.TDs = tds;
                gm.FG  = fg;

                //TODO:  Short week adjustment
                //TODO:  Opponent had Route last game adjustment
                //TODO:  Revenge adjustment

                // Total up all the parts of a score
                score = (tdp + tdr + tdd + tds) * 7 + (fg * 3);

                DumpCalculations(
                    isHome,
                    game,
                    tdr,
                    pr,
                    pp,
                    ro,
                    tds,
                    tdd,
                    rd,
                    oppRatings,
                    teamRatings,
                    ppr,
                    tdp,
                    score,
                    pd,
                    po,
                    fg);

                if (isHome)
                {
                    _homeTDp = tdp;
                    _homeTDr = tdr;
                    _homeFg  = fg;
                    _homeTDd = tdd;
                    _homeTDs = tds;
                    _homeYDr = ydr;
                    _homeYDp = ydp;
                }
                else
                {
                    _awayTDp = tdp;
                    _awayTDr = tdr;
                    _awayFg  = fg;
                    _awayTDd = tdd;
                    _awayTDs = tds;
                    _awayYDr = ydr;
                    _awayYDp = ydp;
                }
            }
            gm.Score = score;
            return(gm);
        }