// Select the choke point for either the start location or the natural expansions location. private bool SelectChoke(bool startChoke) { // get the distance between start and natural BuildSite site = Interface().currentBuildSite; TilePosition start = Interface().baseLocations[(int)BuildSite.StartingLocation]; TilePosition targetChoke = null; Chokepoint chokepoint = null; if (!startChoke) { targetChoke = Interface().baseLocations[2]; double distance = start.getDistance(targetChoke); // find some kind of measure to determine if the the closest choke to natural is not the once between choke and start but after the natural IEnumerable <Chokepoint> chokes = bwta.getChokepoints().Where(ck => bwta.getGroundDistance(new TilePosition(ck.getCenter()), start) > 0).OrderBy(choke => choke.getCenter().getDistance(new Position(targetChoke))); if (chokes == null) { return(false); } foreach (Chokepoint ck in chokes) { if (bwta.getGroundDistance(new TilePosition(ck.getCenter()), targetChoke) < bwta.getGroundDistance(new TilePosition(ck.getCenter()), start)) { chokepoint = ck; break; } } } else { targetChoke = start; chokepoint = bwta.getChokepoints().Where(ck => bwta.getGroundDistance(new TilePosition(ck.getCenter()), start) > 0).OrderBy(choke => choke.getCenter().getDistance(new Position(start))).First(); } if (chokepoint == null) { return(false); } //picking the right side of the choke to position forces Interface().forcePoints[ForceLocations.NaturalChoke] = (targetChoke.getDistance(new TilePosition(chokepoint.getSides().first)) < targetChoke.getDistance(new TilePosition(chokepoint.getSides().second))) ? new TilePosition(chokepoint.getSides().first) : new TilePosition(chokepoint.getSides().second); Interface().currentForcePoint = ForceLocations.NaturalChoke; if (!Interface().baseLocations.ContainsKey((int)BuildSite.Choke)) { Interface().baseLocations.Add(4, Interface().forcePoints[ForceLocations.NaturalChoke]); } return(true); }
// Function to position buildings taking he unit type for the building size protected bool Position(UnitType type, int timeout = 10) { try { // can the AI afford the building if (CanBuildBuilding(type)) { TilePosition buildPosition; // get eh base location for building buildPosition = Interface().baseLocations[(int)Interface().currentBuildSite]; // if no builder selected then select one if (builder == null || builder.getHitPoints() <= 0) { builder = Interface().GetBuilder(buildPosition, false); } // if the build location is further than dist and itterations, then move the builder double dist = DELTADISTANCE; if (buildLocation is TilePosition && buildPosition is TilePosition) { dist = buildLocation.getDistance(buildPosition); } if (buildLocation != null && dist > iterations) { move(new Position(buildLocation), builder); return(true); } else { buildPosition = PossibleBuildLocation(buildPosition, builder, type); // if build location is NULL then build at builders location if (buildPosition == null) { if (bwapi.Broodwar.canBuildHere(builder, new TilePosition(builder.getPosition()), type)) { buildPosition = new TilePosition(builder.getPosition()); } } } try { buildLocation = buildPosition; } catch { return(false); } if (buildLocation is TilePosition) { // set target to becom a new Position from the TilePosition"buildPosition" Position target = new Position(buildPosition); // Move the builder into place builder.move(target, true); Console.Out.WriteLine("Builder Moving into Position"); // While the builder is to far from the build location move to location while (builder.getDistance(target) >= DELTADISTANCE && timeout > 0) { if (builder.move(target, true)) { break; } System.Threading.Thread.Sleep(100); timeout--; } // If the buildder takes too long to get into position a new builder is selected if (timeout <= 0) { Console.Out.WriteLine("Positioning Timed Out Replacing Builder"); builder = Interface().GetBuilder(buildPosition, true); return(false); } Console.Out.WriteLine("Builder in Position"); return(true); } // If the builder cant get inot position and the position is NULL then attempt to build a pylon at the location Console.Out.WriteLine("buildLocation is NULL"); builder.build(builder.getTilePosition(), bwapi.UnitTypes_Protoss_Pylon); return(false); } // Stop the output box from filling up too much if (textCounter >= 1) { return(false); } textCounter++; Console.Out.WriteLine("Can't Afford to Build"); return(false); } catch { return(false); } }