예제 #1
0
        public MLBGameFuture(XElement game)
            : base(game)
        {
            float era;
            int num;

            away_team = new MLBTeam(
               game.Attribute("away_team_city").Value,
               game.Attribute("away_team_name").Value,
               game.Attribute("away_division").Value,
               game.Attribute("away_league_id").Value,
               game.Attribute("away_games_back").Value,
               game.Attribute("away_games_back_wildcard").Value,
               Convert.ToInt32(game.Attribute("away_win").Value),
               Convert.ToInt32(game.Attribute("away_loss").Value),
                game.Attribute("away_name_abbrev").Value
               );

            home_team = new MLBTeam(
                game.Attribute("home_team_city").Value,
                game.Attribute("home_team_name").Value,
                game.Attribute("home_division").Value,
                game.Attribute("home_league_id").Value,
                game.Attribute("home_games_back").Value,
                game.Attribute("home_games_back_wildcard").Value,
                Convert.ToInt32(game.Attribute("home_win").Value),
                Convert.ToInt32(game.Attribute("home_loss").Value),
                game.Attribute("home_name_abbrev").Value
                );

            id = game.Attribute("id").Value;
            park = game.Attribute("venue").Value;

            data_dir = game.Attribute("game_data_directory").Value;

            if (game.Element("home_probable_pitcher").Attribute("id").Value == "")
            {
                home_prob = new MLBPitcher(
                    0,
                    "N/A",
                    "N/A",
                    0,
                    0,
                    0,
                    0,
                    start);
            }
            else
            {
                if (game.Element("home_probable_pitcher").Attribute("number").Value == "")
                    num = 0;
                else
                    num = Convert.ToInt32(game.Element("home_probable_pitcher").Attribute("number").Value);

                if (game.Element("home_probable_pitcher").Attribute("era").Value == "-.--")
                    era = 0;
                else
                    era = Convert.ToSingle(game.Element("home_probable_pitcher").Attribute("era").Value);

                    home_prob = new MLBPitcher(
                        Convert.ToInt32(game.Element("home_probable_pitcher").Attribute("id").Value),
                        game.Element("home_probable_pitcher").Attribute("last").Value,
                        game.Element("home_probable_pitcher").Attribute("first").Value,
                        num,
                        era,
                        Convert.ToInt32(game.Element("home_probable_pitcher").Attribute("wins").Value),
                        Convert.ToInt32(game.Element("home_probable_pitcher").Attribute("losses").Value),
                        start
                        );
            }

            if (game.Element("away_probable_pitcher").Attribute("id").Value == "")
            {
                away_prob = new MLBPitcher(
                    0,
                    "N/A",
                    "N/A",
                    0,
                    0,
                    0,
                    0,
                    start);
            }
            else
            {
                if (game.Element("away_probable_pitcher").Attribute("era").Value == "-.--")
                    era = 0;
                else
                    era = Convert.ToSingle(game.Element("away_probable_pitcher").Attribute("era").Value);

                if (game.Element("away_probable_pitcher").Attribute("number").Value == "")
                    num = 0;
                else
                    num = Convert.ToInt32(game.Element("away_probable_pitcher").Attribute("number").Value);

                away_prob = new MLBPitcher(
                    Convert.ToInt32(game.Element("away_probable_pitcher").Attribute("id").Value),
                    game.Element("away_probable_pitcher").Attribute("last").Value,
                    game.Element("away_probable_pitcher").Attribute("first").Value,
                    num,
                    era,
                    Convert.ToInt32(game.Element("away_probable_pitcher").Attribute("wins").Value),
                    Convert.ToInt32(game.Element("away_probable_pitcher").Attribute("losses").Value),
                    start
                    );
            }

            status = GameStatus.Future;
        }
예제 #2
0
        public MLBGameCompleted(XElement game)
            : base(game)
        {
            int aruns, ahits, aerrors;
            int hruns, hhits, herrors;
            bool away_won;
            float era;
            int number;

            IEnumerable<XElement> i_innings = game.Element("linescore").Elements("inning");

            if (game.Element("winning_pitcher").Attribute("era").Value == "-.--"
                    || game.Element("winning_pitcher").Attribute("era").Value == "-")
                era = 0;
            else
                era = Convert.ToSingle(game.Element("winning_pitcher").Attribute("era").Value);

            if (game.Element("winning_pitcher").Attribute("number").Value == "")
                number = 0;
            else
                number = Convert.ToInt32(game.Element("winning_pitcher").Attribute("number").Value);

            winner = new MLBPitcher(
                Convert.ToInt32(game.Element("winning_pitcher").Attribute("id").Value),
                game.Element("winning_pitcher").Attribute("last").Value,
                game.Element("winning_pitcher").Attribute("first").Value,
                number,
                era,
                Convert.ToInt32(game.Element("winning_pitcher").Attribute("wins").Value),
                Convert.ToInt32(game.Element("winning_pitcher").Attribute("losses").Value),
                start);

            if (game.Element("losing_pitcher").Attribute("era").Value == "-.--"
                    || game.Element("losing_pitcher").Attribute("era").Value == "-")
                era = 0;
            else
                era = Convert.ToSingle(game.Element("losing_pitcher").Attribute("era").Value);

            if (game.Element("losing_pitcher").Attribute("number").Value == "")
                number = 0;
            else
                number = Convert.ToInt32(game.Element("losing_pitcher").Attribute("number").Value);

            loser = new MLBPitcher(
                Convert.ToInt32(game.Element("losing_pitcher").Attribute("id").Value),
                game.Element("losing_pitcher").Attribute("last").Value,
                game.Element("losing_pitcher").Attribute("first").Value,
                number,
                era,
                Convert.ToInt32(game.Element("losing_pitcher").Attribute("wins").Value),
                Convert.ToInt32(game.Element("losing_pitcher").Attribute("losses").Value),
                start);

            if (game.Element("save_pitcher").Attribute("id").Value != "")
                closer = new MLBPitcherClosing(
                    Convert.ToInt32(game.Element("save_pitcher").Attribute("id").Value),
                    game.Element("save_pitcher").Attribute("last").Value,
                    game.Element("save_pitcher").Attribute("first").Value,
                    Convert.ToInt32(game.Element("save_pitcher").Attribute("number").Value),
                    Convert.ToSingle(game.Element("save_pitcher").Attribute("era").Value),
                    Convert.ToInt32(game.Element("save_pitcher").Attribute("saves").Value),
                    Convert.ToInt32(game.Element("save_pitcher").Attribute("svo").Value),
                    Convert.ToInt32(game.Element("losing_pitcher").Attribute("wins").Value),
                    Convert.ToInt32(game.Element("losing_pitcher").Attribute("losses").Value),
                    start);

            foreach (XElement inning in i_innings)
            {
                if(inning.Attribute("home") != null)
                    innings.Add(new MLBInning(inning.Attribute("away").Value, inning.Attribute("home").Value));
                else
                    innings.Add(new MLBInning(inning.Attribute("away").Value, ""));
            }

            aruns = Convert.ToInt32(game.Element("linescore").Element("r").Attribute("away").Value);
            ahits = Convert.ToInt32(game.Element("linescore").Element("h").Attribute("away").Value);
            aerrors = Convert.ToInt32(game.Element("linescore").Element("e").Attribute("away").Value);

            hruns = Convert.ToInt32(game.Element("linescore").Element("r").Attribute("home").Value);
            hhits = Convert.ToInt32(game.Element("linescore").Element("h").Attribute("home").Value);
            herrors = Convert.ToInt32(game.Element("linescore").Element("e").Attribute("home").Value);

            away_won = (aruns > hruns);

                away_team = new MLBTeamCompleted(
                game.Attribute("away_team_city").Value,
                game.Attribute("away_team_name").Value,
                game.Attribute("away_division").Value,
                game.Attribute("away_league_id").Value,
                game.Attribute("away_games_back").Value,
                game.Attribute("away_games_back_wildcard").Value,
                Convert.ToInt32(game.Attribute("away_win").Value),
                Convert.ToInt32(game.Attribute("away_loss").Value),
                game.Attribute("away_name_abbrev").Value,
                aruns,
                ahits,
                aerrors,
                away_won
                );

                home_team = new MLBTeamCompleted(
                    game.Attribute("home_team_city").Value,
                    game.Attribute("home_team_name").Value,
                    game.Attribute("home_division").Value,
                    game.Attribute("home_league_id").Value,
                    game.Attribute("home_games_back").Value,
                    game.Attribute("home_games_back_wildcard").Value,
                    Convert.ToInt32(game.Attribute("home_win").Value),
                    Convert.ToInt32(game.Attribute("home_loss").Value),
                    game.Attribute("home_name_abbrev").Value,
                    hruns,
                    hhits,
                    herrors,
                    !away_won
                    );

            status = GameStatus.Completed;
        }
예제 #3
0
        public MLBGameInProgress(XElement game)
            : base(game)
        {
            int runs, hits, errors, sb, hr;
            float era;

            IEnumerable<XElement> i_innings = game.Element("linescore").Elements("inning");

            foreach (XElement inning in i_innings)
            {
                if (inning.Attribute("home") != null)
                    innings.Add(new MLBInning(inning.Attribute("away").Value, inning.Attribute("home").Value));
                else
                    innings.Add(new MLBInning(inning.Attribute("away").Value, ""));
            }

            inning_half = game.Element("status").Attribute("inning_state").Value;

            if (inning_half == "")
                inning_half = "Top";

            runs = Convert.ToInt32(game.Element("linescore").Element("r").Attribute("away").Value);
            hits = Convert.ToInt32(game.Element("linescore").Element("h").Attribute("away").Value);
            errors = Convert.ToInt32(game.Element("linescore").Element("e").Attribute("away").Value);
            sb = Convert.ToInt32(game.Element("linescore").Element("sb").Attribute("away").Value);
            hr = Convert.ToInt32(game.Element("linescore").Element("hr").Attribute("away").Value);

            away_team = new MLBTeamActive(
                game.Attribute("away_team_city").Value,
                game.Attribute("away_team_name").Value,
                game.Attribute("away_division").Value,
                game.Attribute("away_league_id").Value,
                game.Attribute("away_games_back").Value,
                game.Attribute("away_games_back_wildcard").Value,
                Convert.ToInt32(game.Attribute("away_win").Value),
                Convert.ToInt32(game.Attribute("away_loss").Value),
                game.Attribute("away_name_abbrev").Value,
                runs,
                hits,
                errors
                );

            runs = Convert.ToInt32(game.Element("linescore").Element("r").Attribute("home").Value);
            hits = Convert.ToInt32(game.Element("linescore").Element("h").Attribute("home").Value);
            errors = Convert.ToInt32(game.Element("linescore").Element("e").Attribute("home").Value);
            sb = Convert.ToInt32(game.Element("linescore").Element("sb").Attribute("home").Value);
            hr = Convert.ToInt32(game.Element("linescore").Element("hr").Attribute("home").Value);

            home_team = new MLBTeamActive(
                game.Attribute("home_team_city").Value,
                game.Attribute("home_team_name").Value,
                game.Attribute("home_division").Value,
                game.Attribute("home_league_id").Value,
                game.Attribute("home_games_back").Value,
                game.Attribute("home_games_back_wildcard").Value,
                Convert.ToInt32(game.Attribute("home_win").Value),
                Convert.ToInt32(game.Attribute("home_loss").Value),
                game.Attribute("home_name_abbrev").Value,
                runs,
                hits,
                errors
                );

            last_play = Regex.Replace(game.Element("pbp").Attribute("last").Value, @"\s+", " ");

            int num;

            try
            {
                num = Convert.ToInt32(game.Element("batter").Attribute("number").Value);
            }
            catch (Exception)
            {
                num = 0;
            }

            cur_batter = new MLBBatter(
                Convert.ToInt32(game.Element("batter").Attribute("id").Value),
                game.Element("batter").Attribute("last").Value,
                game.Element("batter").Attribute("first").Value,
                num,
                game.Element("batter").Attribute("pos").Value,
                Convert.ToInt32(game.Element("batter").Attribute("ab").Value),
                Convert.ToInt32(game.Element("batter").Attribute("h").Value),
                Convert.ToSingle(game.Element("batter").Attribute("avg").Value),
                Convert.ToInt32(game.Element("batter").Attribute("hr").Value),
                Convert.ToInt32(game.Element("batter").Attribute("rbi").Value),
                Convert.ToSingle(game.Element("batter").Attribute("slg").Value),
                Convert.ToSingle(game.Element("batter").Attribute("ops").Value),
                Convert.ToSingle(game.Element("batter").Attribute("obp").Value),
                start
                );

            try
            {
                num = Convert.ToInt32(game.Element("pitcher").Attribute("number").Value);
            }
            catch (Exception)
            {
                num = 0;
            }

            if (game.Element("pitcher").Attribute("era").Value == "-.--"
                || game.Element("pitcher").Attribute("era").Value == "-")
                era = 0;
            else
            {
                era = Convert.ToSingle(game.Element("pitcher").Attribute("era").Value);

                cur_pitcher = new MLBPitcher(
                    Convert.ToInt32(game.Element("pitcher").Attribute("id").Value),
                    game.Element("pitcher").Attribute("last").Value,
                    game.Element("pitcher").Attribute("first").Value,
                    num,
                    Convert.ToSingle(game.Element("pitcher").Attribute("era").Value),
                    Convert.ToInt32(game.Element("pitcher").Attribute("wins").Value),
                    Convert.ToInt32(game.Element("pitcher").Attribute("losses").Value),
                    start);
            }

            switch (game.Element("runners_on_base").Attribute("status").Value)
            {
                case "0":
                    base_situation = BaseSituations.BasesEmpty;
                    break;
                case "1":
                    base_situation = BaseSituations.RunnerOnFirst;
                    break;
                case "2":
                    base_situation = BaseSituations.RunnerOnSecond;
                    break;
                case "3":
                    base_situation = BaseSituations.RunnerOnThird;
                    break;
                case "4":
                    base_situation = BaseSituations.RunnersOnFirstAndSecond;
                    break;
                case "5":
                    base_situation = BaseSituations.RunnersOnFirstAndThird;
                    break;
                case "6":
                    base_situation = BaseSituations.RunnersOnSecondAndThird;
                    break;
                case "7":
                    base_situation = BaseSituations.BasesLoaded;
                    break;
            }

            cur_balls = Convert.ToInt32(game.Element("status").Attribute("b").Value);
            cur_strikes = Convert.ToInt32(game.Element("status").Attribute("s").Value);
            cur_outs = Convert.ToInt32(game.Element("status").Attribute("o").Value);

            // get HR hitters

            status = GameStatus.InProgress;
        }