예제 #1
0
 public static IEnumerable<Point> GetNeededTrenches(Pump pump)
 {
     var digworthy = GetDiggableAndUnDug();
     var starts = new HashSet<Point>(pump.GetPoints());
     var goals = Bb.GlaciersSet.Where(g => Bb.tileLookup[g].WaterAmount > 5);
     var impassable = new BitArray(Bb.OurSpawns).Or(Bb.TheirSpawns).Or(Bb.OurPumps).Or(Bb.TheirPumps);
     var path = Pather.AStar(starts, p => goals.Contains(p), impassable.Not(), (c, n) => digworthy.Get(n) ? 1 : 0, p => 0);
     return path.Where(p => digworthy.Get(p));
 }
예제 #2
0
    public static void ReadBoard()
    {
        if (!init)
        {
            throw new Exception("Must call Init(AI ai) before using ReadBoard()");
        }
        Reset();

        tileLookup = BaseAI.tiles.ToDictionary(t => t.ToPoint());

        foreach (Tile tile in BaseAI.tiles)
        {
            int offset = GetOffset(tile.X, tile.Y);
            Point point = new Point(tile.X, tile.Y);

            // IsSpawning
            if (tile.IsSpawning)
            {
                IsSpawning[offset] = true;
            }

            // Glaciers
            if (tile.Depth == 0 && tile.WaterAmount > 0 && tile.Owner == 3)
            {
                Glaciers[offset] = true;
                GlaciersSet.Add(point);
            }

            // Trenches
            if (tile.Depth > 0 && tile.WaterAmount == 0)
            {
                Trenches[offset] = true;
            }

            // Water
            if (tile.Depth > 0 && tile.WaterAmount > 0)
            {
                Water[offset] = true;
            }

            // Our Spawns
            if (tile.Owner == usId && tile.PumpID == -1)
            {
                OurSpawns[offset] = true;
                OurSpawnSet.Add(point);
            }

            // Their Spawns
            if (tile.Owner == themId && tile.PumpID == -1)
            {
                TheirSpawns[offset] = true;
                TheirSpawnSet.Add(point);
            }

            // Our Pumps
            if (tile.Owner == usId && tile.PumpID != -1)
            {
                OurPumps[offset] = true;
            }

            // Their Pumps
            if (tile.Owner == themId && tile.PumpID != -1)
            {
                TheirPumps[offset] = true;
            }

            // Neutral Pumps
            if (tile.Owner == 2 && tile.PumpID != -1)
            {
                NeutralPumps[offset] = true;
            }
        }

        // Units
        foreach (Unit unit in BaseAI.units)
        {
            Point point = new Point(unit.X, unit.Y);
            int offset = GetOffset(point);

            // Our Units
            if (unit.Owner == usId)
            {
                OurUnits[offset] = true;
                OurUnitsSet.Add(unit);
                switch (unit.Type)
                {
                    case 0: OurWorkersSet.Add(unit); break;
                    case 1: OurScoutsSet.Add(unit); break;
                    case 2: OurTanksSet.Add(unit); break;
                }
            }

            // Their Units
            if (unit.Owner == themId)
            {
                TheirUnits[offset] = true;
                TheirUnitsSet.Add(unit);
                switch (unit.Type)
                {
                    case 0: TheirWorkersSet.Add(unit); break;
                    case 1: TheirScoutsSet.Add(unit); break;
                    case 2: TheirTanksSet.Add(unit); break;
                }
            }
        }

        var pumps = new BitArray(OurPumps).Or(TheirPumps).Or(NeutralPumps);
        var pumpLookup = BaseAI.pumpStations.ToDictionary(p => p.Id);
        foreach (var p in pumps.ToPoints())
        {
            var tile = tileLookup[p];
            if (!pumpLookup.ContainsKey(tile.PumpID))
            {
                continue;
            }
            var ps = pumpLookup[tile.PumpID];
            pumpLookup.Remove(ps.Id);

            var pump = new Pump(ps, p);
            if (pump.station.SiegeAmount > 0)
            {
                UnderSiege[GetOffset(pump.SW.x, pump.SW.y)] = true;
                UnderSiege[GetOffset(pump.NW.x, pump.NW.y)] = true;
                UnderSiege[GetOffset(pump.SE.x, pump.SE.y)] = true;
                UnderSiege[GetOffset(pump.NE.x, pump.NE.y)] = true;
            }
            if (tile.Owner == usId)
            {
                OurPumpSet.Add(pump);
            }
            else if (tile.Owner == themId)
            {
                TheirPumpSet.Add(pump);
            }
            else
            {
                NeutralPumpSet.Add(pump);
            }
        }

        pumpPointLookup = OurPumpSet.Union(TheirPumpSet).Union(NeutralPumpSet)
            .SelectMany(pump => pump.GetPoints().Select(point => new { ump = pump, oint = point }))
            .ToDictionary(a => a.oint, a => a.ump);
    }
예제 #3
0
    public static bool WillBePumping(Pump pump)
    {
        var starts = pump.GetPoints();
        var goals = Bb.GlaciersSet.Where(g => Bb.tileLookup[g].WaterAmount > 6).ToBitArray();
        var passable = new BitArray(Bb.Water).Or(starts.ToBitArray()).Or(goals).Or(Bb.Trenches);

        return Pather.AStar(starts, p => goals.Get(p), passable, (c, n) => 1, p => 0) != null;
    }