private Team buildTeam(String teamAbrv, String division)
        {
            Team testTeam = new Team(RecordIndex.getNextId(RecordIndex.INDEX.TestTeamId), division, 0);

            testTeam.Abrv = teamAbrv;
            return(testTeam);
        }
        private List <Player> lookupAssigned(int index)
        {
            List <Player> playersInLineup = new List <Player>();

            for (int posIndex = index; posIndex <= index + 9; posIndex++)
            {
                if (GRID.Children[posIndex] is ComboBox)
                {
                    ComboBox box   = (ComboBox)GRID.Children[posIndex];
                    Object   value = (Object)box.SelectedValue;
                    if (value is DefenseComboBoxItem)
                    {
                        Player player = ((DefenseComboBoxItem)value).Value;
                        if (player.Id == 0)
                        {
                            player.Id = RecordIndex.getNextId(RecordIndex.INDEX.PlayerId);
                        }
                        playersInLineup.Add(player);
                    }
                    else
                    {
                        playersInLineup.Add(new Player(true));
                    }
                }
            }
            return(playersInLineup);
        }
Esempio n. 3
0
        private void fillWithTestTeams(Dictionary <String, TeamLineup> lineups, int count)
        {
            for (int i = 1; i <= count; i++)
            {
                String     teamName = "MyTeam" + i;
                TeamLineup lineup   = new TeamLineup();

                LineupData lupLeft = new LineupData(RecordIndex.getNextId(RecordIndex.INDEX.TestLineupDataId), "L",
                                                    new LineupBalanceItem(0, 9, "L"), new LineupBalanceItem(18, 9, "R"), 77);
                lineup.Lineups.Add(lupLeft);
                List <Player> players = new List <Player>();
                String[]      names   = { "CatcherL1", "FirstL1", "SecondL1", "ThirdL1", "ShortstopL1", "LeftL1", "CenterL1", "RightL1", "DesignatedL1" };
                foreach (String name in names)
                {
                    players.Add(createTestPlayer(name));
                }

                LineupData lupRight = new LineupData(RecordIndex.getNextId(RecordIndex.INDEX.TestLineupDataId), "R",
                                                     new LineupBalanceItem(0, 9, "L"), new LineupBalanceItem(18, 9, "R"), 888);
                lineup.Lineups.Add(lupRight);
                String[] namesR = { "CatcherR1", "FirstR1", "SecondR1", "ThirdR1", "ShortstopR1", "LeftR1", "CenterR1", "RightR1", "DesignatedR1" };
                foreach (String name in namesR)
                {
                    players.Add(createTestPlayer(name));
                }

                lineup.playerByGRID = players;

                lineups.Add(teamName, lineup);
            }
        }
        private LineupDataObj createTestTeamLineup(String arm, String start, String end)
        {
            LineupDataObj lineup = new LineupDataObj(RecordIndex.getNextId(RecordIndex.INDEX.TestLineupDataId));

            lineup.PitcherArm = arm;
            // Converts 1R to the int 1 and letter 'R'
            if (start.Equals("E"))
            {
                lineup.BalanceItemFrom = balanceItems[hackyLookupIndex(0, start)];
            }
            else
            {
                lineup.BalanceItemFrom = balanceItems[hackyLookupIndex(Int32.Parse(start.Substring(0, 1)),
                                                                       start.Substring(1, 1))];
            }

            if (end.Equals("E"))
            {
                lineup.BalanceItemTo = balanceItems[hackyLookupIndex(0, start)];
            }
            else
            {
                lineup.BalanceItemTo = balanceItems[hackyLookupIndex(Int32.Parse(end.Substring(0, 1)),
                                                                     end.Substring(1, 1))];
            }
            return(lineup);
        }
Esempio n. 5
0
        public LineupMgrDlg(Boolean testMode)
        {
            if (!testMode)
            {
                InitializeComponent();
            }

            WorkingLineup = new LineupDataObj(RecordIndex.getNextId(RecordIndex.INDEX.LineupDataId));
            balanceItems  = LineupTools.buildDefaultLineupTypes();

            if (!testMode)
            {
                populateComboBoxes(CB_FROM, CB_TO, null);
            }
        }
Esempio n. 6
0
        private void BTN_SAVE_Click(object sender, EventArgs e)
        {
            if (CB_FROM.SelectedItem == null || CB_TO.SelectedItem == null ||
                ((LineupBalanceItem)CB_FROM.SelectedItem).Value > ((LineupBalanceItem)CB_TO.SelectedItem).Value)
            {
                MessageBox.Show("FROM Selection must be less than or equal to the TO Selection");
                return;
            }
            WorkingLineup = new LineupDataObj(RecordIndex.getNextId(RecordIndex.INDEX.LineupDataId));
            WorkingLineup.BalanceItemFrom = (LineupBalanceItem)CB_FROM.SelectedItem;
            WorkingLineup.BalanceItemTo   = (LineupBalanceItem)CB_TO.SelectedItem;
            WorkingLineup.PitcherArm      = radioButtonLH.Checked ? "L" : "R";

            this.Close();
        }
Esempio n. 7
0
        private List <Player> buildListOfTestPitchers(String[,] testData)
        {
            List <Player> players = new List <Player>();

            for (int i = 0; i < testData.GetLength(0); i++)
            {
                Player player = new Player();
                player.Name     = testData[i, 0];
                player.IP       = Int32.Parse(testData[i, 3]);
                player.Bal      = testData[i, 2];
                player.Hits     = Int32.Parse(testData[i, 4]);
                player.BB       = Int32.Parse(testData[i, 5]);
                player.GS       = Int32.Parse(testData[i, 6]);
                player.SAVE     = Int32.Parse(testData[i, 7]);
                player.Team     = new Team(RecordIndex.getNextId(RecordIndex.INDEX.TestTeamId), "ABV", 3);
                player.IsHitter = false;
                player.Throws   = testData[i, 1];
                players.Add(player);
            }
            players.Sort();
            return(players);
        }
        public void collectData(string teamName, string line, int leagueNameLength)
        {
            if (line.StartsWith("--AVERAGE"))
            {
                m_bWorkingOnHitters = true;
            }
            else if (line.StartsWith("----ERA"))
            {
                m_bWorkingOnHitters = false;
            }
            else if (line.StartsWith("NAME") || line.Trim().Length == 0)
            {
                return;
            }
            else
            {
                int    idx        = line.IndexOf("[4]");
                String playerName = line.Substring(0, idx).Trim();
                if (playerName.Length > 0)
                {
                    Player player = new Player();
                    player.IsHitter = m_bWorkingOnHitters;
                    player.Name     = playerName;
                    String data = line.Substring(idx + 4).Trim();
                    Regex  regex;
                    if (data.Contains("---") && !m_bWorkingOnHitters)
                    {
                        regex = new Regex(REGEX_USAGE_PITCHER_NOT_USED);
                    }
                    else
                    {
                        regex = m_bWorkingOnHitters ?
                                new Regex(REGEX_USAGE_HITTER) :
                                new Regex(REGEX_USAGE_PITCHER);
                    }
                    Match teamMatch = regex.Match(line);
                    if (teamMatch.Success)
                    {
                        /*
                         *  Hitters < 120 actual at bats are allowed at 150%      (ie ab * 1.5)
                         *  Hitters > 120 actual at bats are actual at bats + 60  (ie ab + 60)
                         *  Hitters > 600 actual at bats are allowed at 110%      (ie ab * 1.1)
                         *
                         *  Pitchers < 60 is 150% of actual   (59 * 1.5) = +29
                         *  Pitchers > 118 innings is innings + 30
                         *  Pitchers > 199 is 115% of actual (199 * 1.15) = +29
                         */

                        if (m_bWorkingOnHitters)
                        {
                            player.Actual = Convert.ToInt32(teamMatch.Groups[1].Value.Trim());
                            if (player.Actual < 25)
                            {
                                return;
                            }
                            player.Replay = Convert.ToInt32(teamMatch.Groups[2].Value.Trim());

                            player.TargetUsage = getPlayerTargetUsage(player.Actual);
                        }
                        else
                        {
                            player.Actual = Convert.ToInt32(teamMatch.Groups[1].Value.Trim());
                            if (player.Actual < 25)
                            {
                                return;
                            }
                            player.Replay = Convert.ToInt32(teamMatch.Groups[2].Value.Trim());

                            player.TargetUsage = getPitcherTargetUsage(player.Actual);
                        }

                        Team team = Report.DATABASE.getTeam(TeamUtils.prettyTeamName(teamName));
                        if (team == null)
                        {
                            team      = new Team(RecordIndex.getNextId(RecordIndex.INDEX.TeamId), "XX", leagueNameLength);
                            team.Abrv = teamName;
                        }
                        player.Team = team;
                    }
                    listOfPlayers.Add(player);
                }
            }
        }
Esempio n. 9
0
        private void organizeDataTeam(List <string> lines)
        {
            Regex regex                  = new Regex(@"^([0-9]+) (.{1,18})");
            Regex regexPitcherLine       = new Regex(@"^(.{1,22}) [0-9]+ +[0-9]+ +[0-9]+ +([A-Z]+) +([RL]) {1,6}([0-9 ])");
            Regex regexPitcherBalLine    = new Regex(@"^(.{1,17})[0-9]+ +([0-9ERL]+) +[0-9]+ +[0-9]+ +[0-9.]+ +([0-9]+) +([0-9]+) +([0-9]+) +[0-9]+ +[0-9]+ +([0-9]+) +([0-9]+)");
            Regex regexBatterLine        = new Regex(@"^(.{1,17}) +[0-9]+ +[0-9] +[0-9]+ +([A-Z]+) +([0-9ERL]+) +([0-9]+)");
            Regex regexBatterBalanceLine = new Regex(@"^(.{1,16}) +[0-9]+ +([NW])\/([NW]) +([LRS])");

            Team          currentTeam;
            bool          inPitcherBalanceSection = false;
            bool          inPitcherSection        = false;
            bool          inBatterSection         = false;
            bool          inBatterBalanceSection  = false;
            bool          inDefenseSection        = false;
            int           pitcherIndex            = 0;
            int           batterIndex             = 0;
            Team          team     = null;
            List <Player> pitchers = new List <Player>();
            List <Player> batters  = new List <Player>();

            pitcherDataByTeam = new Dictionary <Team, List <Player> >();
            batterDataByTeam  = new Dictionary <Team, List <Player> >();
            foreach (String line in lines)
            {
                Match match = regex.Match(line);
                if (match.Success)
                {
                    String thisTeam = isTeamNameLineOfReport(line);
                    if (thisTeam != null)
                    {
                        inPitcherBalanceSection = false;
                        inPitcherSection        = false;
                        if (team != null)
                        {
                            Console.Out.WriteLine("Finished reading " + team);
                            pitcherDataByTeam.Add(team, pitchers);
                            batterDataByTeam.Add(team, batters);
                            team = null;
                        }
                        pitchers     = new List <Player>();
                        batters      = new List <Player>();
                        pitcherIndex = 0;
                        batterIndex  = 0;
                        team         = new Team(RecordIndex.getNextId(RecordIndex.INDEX.TeamId), "", 0);
                        teams.Add(team);
                        team.Name = thisTeam;
                        team.Abrv = TeamUtils.prettyTeamName(thisTeam);
                        if (team.Abrv.Equals("UNK"))
                        {
                            System.Console.WriteLine("Abreviation mapping for team " + team.Name + " not found.");
//                            MessageBox.Show("Abreviation mapping for team " + team.Name + " not found.");
                        }
                        currentTeam = team;
                    }
                }
                if (!inBatterSection)
                {
                    inBatterSection = line.Contains("CODES YEAR TEAM BAL  AB DO TR HR BAVG  BB K'S RBI  OB%");
                }
                if (!inBatterBalanceSection)
                {
                    inBatterBalanceSection = line.Contains("LEFT% POWER BAT STEAL BUNT H&R RUN");
                    if (inBatterBalanceSection)
                    {
                        inBatterSection = false;
                    }
                }
                if (!inPitcherBalanceSection)
                {
                    inPitcherBalanceSection = line.Contains("LEFT% BAL WON LOST  ERA");
                    if (inPitcherBalanceSection)
                    {
                        inPitcherSection = false;
                    }
                }
                if (!inPitcherSection)
                {
                    inPitcherSection = line.Contains("CODES YEAR TEAM  THROWS START RELIEF");
                    if (inPitcherSection)
                    {
                        inDefenseSection = false;
                    }
                }
                if (!inDefenseSection)
                {
                    inDefenseSection = line.Contains("Catcher       1b   2b   3b   ss   lf   cf   rf   ARM");
                    if (inDefenseSection)
                    {
                        batterIndex            = 0;
                        inBatterBalanceSection = false;
                    }
                }

                if (inBatterSection)
                {
                    Match matchB = regexBatterLine.Match(line);
                    if (matchB.Success)
                    {
                        if (matchB.Groups.Count != 5)
                        {
                            throw new Exception("Expecting Yeam, Team and Text");
                        }
                        Player player = new Player();
                        player.Name = matchB.Groups[1].Value.Trim();
                        //            if (team.Abrv.Length == 0)
                        //                 team.Abrv = matchB.Groups[2].Value.Trim();
                        player.IsHitter = true;
                        player.Bal      = matchB.Groups[3].Value.Trim();

                        float value = 0f;
                        float.TryParse(matchB.Groups[4].Value.Trim(), out value);
                        player.Actual = (int)(value * _config.getABMultiplier());
                        player.Id     = lookupPlayerId(player, team);
//                        player.Id = RecordIndex.getNextId(RecordIndex.INDEX.PlayerId);

                        batters.Add(player);
                        //                   Console.Out.WriteLine("   inBatterSection ");
                    }
                }
                else if (inBatterBalanceSection)
                {
                    Match matchBB = regexBatterBalanceLine.Match(line);
                    if (matchBB.Success)
                    {
                        if (matchBB.Groups.Count != 5)
                        {
                            throw new Exception("Expecting Yeam, Team and Text");
                        }
                        Player player = batters[batterIndex];
                        String name   = matchBB.Groups[1].Value.Trim();

                        // Some reports cut the name off at 16 charaters, then cuts off the last name.
                        if (player.Name.Length > 16)
                        {
                            int firstSpaceIndex = player.Name.IndexOf(' ') + 1;
                            int lastNameLength  = player.Name.Length - firstSpaceIndex;
                            name = name.Substring(0, lastNameLength);
                        }
                        if (!player.Name.EndsWith(name))
                        {
                            Console.Out.WriteLine("ERROR: Batter Name not as expected " + player.Name + " != " + name);
                            continue;
                        }
                        player.PowerL = matchBB.Groups[2].Value.Trim();
                        player.PowerR = matchBB.Groups[3].Value.Trim();
                        player.Throws = matchBB.Groups[4].Value.Trim();
                        player.Id     = lookupPlayerId(player, team);


                        batterIndex++;
                        //                      Console.Out.WriteLine("   inBatterBalanceSection ");
                    }
                }
                else if (inPitcherSection)
                {
                    Match matchP = regexPitcherLine.Match(line);
                    if (matchP.Success)
                    {
                        if (matchP.Groups.Count != 5)
                        {
                            throw new Exception("Expecting Yeam, Team and Text");
                        }
                        Player player = new Player();
                        player.Name = matchP.Groups[1].Value.Trim();
                        if (team.Abrv.Length == 0)
                        {
                            team.Abrv = matchP.Groups[2].Value.Trim();
                        }
                        player.Team     = team;
                        player.IsHitter = false;
                        player.Throws   = matchP.Groups[3].Value.Trim();
                        String spRating = matchP.Groups[4].Value.Trim();
                        if (spRating.Length > 0)
                        {
                            player.Games = Int32.Parse(spRating);
                        }
                        player.Id = lookupPlayerId(player, team);


                        pitchers.Add(player);
//                        Console.Out.WriteLine("   inPitcherSection ");
                    }
                }
                else if (inPitcherBalanceSection)
                {
                    Match matchPB = regexPitcherBalLine.Match(line);
                    if (matchPB.Success)
                    {
                        Player player = pitchers[pitcherIndex];
                        String name   = matchPB.Groups[1].Value.Trim();
                        if (!player.Name.EndsWith(name))
                        {
                            Console.Out.WriteLine("ERROR: Pitcher Name not as expected " + player.Name + " != " + name);
                            continue;
                        }
                        player.Bal = matchPB.Groups[2].Value.Trim();
                        player.IP  = Int32.Parse(matchPB.Groups[3].Value.Trim());

                        player.Hits = Int32.Parse(matchPB.Groups[4].Value.Trim());
                        player.BB   = Int32.Parse(matchPB.Groups[5].Value.Trim());
                        player.GS   = Int32.Parse(matchPB.Groups[6].Value.Trim());
                        player.SAVE = Int32.Parse(matchPB.Groups[7].Value.Trim());
                        pitcherIndex++;
                    }
                }
                else if (inDefenseSection)
                {
                    if (!line.StartsWith("Catcher"))
                    {
                        String name    = line.Substring(0, 16).Trim();
                        String catcher = line.Substring(17, 13).Trim();
                        if (catcher.Length > 0)
                        {  // strip off passball and throwing error stats
                            catcher = catcher.Substring(0, catcher.IndexOf('t'));
                        }
                        String first  = line.Substring(30, 4).Trim();
                        String second = line.Substring(35, 4).Trim();
                        String third  = line.Substring(40, 4).Trim();
                        String sstop  = line.Substring(45, 4).Trim();
                        String left   = line.Substring(50, 4).Trim();
                        String center = line.Substring(55, 4).Trim();
                        String right  = line.Substring(60, 4).Trim();
                        String ofArm  = line.Substring(65, 4).Trim();
                        Player player = batters[batterIndex];

                        if (!player.Name.EndsWith(name))
                        {
                            // Sometimes the game strips off the last 1-3 characters in the report, so this checks for that.
                            if (!player.Name.EndsWith(name.Substring(0, name.Length - 1)) &&
                                !player.Name.EndsWith(name.Substring(0, name.Length - 2)) &&
                                !player.Name.EndsWith(name.Substring(0, name.Length - 3)))
                            {
                                Console.Out.WriteLine("ERROR: Defense Player Name not as expected " + player.Name + " != " + name);

                                continue;
                            }
                        }
                        Defense def = new Defense(RecordIndex.getNextId(RecordIndex.INDEX.DefenseId), catcher, first, second, third, sstop, left, center, right, ofArm);
                        player.Def = def;

                        batterIndex++;
                    }
                }
            }
            pitcherDataByTeam.Add(team, pitchers);
            batterDataByTeam.Add(team, batters);
        }