public static IEnumerable <FlowBuilding> SolidPointLeaks(this FlowBuilding building, Vector2 offset, Searchspace space)
        {
            var forward   = space.CalculateCollisions(building.Position + building.Rotation.ToVector()).ToList();
            var belts     = forward.OfType <Belt>();
            var splitters = forward.OfType <Splitter>();
            var ground    = forward.OfType <GroundToUnderground>().Where((g) => g.FlowDepth != Depth.Fluid);

            var filteredBelts     = belts.Where((b) => b.Item.Item != building.Item.Item);
            var filteredSplitters = splitters.Where((s) => s.Item.Item != building.Item.Item && s.Rotation == building.Rotation);
            var filteredGround    = ground.Where((g) => !g.IsUpward && g.Rotation == building.Rotation.Invert() && g.Item.Item != building.Item.Item);

            return(filteredBelts.Cast <FlowBuilding>()
                   .Concat(filteredSplitters)
                   .Concat(filteredGround));
        }
Ejemplo n.º 2
0
        public void SearchstateCollisions()
        {
            var state = new Searchspace(new Vector2(4, 4));

            var item     = new Item("test");
            var building = new Building("test");

            building.Size = 2 * Vector2.One;
            var flow = new FlowBuilding(new ItemAmount(item, 1), building, Vector2.One, BuildingRotation.North);

            var newState = state.AddRoute(flow);

            Assert.AreEqual(0, state.CalculateCollisions(Vector2.One).Count());
            Assert.AreEqual(1, newState.CalculateCollisions(Vector2.One).Count());

            Assert.AreEqual(0, newState.CalculateCollisions(Vector2.Zero).Count());
            Assert.AreEqual(1, newState.CalculateCollisions(Vector2.One, 2 * Vector2.One).Count());
        }
Ejemplo n.º 3
0
        public double CalculateCost(Searchspace space, SolutionGrader grader)
        {
            var cost = base.CalculateCost(space, grader);

            var pipeBuilding = Building;

            BuildingRotation[] rotations = new BuildingRotation[] { BuildingRotation.North, BuildingRotation.East, BuildingRotation.South, BuildingRotation.West };
            foreach (var rotation in rotations)
            {
                var neighbors = space.CalculateCollisions(Position + rotation.ToVector());
                var misMatch  = neighbors.Where((b) => b.Building == pipeBuilding && b is FlowBuilding).Cast <FlowBuilding>()
                                .Where((f) => f.Item.Item != Item.Item);


                cost += misMatch.Count() * grader.TouchLeakCost;
            }

            return(cost);
        }