Beispiel #1
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();
             * }
             */
        }