//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); } } }
//################################################################################################################################################ #region funkce pro strategie private GridRule FindBestRuleGraph(Storage storage) { GridRule bestRule = null; int x, y; //mine matrix = new List <int> [6, 4]; for (int i = 0; i < storage.RightRobots.Length - 1; i++) { Vector2D v = gStrategy.RealToGrid(storage.RightRobots[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.LeftRobots.Length - 1; i++) { Vector2D v = gStrategy.RealToGrid(storage.LeftRobots[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; if (lastRule == -1) { GridRule rule; for (int r = 0; r < gStrategy.Rules.Count; r++) { //nesmysl //if (graph.Nodes[r].neighbours.Count == 0) //{ // if (gStrategy.Rules.Count > 0) // { // bestRule = gStrategy.Rules[0]; // lastRule = 0; // } // break; //} 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.LeftRobots[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.RightRobots[actOppnt[i]].Position); } if (ballRuleSize + mineSize + oppntSize < min) { min = ballRuleSize + mineSize + oppntSize; bestRule = rule; lastRule = r; } } } else { Node actNode = graph.Nodes[lastRule]; GridRule rule; List <int> tempKeys = new List <int>(actNode.neighbours.Keys); tempKeys.Add(lastRule); //foreach (int k in actNode.neighbours.Keys) 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.RightRobots[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.LeftRobots[actOppnt[i]].Position); } if (ballRuleSize + mineSize + oppntSize < min) { min = ballRuleSize + mineSize + oppntSize; bestRule = rule; lastRule = k; } } } return(bestRule); }