コード例 #1
0
        /*   static void Main(string[] args)
         * {
         *
         *     LineUp l = LineUpParser.parseLineUPXML("");
         *     Console.Out.WriteLine(l.toString());
         * }
         */
        public static LineUp parseLineUPXML(string file)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(file);
            //doc.Load("C:\\fantabz\\F2019_6_C_T01.xml");

            LineUp lineup = new LineUp();



            XmlNodeList nodes = doc.DocumentElement.SelectNodes("/fantabzzz/competition/team");

            foreach (XmlNode node in nodes)
            {
                string deliveryTime = node.SelectSingleNode("delivery").InnerText;
                lineup.DeliveryTime = deliveryTime;
            }

            XmlNodeList starterNodes = doc.DocumentElement.SelectNodes("/fantabzzz/competition/team/lineup/footballer");

            string[] starter = new string[11];
            int      i       = 0;
            Dictionary <string, string> penaltyTaker = new Dictionary <string, string>();

            foreach (XmlNode node in starterNodes)
            {
                string pid = node.Attributes["id"].Value;
                string pen = node.SelectSingleNode("penaltyPos").InnerText;
                starter[i] = pid;
                i++;
                penaltyTaker.Add(pid, pen);
            }
            lineup.Starting11   = starter;
            lineup.PenaltyTaker = penaltyTaker;

            XmlNodeList substitutesNodes = doc.DocumentElement.SelectNodes("/fantabzzz/competition/team/substitutes/footballer");

            string[] substitutes = new string[8];
            int      j           = 0;

            foreach (XmlNode node in substitutesNodes)
            {
                string pid = node.Attributes["id"].Value;
                substitutes[j] = pid;
                j++;
            }
            lineup.Substitues = substitutes;

            XmlNodeList   excludedNodes = doc.DocumentElement.SelectNodes("/fantabzzz/competition/team/excluded/footballer");
            List <string> excluded      = new List <string>();

            foreach (XmlNode node in excludedNodes)
            {
                string pid = node.Attributes["id"].Value;
                excluded.Add(pid);
            }
            lineup.Excluded = excluded;
            return(lineup);
        }
コード例 #2
0
        public XmlElement evaluateMatch(Match match)
        {
            LineUpEvaluator le = new LineUpEvaluator();
            List <PlayerEvaluationEntry> evaluatedLineUpHome = le.evaluateLinuep(match.Teamid_home, match.Day, match.CompetitionID);

            initialLineUpHome = le.InitialLinup;
            List <PlayerEvaluationEntry> evaluatedLineUpAway = le.evaluateLinuep(match.Teamid_away, match.Day, match.CompetitionID);

            initialLineUpAway = le.InitialLinup;

            double parzialeHome = calculateParzialeSquadra(evaluatedLineUpHome);
            double parzialeAway = calculateParzialeSquadra(evaluatedLineUpAway);

            double fattoreCampoHome = calculateFattoreCampo(match.CompetitionID);

            double modPortiereHome = calculateModPortiere(evaluatedLineUpAway);
            double modPortiereAway = calculateModPortiere(evaluatedLineUpHome);

            double modDifesaHome = calculateModDifesa(evaluatedLineUpAway);
            double modDifesaAway = calculateModDifesa(evaluatedLineUpHome);

            double[] modCentrocampo     = calculateModCentrocampo(evaluatedLineUpHome, evaluatedLineUpAway);
            double   modCentrocampoHome = modCentrocampo[0];
            double   modCentrocampoAway = modCentrocampo[1];

            double modAttaccoHome = calculateModAttacco(evaluatedLineUpHome);
            double modAttaccoAway = calculateModAttacco(evaluatedLineUpAway);

            double[] modPersonale     = calculateModPersonale();
            double   modPersonaleHome = modPersonale[0];
            double   modPersonaleAway = modPersonale[1];

            double totalHome = parzialeHome + fattoreCampoHome + modPortiereHome + modDifesaHome + modCentrocampoHome + modAttaccoHome + modPersonaleHome;
            double totalAway = parzialeAway + modPortiereAway + modDifesaAway + modCentrocampoAway + modAttaccoAway + modPersonaleAway;

            int goalHome = calculateGoals(totalHome);
            int goalAway = calculateGoals(totalAway);

            if (totalHome < 60 && totalAway >= 60 && totalAway - totalHome >= 3)
            {
                goalAway += 1;
            }
            else if (totalAway < 60 && totalHome >= 60 && totalHome - totalAway >= 3)
            {
                goalHome += 1;
            }
            else if (goalHome != goalAway && totalHome < totalAway && totalAway - totalHome < 3)
            {
                if (totalAway < 72)
                {
                    goalAway -= 1;
                }
                else
                {
                    goalHome += 1;
                }
            }
            else if (goalHome != goalAway && totalAway < totalHome && totalHome - totalAway < 3)
            {
                if (totalHome < 72)
                {
                    goalHome -= 1;
                }
                else
                {
                    goalAway += 1;
                }
            }

            match.GoalsAwayTeam = goalAway;
            match.GoalsHomeTeam = goalHome;

            writeTotalScoreToDB(match, totalHome + "", totalAway + "");

            XmlElement matchNode = xmlDoc.CreateElement("match");

            matchNode.SetAttribute("id", match.MatchID);

            XmlElement homeTeamNode = xmlDoc.CreateElement("team");

            homeTeamNode.SetAttribute("id", match.Teamid_home);
            homeTeamNode.SetAttribute("name", match.Teamid_home);
            matchNode.AppendChild(homeTeamNode);

            XmlElement awayTeamNode = xmlDoc.CreateElement("team");

            awayTeamNode.SetAttribute("id", match.Teamid_away);
            awayTeamNode.SetAttribute("name", match.Teamid_away);
            matchNode.AppendChild(awayTeamNode);

            generateLineUPXML(evaluatedLineUpHome, homeTeamNode);
            generateLineUPXML(evaluatedLineUpAway, awayTeamNode);

            XmlElement homePointsNode  = xmlDoc.CreateElement("points");
            XmlElement partialHomeNode = xmlDoc.CreateElement("partial");

            partialHomeNode.InnerText = parzialeHome + "";
            homePointsNode.AppendChild(partialHomeNode);

            XmlElement fattoreCampoHomeNode = xmlDoc.CreateElement("field");

            fattoreCampoHomeNode.InnerText = fattoreCampoHome + "";
            homePointsNode.AppendChild(fattoreCampoHomeNode);

            XmlElement modPerNode = xmlDoc.CreateElement("firstlineup");

            modPerNode.InnerText = modPersonaleHome + "";
            homePointsNode.AppendChild(modPerNode);

            XmlElement modPortieriNode = xmlDoc.CreateElement("goalkeeper");

            modPortieriNode.InnerText = modPortiereHome + "";
            homePointsNode.AppendChild(modPortieriNode);

            XmlElement modDifesaNode = xmlDoc.CreateElement("defender");

            modDifesaNode.InnerText = modDifesaHome + "";
            homePointsNode.AppendChild(modDifesaNode);

            XmlElement modCentrocampoNode = xmlDoc.CreateElement("midfielder");

            modCentrocampoNode.InnerText = modCentrocampoHome + "";
            homePointsNode.AppendChild(modCentrocampoNode);

            XmlElement modAttaccoNode = xmlDoc.CreateElement("striker");

            modAttaccoNode.InnerText = modAttaccoHome + "";
            homePointsNode.AppendChild(modAttaccoNode);

            XmlElement totalNode = xmlDoc.CreateElement("total");

            totalNode.InnerText = totalHome + "";
            homePointsNode.AppendChild(totalNode);

            homeTeamNode.AppendChild(homePointsNode);

            XmlElement homegoalsNode = xmlDoc.CreateElement("goals");

            homegoalsNode.InnerText = goalHome + "";
            homeTeamNode.AppendChild(homegoalsNode);



            XmlElement awayPointsNode  = xmlDoc.CreateElement("points");
            XmlElement partialawayNode = xmlDoc.CreateElement("partial");

            partialawayNode.InnerText = parzialeAway + "";
            awayPointsNode.AppendChild(partialawayNode);

            XmlElement fattoreCampoawayNode = xmlDoc.CreateElement("field");

            fattoreCampoawayNode.InnerText = "0";
            awayPointsNode.AppendChild(fattoreCampoawayNode);

            XmlElement modPerAwayNode = xmlDoc.CreateElement("firstlineup");

            modPerAwayNode.InnerText = modPersonaleAway + "";
            awayPointsNode.AppendChild(modPerAwayNode);

            XmlElement modPortieriAwayNode = xmlDoc.CreateElement("goalkeeper");

            modPortieriAwayNode.InnerText = modPortiereAway + "";
            awayPointsNode.AppendChild(modPortieriAwayNode);

            XmlElement modDifesaAwayNode = xmlDoc.CreateElement("defender");

            modDifesaAwayNode.InnerText = modDifesaAway + "";
            awayPointsNode.AppendChild(modDifesaAwayNode);

            XmlElement modCentrocampoAwayNode = xmlDoc.CreateElement("midfielder");

            modCentrocampoAwayNode.InnerText = modCentrocampoAway + "";
            awayPointsNode.AppendChild(modCentrocampoAwayNode);

            XmlElement modAttaccoAwayNode = xmlDoc.CreateElement("striker");

            modAttaccoAwayNode.InnerText = modAttaccoAway + "";
            awayPointsNode.AppendChild(modAttaccoAwayNode);

            XmlElement totalAwayNode = xmlDoc.CreateElement("total");

            totalAwayNode.InnerText = totalAway + "";
            awayPointsNode.AppendChild(totalAwayNode);

            awayTeamNode.AppendChild(awayPointsNode);

            XmlElement awaygoalsNode = xmlDoc.CreateElement("goals");

            awaygoalsNode.InnerText = goalAway + "";
            awayTeamNode.AppendChild(awaygoalsNode);

            return(matchNode);
        }