Exemple #1
0
        //naplneni ZOrder
        public void fillZOrder()
        {
            ZOrder zord = new ZOrder();
            int    x, y;

            List <int>[,] matrix;

            matrix = new List <int> [6, 4];
            for (int i = 0; i < mine.Length; i++)
            {
                x = Convert.ToInt32(mine[i].X) - 1;
                y = Convert.ToInt32(mine[i].Y) - 1;
                if (matrix[x, y] != null)
                {
                    matrix[x, y].Add(i);
                }
                else
                {
                    matrix[x, y] = new List <int>()
                    {
                        i
                    }
                };
            }
            zMine = zord.zOrderMain(matrix, 2);

            matrix = new List <int> [6, 4];
            for (int i = 0; i < oppnt.Length; i++)
            {
                x = Convert.ToInt32(oppnt[i].X) - 1;
                y = Convert.ToInt32(oppnt[i].Y) - 1;
                if (matrix[x, y] != null)
                {
                    matrix[x, y].Add(i);
                }
                else
                {
                    matrix[x, y] = new List <int>()
                    {
                        i
                    }
                };
            }
            zOppnt = zord.zOrderMain(matrix, 2);
        }
    }
}
Exemple #2
0
        // funkce, ktera podle daneho algoritmu najde nejlepsi (nejvyhodnejsi) pravidlo a toto vrati soucasne s mapovacim indexem pro roboty

        private GridRule FindBestRuleGraph(StrategyStorage storage)
        {
            double   treshold = 500;
            GridRule bestRule = null;
            int      x, y;

            //mine
            matrix = new List <int> [6, 4];
            for (int i = 0; i < storage.myRobots.Length - 1; i++)
            {
                Vector2D v = gStrategy.RealToGrid(storage.myRobots[i].Position, gameSetting);
                x = Convert.ToInt32(v.X);
                y = Convert.ToInt32(v.Y);
                if (matrix[x, y] != null)
                {
                    matrix[x, y].Add(i);
                }
                else
                {
                    matrix[x, y] = new List <int>()
                    {
                        i
                    }
                };
            }
            List <int> actMine = zorder.zOrderMain(matrix, 2);

            //oppnt
            matrix = new List <int> [6, 4];
            for (int i = 0; i < storage.oppntRobots.Length - 1; i++)
            {
                Vector2D v = gStrategy.RealToGrid(storage.oppntRobots[i].Position, gameSetting);
                x = Convert.ToInt32(v.X);
                y = Convert.ToInt32(v.Y);
                if (matrix[x, y] != null)
                {
                    matrix[x, y].Add(i);
                }
                else
                {
                    matrix[x, y] = new List <int>()
                    {
                        i
                    }
                };
            }
            List <int> actOppnt = zorder.zOrderMain(matrix, 2);

            //nejpodobnejsi pravidlo
            double min = Double.MaxValue;

            StringBuilder sb = new StringBuilder();

jump:

            if (lastRule == -1)
            {
                GridRule rule;
                for (int r = 0; r < gStrategy.Rules.Count; r++)
                {
                    rule = gStrategy.Rules[r];

                    double ballRuleSize = gStrategy.GridToReal(rule.Ball, gameSetting).DistanceFrom(storage.Ball.Position);

                    double mineSize = 0;
                    for (int i = 0; i < actMine.Count; i++)
                    {
                        mineSize += gStrategy.GridToReal(rule.Mine[rule.ZMine[i]], gameSetting).DistanceFrom(storage.myRobots[actMine[i]].Position);
                    }

                    double oppntSize = 0;
                    for (int i = 0; i < actOppnt.Count; i++)
                    {
                        oppntSize += gStrategy.GridToReal(rule.Oppnt[rule.ZOppnt[i]], gameSetting).DistanceFrom(storage.oppntRobots[actOppnt[i]].Position);
                    }

                    if (ballRuleSize + mineSize + oppntSize < min)
                    {
                        min      = ballRuleSize + mineSize + oppntSize;
                        bestRule = rule;
                        lastRule = r;
                    }

                    sb.AppendLine("rule: " + rule.Number + " dist: " + (ballRuleSize + mineSize + oppntSize));
                }
            }
            else
            {
                Node       actNode = graph.Nodes[lastRule];
                GridRule   rule;
                List <int> tempKeys = new List <int>(actNode.neighbours.Keys);
                tempKeys.Add(lastRule);

                foreach (int k in tempKeys)
                {
                    rule = (GridRule)graph.Nodes[k].data;

                    double ballRuleSize = gStrategy.GridToReal(rule.Ball, gameSetting).DistanceFrom(storage.Ball.Position);

                    double mineSize = 0;
                    for (int i = 0; i < actMine.Count; i++)
                    {
                        mineSize += gStrategy.GridToReal(rule.Mine[rule.ZMine[i]], gameSetting).DistanceFrom(storage.myRobots[actMine[i]].Position);
                    }

                    double oppntSize = 0;
                    for (int i = 0; i < actOppnt.Count; i++)
                    {
                        oppntSize += gStrategy.GridToReal(rule.Oppnt[rule.ZOppnt[i]], gameSetting).DistanceFrom(storage.oppntRobots[actOppnt[i]].Position);
                    }

                    if (ballRuleSize + mineSize + oppntSize < min)
                    {
                        min      = ballRuleSize + mineSize + oppntSize;
                        bestRule = rule;
                        lastRule = k;
                    }

                    sb.AppendLine("rule: " + rule.Number + " dist: " + (ballRuleSize + mineSize + oppntSize));
                }

                //pokud je hodnota podobnosti mensi nez nejaky nastaveny treshold, tak bych mel znovu prohledavat vsechna pravidla
                if (min > treshold)
                {
                    sb.AppendLine("-----SEARCH ALL RULES----");
                    lastRule = -1;
                    goto jump;
                }
            }

            if (bestRule != null)
            {
                sb.AppendLine("BESTrule: " + bestRule.Number + " MINdist: " + min);
                sb.AppendLine("----------------------------------------------------------------");
            }

            return(bestRule);
        }