public static Point FindClosest(EntityEnum e, Point from, NanoBotType botType) { // initial boundary int boundary = 50; // initial region ArrayList list = new ArrayList(20); EntityCollection c = e == EntityEnum.HoshimiPoint ? MYAI.Tissue.GetEntitiesByType(EntityEnum.HoshimiPoint) : MYAI.Tissue.GetEntitiesByType(EntityEnum.AZN); /* * // check whether already on nearest entity * foreach (Entity ee in c) * { * if (from.X == ee.X && from.Y == ee.Y) * return new Point(ee.X, ee.Y); * }*/ while ((list.Count <= 0) || (boundary > 200)) { foreach (Entity ee in c) { if ((e == EntityEnum.HoshimiPoint) && (Global.NeedleGrid[ee.X][ee.Y] != null)) { if (Global.NeedleGrid[ee.X][ee.Y].Skipped) { continue; // skip this HP cos already built by other player } if (Global.NeedleGrid[ee.X][ee.Y].NeedleBuilt) { continue; // AI ignores needle already built } else if (botType == NanoBotType.NanoContainer && Global.NeedleGrid[ee.X][ee.Y].NeedleTargetted) { continue; // Container ignores needle already targetted (may not be built yet) } } else if ((e == EntityEnum.AZN) && (!Global.isPierreAIDead)) { // check if we should avoid this AZN if (Global.CanShoot(new Point(ee.X, ee.Y), Global.MYAI.PierreTeamInjectionPoint, 10)) { continue; } } if (ee.X >= (from.X - boundary) && ee.X <= (from.X + boundary) && ee.Y >= (from.Y - boundary) && ee.Y <= (from.Y + boundary) ) { list.Add(new Point(ee.X, ee.Y)); } } if (list.Count > 0) { break; } // else increment boundary boundary += 50; } if (list.Count <= 0) { return(Point.Empty); } // Now calculate each HP/AZN to find the closest one Point p = Point.Empty; int curDistance; int minDistance = int.MaxValue; Point closestPt = from; for (int i = 0; i < list.Count; i++) { p = (Point)list[i]; curDistance = Global.GetPathLength(from, p); if (curDistance < minDistance) { minDistance = curDistance; closestPt = p; } } // return closest HP/AZN; return(closestPt); }
public static Point FindClosest(EntityEnum e, Point from, NanoBotType botType) { // initial boundary int boundary = 50; // initial region ArrayList list = new ArrayList(20); EntityCollection c = e == EntityEnum.HoshimiPoint ? MYAI.Tissue.GetEntitiesByType(EntityEnum.HoshimiPoint) : MYAI.Tissue.GetEntitiesByType(EntityEnum.AZN); /* // check whether already on nearest entity foreach (Entity ee in c) { if (from.X == ee.X && from.Y == ee.Y) return new Point(ee.X, ee.Y); }*/ while ((list.Count <= 0) || (boundary > 200)) { foreach (Entity ee in c) { if ((e == EntityEnum.HoshimiPoint) && (Global.NeedleGrid[ee.X][ee.Y] != null)) { if (Global.NeedleGrid[ee.X][ee.Y].Skipped) continue; // skip this HP cos already built by other player if (Global.NeedleGrid[ee.X][ee.Y].NeedleBuilt) continue; // AI ignores needle already built else if (botType == NanoBotType.NanoContainer && Global.NeedleGrid[ee.X][ee.Y].NeedleTargetted) continue; // Container ignores needle already targetted (may not be built yet) } else if ((e == EntityEnum.AZN) && (!Global.isPierreAIDead)) { // check if we should avoid this AZN if (Global.CanShoot(new Point(ee.X, ee.Y), Global.MYAI.PierreTeamInjectionPoint, 10)) continue; } if (ee.X >= (from.X - boundary) && ee.X <= (from.X + boundary) && ee.Y >= (from.Y - boundary) && ee.Y <= (from.Y + boundary) ) { list.Add(new Point(ee.X, ee.Y)); } } if (list.Count > 0) break; // else increment boundary boundary += 50; } if (list.Count <= 0) return Point.Empty; // Now calculate each HP/AZN to find the closest one Point p = Point.Empty; int curDistance; int minDistance = int.MaxValue; Point closestPt = from; for (int i = 0; i < list.Count; i++) { p = (Point)list[i]; curDistance = Global.GetPathLength(from, p); if (curDistance < minDistance) { minDistance = curDistance; closestPt = p; } } // return closest HP/AZN; return closestPt; }