Пример #1
0
        public void Fill_LeftStrg31(GridStrategy gStrategy, GameSetting gameSetting)
        {
            //double _treshold = 0.7;
            double _treshold = 0;

            StringBuilder sb = new StringBuilder();

            //nodes
            for (int i = 0; i < gStrategy.Rules.Count; i++)
            {
                AddNode(new Node(i, gStrategy.Rules[i]));
            }

            GridStrategy offensiveM = new GridStrategy();

            offensiveM.Rules.Add(gStrategy.Rules[0]);
            offensiveM.Rules.Add(gStrategy.Rules[1]);
            offensiveM.Rules.Add(gStrategy.Rules[2]);
            offensiveM.Rules.Add(gStrategy.Rules[3]);
            GridStrategy offensiveR = new GridStrategy();

            offensiveR.Rules.Add(gStrategy.Rules[4]);
            offensiveR.Rules.Add(gStrategy.Rules[5]);
            offensiveR.Rules.Add(gStrategy.Rules[6]);
            offensiveR.Rules.Add(gStrategy.Rules[7]);
            offensiveR.Rules.Add(gStrategy.Rules[8]);
            offensiveR.Rules.Add(gStrategy.Rules[9]);
            GridStrategy offensiveL = new GridStrategy();

            offensiveL.Rules.Add(gStrategy.Rules[10]);
            offensiveL.Rules.Add(gStrategy.Rules[11]);
            offensiveL.Rules.Add(gStrategy.Rules[12]);
            offensiveL.Rules.Add(gStrategy.Rules[13]);
            offensiveL.Rules.Add(gStrategy.Rules[14]);
            offensiveL.Rules.Add(gStrategy.Rules[15]);
            GridStrategy defensiveM = new GridStrategy();

            defensiveM.Rules.Add(gStrategy.Rules[16]);
            defensiveM.Rules.Add(gStrategy.Rules[17]);
            defensiveM.Rules.Add(gStrategy.Rules[18]);
            defensiveM.Rules.Add(gStrategy.Rules[19]);
            GridStrategy defensiveR = new GridStrategy();

            defensiveR.Rules.Add(gStrategy.Rules[20]);
            defensiveR.Rules.Add(gStrategy.Rules[21]);
            defensiveR.Rules.Add(gStrategy.Rules[22]);
            defensiveR.Rules.Add(gStrategy.Rules[23]);
            defensiveR.Rules.Add(gStrategy.Rules[24]);
            defensiveR.Rules.Add(gStrategy.Rules[25]);
            GridStrategy defensiveL = new GridStrategy();

            defensiveL.Rules.Add(gStrategy.Rules[26]);
            defensiveL.Rules.Add(gStrategy.Rules[27]);
            defensiveL.Rules.Add(gStrategy.Rules[28]);
            defensiveL.Rules.Add(gStrategy.Rules[29]);
            defensiveL.Rules.Add(gStrategy.Rules[30]);

            List <GridStrategy> lStrategy = new List <GridStrategy>();

            lStrategy.Add(offensiveM);
            lStrategy.Add(offensiveR);
            lStrategy.Add(offensiveL);
            lStrategy.Add(defensiveM);
            lStrategy.Add(defensiveR);
            lStrategy.Add(defensiveL);

            //edges
            double        max    = -1;
            List <Triple> values = new List <Triple>();

            foreach (GridStrategy tempStrg in lStrategy)
            {
                for (int i = 0; i < tempStrg.Rules.Count - 1; i++)
                {
                    for (int j = i + 1; j < tempStrg.Rules.Count; j++)
                    {
                        GridRule r1 = tempStrg.Rules[i];
                        GridRule r2 = tempStrg.Rules[j];

                        //ball
                        double ballRuleSize = gStrategy.GridToReal(r1.Ball, gameSetting).DistanceFrom(
                            gStrategy.GridToReal(r2.Ball, gameSetting)
                            );

                        //mine
                        double mineSize = 0;
                        for (int k = 0; k < gameSetting.NUMBER_OF_ROBOTS - 1; k++)
                        {
                            mineSize += gStrategy.GridToReal(r1.Mine[r1.ZMine[k]], gameSetting).DistanceFrom(
                                gStrategy.GridToReal(r2.Mine[r2.ZMine[k]], gameSetting)
                                );
                        }

                        //oppnt
                        double oppntSize = 0;
                        for (int k = 0; k < gameSetting.NUMBER_OF_ROBOTS - 1; k++)
                        {
                            oppntSize += gStrategy.GridToReal(r1.Oppnt[r1.ZOppnt[k]], gameSetting).DistanceFrom(
                                gStrategy.GridToReal(r2.Oppnt[r2.ZOppnt[k]], gameSetting)
                                );
                        }

                        if (ballRuleSize + mineSize + oppntSize > max)
                        {
                            max = ballRuleSize + mineSize + oppntSize;
                        }

                        int ii = gStrategy.Rules.IndexOf(tempStrg.Rules[i]);
                        int ij = gStrategy.Rules.IndexOf(tempStrg.Rules[j]);

                        values.Add(new Triple(ii, ij, ballRuleSize + mineSize + oppntSize));
                    }
                }
            }

            for (int i = 0; i < values.Count; i++)
            {
                double norm = 1 - (values[i].z / max);
                sb.AppendLine(values[i].x + " " + values[i].y + " " + Math.Round(norm, 3).ToString().Replace(',', '.'));
                //Console.WriteLine("{0} {1} {2} {3}", values[i].x, values[i].y, values[i].z, norm);

                if (norm >= _treshold)
                {
                    AddEdge(nodes[values[i].x], nodes[values[i].y], norm);
                }
            }

            string filename = "GRAPH_" + gStrategy.Name + ".txt";

            File.Delete(filename);
            using (StreamWriter sw = new StreamWriter(new FileStream(filename, FileMode.CreateNew)))
            {
                sw.Write(sb.ToString());
            }
        }
Пример #2
0
        public void Fill(GridStrategy gStrategy, GameSetting gameSetting, double _treshold)
        {
            StringBuilder sb = new StringBuilder();

            //nodes
            for (int i = 0; i < gStrategy.Rules.Count; i++)
            {
                AddNode(new Node(i, gStrategy.Rules[i]));
            }

            //edges
            double        max    = -1;
            List <Triple> values = new List <Triple>();

            for (int i = 0; i < gStrategy.Rules.Count - 1; i++)
            {
                for (int j = i + 1; j < gStrategy.Rules.Count; j++)
                {
                    GridRule r1 = gStrategy.Rules[i];
                    GridRule r2 = gStrategy.Rules[j];

                    //ball
                    double ballRuleSize = gStrategy.GridToReal(r1.Ball, gameSetting).DistanceFrom(
                        gStrategy.GridToReal(r2.Ball, gameSetting)
                        );

                    //mine
                    double mineSize = 0;
                    for (int k = 0; k < gameSetting.NUMBER_OF_ROBOTS - 1; k++)
                    {
                        mineSize += gStrategy.GridToReal(r1.Mine[r1.ZMine[k]], gameSetting).DistanceFrom(
                            gStrategy.GridToReal(r2.Mine[r2.ZMine[k]], gameSetting)
                            );
                    }

                    //oppnt
                    double oppntSize = 0;
                    for (int k = 0; k < gameSetting.NUMBER_OF_ROBOTS - 1; k++)
                    {
                        oppntSize += gStrategy.GridToReal(r1.Oppnt[r1.ZOppnt[k]], gameSetting).DistanceFrom(
                            gStrategy.GridToReal(r2.Oppnt[r2.ZOppnt[k]], gameSetting)
                            );
                    }

                    if (ballRuleSize + mineSize + oppntSize > max)
                    {
                        max = ballRuleSize + mineSize + oppntSize;
                    }

                    values.Add(new Triple(i, j, ballRuleSize + mineSize + oppntSize));
                }
            }

            for (int i = 0; i < values.Count; i++)
            {
                double norm = 1 - (values[i].z / max);
                //Console.WriteLine("{0} {1} {2} {3}", values[i].x, values[i].y, values[i].z, norm);

                if (norm >= _treshold)
                {
                    AddEdge(nodes[values[i].x], nodes[values[i].y], norm);
                    sb.AppendLine(values[i].x + " " + values[i].y + " " + Math.Round(norm, 3).ToString().Replace(',', '.'));
                }
            }

            /**
             * string filename = "GRAPH_" + gStrategy.Name + ".txt";
             * File.Delete(filename);
             * using (StreamWriter sw = new StreamWriter(new FileStream(filename, FileMode.CreateNew)))
             * {
             *  sw.Write(sb.ToString());
             *  sw.Close();
             * }
             */
        }