Esempio n. 1
0
        public Solver(string targetFile, string sourceFile)
        {
            var targetData = (targetFile != null ? MdlFile.LoadModel(targetFile) : ((byte, BitArray)?)null);

            // load source
            var sourceData = (sourceFile != null ? MdlFile.LoadModel(sourceFile) : ((byte, BitArray)?)null);

            // create system
            MatterSystem = new MatterSystem(targetData?.Item1 ?? sourceData?.Item1 ?? 0, targetData?.Item2, sourceData?.Item2);
        }
Esempio n. 2
0
        public void bleh()
        {
            var system = new MatterSystem(20, null, null);

            for (int x = 1; x < 20; x++)
            {
                for (int y = 0; y < 20; y++)
                {
                    for (int z = 1; z < 20; z++)
                    {
                        system.Matrix.Get(x, y, z).Filled = true;
                    }
                }
            }

            system.Matrix.Get(10, 0, 10).Filled = false;

            AstarGroundFinder.CanReachGround(system.Matrix.Get(10, 10, 10), null, system.Matrix);
        }
Esempio n. 3
0
 public override void ToggleVoxel(Voxel targetVoxel)
 {
     MatterSystem.ExecuteCommand(1, new CommandFill(MatterSystem.Bots[1].Position.Offset(targetVoxel)));
     Octree.Remove(targetVoxel);
 }
Esempio n. 4
0
        public void Solve(string outputFile)
        {
            if (outputFile != null)
            {
                Name = Path.GetFileNameWithoutExtension(outputFile);
            }

            // get all the target voxels
            RemainingVoxels = new HashSet <Voxel>(MatterSystem.Matrix.Storage.Where(x => x.Filled != x.Target));

            var lastCompletePercent = 0;
            var startCount          = RemainingVoxels.Count;

            Log.Info($"{Name} Total targets: {RemainingVoxels.Count:N0}");

            while (RemainingVoxels.Count > 0)
            {
                var(targetVoxel, moveTarget) = ChooseNextTarget();

                // move bot to a nearby if we're not there
                if (MatterSystem.Bots[1].Position != moveTarget)
                {
                    var route = AstarMatrixPather.GetRouteTo(MatterSystem.Bots[1].Position, moveTarget);

                    MatterSystem.ExecuteCommands(CommandOptimizer.Compress(route));
                }

                // fill/void it
                ToggleVoxel(targetVoxel);

                // remove it from targets
                RemainingVoxels.Remove(targetVoxel);

                var complete = (int)(100 - ((float)RemainingVoxels.Count / startCount * 100));
                if (complete != lastCompletePercent)
                {
                    lastCompletePercent = complete;
                    Log.Info($"{Name} {complete:N0}% complete ({RemainingVoxels.Count:N0} remaining)");
                }
            }

            // move to home
            var homeRoute = AstarMatrixPather.GetRouteTo(MatterSystem.Bots[1].Position, MatterSystem.Matrix.Get(0, 0, 0));

            if (homeRoute == null)
            {
                TraceFile.WriteTraceFile(outputFile + ".failed", MatterSystem.Trace);
                Log.Error($"{Path.GetFileNameWithoutExtension(outputFile)} Failed with {RemainingVoxels.Count:N0} targets left");
                return;
            }

            MatterSystem.ExecuteCommands(CommandOptimizer.Compress(homeRoute));

            if (outputFile != null)
            {
                // halt
                MatterSystem.ExecuteCommand(1, new CommandHalt());

                // save trace file
                TraceFile.WriteTraceFile(outputFile, MatterSystem.Trace);
                Log.Debug($"{Path.GetFileNameWithoutExtension(outputFile)} Finished solution ");
            }
        }
Esempio n. 5
0
 public Solver(byte resolution)
 {
     MatterSystem = new MatterSystem(resolution, null, null);
 }