コード例 #1
0
        public void SolutionModify()
        {
            var    item1 = new Item("a");
            var    item2 = new Item("b");
            Recipe r     = new Recipe("");

            r.AddIngredient(new ItemAmount(item1, 1));
            r.AddResult(new ItemAmount(item2, 1));
            r.CraftingCategory = "test";

            Building b = new Building("");

            b.AddCraftingCategory("test");
            b.IngredientCount = 4;
            b.ProductionSpeed = 1;

            Library l = new Library();

            l.AddItem(item1);
            l.AddItem(item2);
            l.AddRecipe(r);
            l.AddBuilding(b);
            l.Initialize();

            var coarseGraph = RecipeGraph.FromLibrary(l, new Item[] { item1 }, new ItemAmount[] { new ItemAmount(item2, 0.01) }, (a) => 1);
            var denseGraph  = TrivialSolutionFactory.CreateFactory(coarseGraph);

            var parameters = SolutionParameters.FromFactory(12, 12, denseGraph);

            Assert.AreEqual(parameters, parameters.Modify(0));
        }
コード例 #2
0
        public async Task <IActionResult> GetSolutionsWithPage([FromQuery] SolutionParameters solutionParameters)
        {
            var find = await _context.Solutions.Include(c => c.Files)
                       .Where(s =>
                              (EF.Functions.Like(s.Id.ToString(), $"%{solutionParameters.Text}%") ||
                               EF.Functions.Like(s.Description, $"%{solutionParameters.Text}%")
                              ) &&
                              EF.Functions.Like(s.LaboratoryWorkId.ToString(), $"%{solutionParameters.LaboratoryWorkId}%") &&
                              EF.Functions.Like(s.OwnerId.ToString(), $"%{solutionParameters.OwnerId}%")
                              ).ToListAsync();

            solutionParameters.TotalCount = find.Count;
            if (!solutionParameters.Check())
            {
                return(NoContent());
            }
            Response.Headers.Add("X-Pagination", solutionParameters.PaginationToJson());
            List <SolutionDTO> dtos = new List <SolutionDTO>();

            foreach (var item in find)
            {
                dtos.Add(item.ToSolutionDto());
            }
            return(Ok(dtos));
        }
コード例 #3
0
        public void RouteSink()
        {
            SolidRouter r = new SolidRouter(
                new Building("belt"),
                new Building("beltground3"),
                new Building("beltground2"),
                new Building("beltground1"),

                new Building("inserter1"),
                new Building("inserter2"),
                new Building("longInserter"),
                new Building("basic-splitter"),

                new SolutionGrader()
                );

            Building assembler = new Building("assembler");

            assembler.Size            = new Vector2(3, 3);
            assembler.IngredientCount = 3;
            assembler.ProductionSpeed = 1;
            assembler.AddCraftingCategory("test");
            Recipe recipe = new Recipe("dummy");

            recipe.CraftingCategory = "test";
            Item item = new Item("dummy");

            Library l = new Library();

            l.AddBuilding(assembler);
            l.AddItem(item);
            l.AddRecipe(recipe);

            l.Initialize();

            Searchspace s        = new Searchspace(new Vector2(13, 10));
            var         physical = new ProductionBuilding(recipe, 1, assembler, new Vector2(7, 3), BuildingRotation.North);

            s = s.AddComponent(physical);

            var dict = new Dictionary <ProductionStep, Tuple <Vector2, BuildingRotation> >();

            dict.Add(physical, new Tuple <Vector2, BuildingRotation>(physical.Position, physical.Rotation));
            var param = new SolutionParameters(13, 10, ImmutableDictionary <SourceStep, Vector2> .Empty, ImmutableDictionary <SinkStep, Vector2> .Empty, dict.ToImmutableDictionary(), ImmutableList <Tuple <IStep, Item, bool> > .Empty);

            var dests = SolutionGenerator.BuildingToPlaceables(physical, param);

            var result = r.Route(new ItemAmount(item, 0.01), s, dests, new RoutingCoordinate[] { new RoutingCoordinate(new Vector2(7, 9), RoutingCoordinate.CoordinateType.Belt, BuildingRotation.South) });
        }
コード例 #4
0
        public void SolutionEdges()
        {
            for (int x = 2; x < 16; x++)
            {
                for (int y = 2; y < 16; y++)
                {
                    SolutionParameters parm = new SolutionParameters(x, y);
                    Vector2            prev = new Vector2(-1, 0);

                    for (int i = -2 * (x + y) + 4; i < 2 * (x + y) - 4; i++)
                    {
                        var newPos = parm.IndexToBound(i);
                        if (i >= 0)
                        {
                            Assert.AreEqual(i, parm.BoundToIndex(newPos), string.Format("{0}, {1}, {2}", x, y, i));
                        }
                        Assert.AreEqual(1, (prev - newPos).DistanceSquared(), string.Format("{0}, {1}, {2}", x, y, i));
                        prev = newPos;
                    }
                }
            }
        }