private IEnumerable <SolidRouteState> GenerateInserters(Func <Searchspace, IPhysicalBuilding, double> costFunction, Building inserter, Building longInserter, Building fastInserter)
        {
            BuildingRotation[] rotations = new BuildingRotation[] { BuildingRotation.North, BuildingRotation.East, BuildingRotation.South, BuildingRotation.West };

            foreach (var rotation in rotations)
            {
                Vector2 nextpos              = _position;
                var     buildingInserter     = new PhysicalFlowBuilding(((FlowBuilding)_building).Item, inserter, nextpos + rotation.ToVector(), rotation);
                var     buildingLongInserter = new PhysicalFlowBuilding(((FlowBuilding)_building).Item, longInserter, nextpos + 2 * rotation.ToVector(), rotation);
                var     buildingFastInserter = new PhysicalFlowBuilding(((FlowBuilding)_building).Item, fastInserter, nextpos + rotation.ToVector(), rotation);

                buildingInserter.Previous.Add(Building);
                buildingLongInserter.Previous.Add(Building);
                buildingFastInserter.Previous.Add(Building);

                yield return(new SolidRouteState(buildingInserter, _cost + costFunction(_space, buildingInserter), nextpos + 2 * rotation.ToVector(), _space.AddRoute(buildingInserter), RoutingCoordinate.CoordinateType.Inserter, Depth.None, BuildingRotation.North));

                yield return(new SolidRouteState(buildingLongInserter, _cost + costFunction(_space, buildingLongInserter), nextpos + 4 * rotation.ToVector(), _space.AddRoute(buildingLongInserter), RoutingCoordinate.CoordinateType.Inserter, Depth.None, BuildingRotation.North));

                yield return(new SolidRouteState(buildingFastInserter, _cost + costFunction(_space, buildingFastInserter), nextpos + 2 * rotation.ToVector(), _space.AddRoute(buildingFastInserter), RoutingCoordinate.CoordinateType.Inserter, Depth.None, BuildingRotation.North));
            }
        }
        public void UndergroundCollisions()
        {
            var item = new Item("test");
            var lib  = new Library();

            lib.AddItem(item);
            lib.Initialize();

            var flow   = new UndergroundFlow(new ItemAmount(item, 1), Vector2.One, Depth.Normal, BuildingRotation.South);
            var grader = new SolutionGrader();

            var space = new Searchspace(new Vector2(4, 4));

            space = space.AddRoute(flow);
            Assert.AreEqual(0, flow.CalculateCost(space, grader));

            var flow2    = new UndergroundFlow(new ItemAmount(item, 1), Vector2.One, Depth.Fast, BuildingRotation.South);
            var newSpace = space.AddRoute(flow2);

            Assert.AreEqual(0, flow.CalculateCost(newSpace, grader));

            flow2    = new UndergroundFlow(new ItemAmount(item, 1), Vector2.One, Depth.Normal, BuildingRotation.South);
            newSpace = space.AddRoute(flow2);
            Assert.IsTrue(flow.CalculateCost(newSpace, grader) > 0);

            flow2    = new UndergroundFlow(new ItemAmount(item, 1), Vector2.One, Depth.Normal, BuildingRotation.North);
            newSpace = space.AddRoute(flow2);
            Assert.IsTrue(flow.CalculateCost(newSpace, grader) > 0);

            flow2    = new UndergroundFlow(new ItemAmount(item, 1), Vector2.One, Depth.Normal, BuildingRotation.East);
            newSpace = space.AddRoute(flow2);
            Assert.AreEqual(0, flow.CalculateCost(newSpace, grader));

            var building = new PhysicalFlowBuilding(new ItemAmount(item, 1), new Building("test1"), Vector2.One, BuildingRotation.North);

            newSpace = space.AddRoute(building);
            Assert.AreEqual(0, flow.CalculateCost(newSpace, grader));
        }